failures.h revision b547a4e327dc376b8fb1b50eb587d4f63d62365d
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Default exit status codes that we could use. */
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen FATAL_LOGWRITE = 81, /* Can't write to log file */
c4cfee078c4a185b5ba8f0c55f51275b7e885b2cTimo Sirainen FATAL_LOGERROR = 82, /* Internal logging error */
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainen#define DEFAULT_FAILURE_STAMP_FORMAT "%b %d %H:%M:%S "
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainentypedef void failure_callback_t(enum log_type type, const char *, va_list);
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainentypedef void fatal_failure_callback_t(enum log_type type, int status,
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainen const char *, va_list);
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenextern const char *failure_log_type_prefixes[];
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenvoid i_log_type(enum log_type type, const char *format, ...) ATTR_FORMAT(2, 3);
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenvoid i_panic(const char *format, ...) ATTR_FORMAT(1, 2) ATTR_NORETURN;
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenvoid i_fatal(const char *format, ...) ATTR_FORMAT(1, 2) ATTR_NORETURN;
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenvoid i_error(const char *format, ...) ATTR_FORMAT(1, 2);
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenvoid i_warning(const char *format, ...) ATTR_FORMAT(1, 2);
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenvoid i_info(const char *format, ...) ATTR_FORMAT(1, 2);
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainenvoid i_fatal_status(int status, const char *format, ...)
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainen/* Change failure handlers. */
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainenvoid i_set_fatal_handler(fatal_failure_callback_t *callback ATTR_NORETURN);
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainen/* Older g++ doesn't like attributes in parameters */
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainenvoid i_set_fatal_handler(fatal_failure_callback_t *callback);
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainenvoid i_set_error_handler(failure_callback_t *callback);
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainenvoid i_set_info_handler(failure_callback_t *callback);
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainenvoid i_get_failure_handlers(fatal_failure_callback_t **fatal_callback_r,
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainen/* Send failures to file. */
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainenvoid default_fatal_handler(enum log_type type, int status,
9d3ccd79130199ffdb19a688027d49bf20a4aaaaTimo Sirainenvoid default_error_handler(enum log_type type, const char *format, va_list args)
8d6cb44a0161d88743756733f83c4fb278485987Timo Sirainen/* Send failures to syslog() */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid i_syslog_fatal_handler(enum log_type type, int status,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid i_syslog_error_handler(enum log_type type, const char *fmt, va_list args)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Open syslog and set failure/info handlers to use it. */
5c0034beb9933bca2a8b7d83d11dface1ea3b7faTimo Sirainenvoid i_set_failure_syslog(const char *ident, int options, int facility);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Send failures to specified log file instead of stderr. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid i_set_failure_file(const char *path, const char *prefix);
9bf2dc275ec21bff3d468ab1bc4fddc8874f7d1bTimo Sirainen/* Send errors to stderr using internal error protocol. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* If writing to log fails, ignore it instead of existing with
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen FATAL_LOGWRITE or FATAL_LOGERROR. */
be889d9b142fbb5604a922c6955bd7f6ea32f163Timo Sirainen/* Send informational messages to specified log file. i_set_failure_*()
be889d9b142fbb5604a922c6955bd7f6ea32f163Timo Sirainen functions modify the info file too, so call this function after them. */
be889d9b142fbb5604a922c6955bd7f6ea32f163Timo Sirainen/* Set the failure prefix. */
be889d9b142fbb5604a922c6955bd7f6ea32f163Timo Sirainen/* Prefix failures with a timestamp. fmt is in strftime() format. */
be889d9b142fbb5604a922c6955bd7f6ea32f163Timo Sirainenvoid i_set_failure_timestamp_format(const char *fmt);
be889d9b142fbb5604a922c6955bd7f6ea32f163Timo Sirainen/* When logging with internal error protocol, update the process's current
be889d9b142fbb5604a922c6955bd7f6ea32f163Timo Sirainen IP address. This is mainly used by the master process to log some IP
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen address if the process crash. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid i_set_failure_ip(const struct ip_addr *ip);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Call the callback before exit()ing. The callback may update the status. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid i_set_failure_exit_callback(void (*callback)(int *status));
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Call the exit callback and exit() */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Parse a line logged using internal failure handler */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid i_failure_parse_line(const char *line, struct failure_line *failure);