failures.h revision 6a058aa8c986a8fbec5ddd72c141db9df0b64b2d
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen#ifndef __FAILURES_H
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen#define __FAILURES_H
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen/* Default exit status codes that we could use. */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenenum fatal_exit_status {
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen FATAL_LOGOPEN = 80, /* Can't open log file */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen FATAL_LOGWRITE = 81, /* Can't write to log file */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen FATAL_LOGERROR = 82, /* Internal logging error */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen FATAL_OUTOFMEM = 83, /* Out of memory */
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen FATAL_EXEC = 84, /* exec() failed */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen FATAL_DEFAULT = 89
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen};
1382a978f06181d68151194ee4569378df16416aTimo Sirainen
311d3dd2078c1b711a0cef013ba43a94078c115cTimo Sirainen#define DEFAULT_FAILURE_STAMP_FORMAT "%b %d %H:%M:%S "
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen
311d3dd2078c1b711a0cef013ba43a94078c115cTimo Sirainentypedef void failure_callback_t(const char *, va_list);
311d3dd2078c1b711a0cef013ba43a94078c115cTimo Sirainentypedef void fatal_failure_callback_t(int status, const char *, va_list);
311d3dd2078c1b711a0cef013ba43a94078c115cTimo Sirainen
311d3dd2078c1b711a0cef013ba43a94078c115cTimo Sirainenvoid i_panic(const char *format, ...) __attr_format__(1, 2) __attr_noreturn__;
311d3dd2078c1b711a0cef013ba43a94078c115cTimo Sirainenvoid i_fatal(const char *format, ...) __attr_format__(1, 2) __attr_noreturn__;
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_error(const char *format, ...) __attr_format__(1, 2);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_warning(const char *format, ...) __attr_format__(1, 2);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_info(const char *format, ...) __attr_format__(1, 2);
0c1ed553b9add66a85e908b0c783c1b0dee1e0feTimo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenvoid i_fatal_status(int status, const char *format, ...)
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen __attr_format__(2, 3) __attr_noreturn__;
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen/* Change failure handlers. Make sure they don't modify errno. */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_set_panic_handler(failure_callback_t *callback __attr_noreturn__);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_set_fatal_handler(fatal_failure_callback_t *callback __attr_noreturn__);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_set_error_handler(failure_callback_t *callback);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_set_warning_handler(failure_callback_t *callback);
e563b8a1457be8c08cc7567043c9f06b8243a025Timo Sirainenvoid i_set_info_handler(failure_callback_t *callback);
e563b8a1457be8c08cc7567043c9f06b8243a025Timo Sirainen
e563b8a1457be8c08cc7567043c9f06b8243a025Timo Sirainen/* Send failures to syslog() */
e563b8a1457be8c08cc7567043c9f06b8243a025Timo Sirainenvoid i_syslog_panic_handler(const char *fmt, va_list args)
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen __attr_noreturn__ __attr_format__(1, 0);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_syslog_fatal_handler(int status, const char *fmt, va_list args)
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen __attr_noreturn__ __attr_format__(2, 0);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_syslog_error_handler(const char *fmt, va_list args)
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen __attr_format__(1, 0);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_syslog_warning_handler(const char *fmt, va_list args)
1382a978f06181d68151194ee4569378df16416aTimo Sirainen __attr_format__(1, 0);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_syslog_info_handler(const char *fmt, va_list args)
311d3dd2078c1b711a0cef013ba43a94078c115cTimo Sirainen __attr_format__(1, 0);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen/* Open syslog and set failure/info handlers to use it. */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_set_failure_syslog(const char *ident, int options, int facility);
0c1ed553b9add66a85e908b0c783c1b0dee1e0feTimo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen/* Send failures to specified log file instead of stderr. */
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainenvoid i_set_failure_file(const char *path, const char *prefix);
f46fce070a135ec6bb3078c104f32651ea84cdefTimo Sirainen
/* Send errors to stderr using internal error protocol. */
void i_set_failure_internal(void);
/* Send informational messages to specified log file. i_set_failure_*()
functions modify the info file too, so call this function after them. */
void i_set_info_file(const char *path);
/* Prefix failures with a timestamp. fmt is in strftime() format. */
void i_set_failure_timestamp_format(const char *fmt);
void failures_deinit(void);
#endif