failures.h revision be0185d71b19869700ac936fa9d09fb4ce950ae3
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef FAILURES_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define FAILURES_H
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen
1d5e52e398381873081455ad99edec945038eec0Timo Sirainenstruct ip_addr;
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen/* Default exit status codes that we could use. */
1d5e52e398381873081455ad99edec945038eec0Timo Sirainenenum fatal_exit_status {
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen FATAL_LOGOPEN = 80, /* Can't open log file */
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen FATAL_LOGWRITE = 81, /* Can't write to log file */
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen FATAL_LOGERROR = 82, /* Internal logging error */
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen FATAL_OUTOFMEM = 83, /* Out of memory */
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen FATAL_EXEC = 84, /* exec() failed */
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen FATAL_DEFAULT = 89
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen};
1d5e52e398381873081455ad99edec945038eec0Timo Sirainen
1d5e52e398381873081455ad99edec945038eec0Timo Sirainenenum log_type {
LOG_TYPE_INFO,
LOG_TYPE_WARNING,
LOG_TYPE_ERROR,
LOG_TYPE_FATAL,
LOG_TYPE_PANIC
};
#define DEFAULT_FAILURE_STAMP_FORMAT "%b %d %H:%M:%S "
typedef void failure_callback_t(enum log_type type, const char *, va_list);
typedef void fatal_failure_callback_t(enum log_type type, int status,
const char *, va_list);
extern const char *failure_log_type_prefixes[];
void i_log_type(enum log_type type, const char *format, ...) ATTR_FORMAT(2, 3);
void i_panic(const char *format, ...) ATTR_FORMAT(1, 2) ATTR_NORETURN;
void i_fatal(const char *format, ...) ATTR_FORMAT(1, 2) ATTR_NORETURN;
void i_error(const char *format, ...) ATTR_FORMAT(1, 2);
void i_warning(const char *format, ...) ATTR_FORMAT(1, 2);
void i_info(const char *format, ...) ATTR_FORMAT(1, 2);
void i_fatal_status(int status, const char *format, ...)
ATTR_FORMAT(2, 3) ATTR_NORETURN;
/* Change failure handlers. */
#ifndef __cplusplus
void i_set_fatal_handler(fatal_failure_callback_t *callback ATTR_NORETURN);
#else
/* Older g++ doesn't like attributes in parameters */
void i_set_fatal_handler(fatal_failure_callback_t *callback);
#endif
void i_set_error_handler(failure_callback_t *callback);
void i_set_info_handler(failure_callback_t *callback);
/* Send failures to file. */
void default_fatal_handler(enum log_type type, int status,
const char *format, va_list args)
ATTR_NORETURN ATTR_FORMAT(3, 0);
void default_error_handler(enum log_type type, const char *format, va_list args)
ATTR_FORMAT(2, 0);
/* Send failures to syslog() */
void i_syslog_fatal_handler(enum log_type type, int status,
const char *fmt, va_list args)
ATTR_NORETURN ATTR_FORMAT(3, 0);
void i_syslog_error_handler(enum log_type type, const char *fmt, va_list args)
ATTR_FORMAT(2, 0);
/* Open syslog and set failure/info handlers to use it. */
void i_set_failure_syslog(const char *ident, int options, int facility);
/* Send failures to specified log file instead of stderr. */
void i_set_failure_file(const char *path, const char *prefix);
/* 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);
/* Set the failure prefix. */
void i_set_failure_prefix(const char *prefix);
/* Prefix failures with a timestamp. fmt is in strftime() format. */
void i_set_failure_timestamp_format(const char *fmt);
/* When logging with internal error protocol, update the process's current
IP address. This is mainly used by the master process to log some IP
address if the process crash. */
void i_set_failure_ip(const struct ip_addr *ip);
/* Call the callback before exit()ing. The callback may update the status. */
void i_set_failure_exit_callback(void (*callback)(int *status));
/* Call the exit callback and exit() */
void failure_exit(int status) ATTR_NORETURN;
void failures_deinit(void);
#endif