failures.c revision 04f0944b16374064e8d657f3925082a2613da4b9
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen/* Initialize working defaults */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic fatal_failure_callback_t *fatal_handler ATTR_NORETURN =
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainenstatic failure_callback_t *error_handler = default_error_handler;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic failure_callback_t *info_handler = default_error_handler;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic void (*failure_exit_callback)(int *) = NULL;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic int log_fd = STDERR_FILENO, log_info_fd = STDERR_FILENO;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic char *log_prefix = NULL, *log_stamp_format = NULL;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen/* kludgy .. we want to trust log_stamp_format with -Wformat-nonliteral */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic const char *get_log_stamp_format(const char *unused)
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic const char *get_log_stamp_format(const char *unused ATTR_UNUSED)
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenstatic void log_fd_flush_stop(struct ioloop *ioloop)
5e327e031d1591f8bff17b67eba7139afbd36cddTimo Sirainenstatic int log_fd_write(int fd, const unsigned char *data, unsigned int len)
a13b1245bee0b6524b4aeb3c8fd9e34af648b746Aki Tuomi while ((ret = write(fd, data, len)) != (ssize_t)len) {
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* some was written, continue.. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* out of disk space? */
a2fdfd2efdbb2d912aad23900a466cf74114920bTimo Sirainen /* wait until we can write more. this can happen at least
237a6211c7fc4d6dbb58dd0467da6dba1b8f21f6Timo Sirainen when writing to terminal, even if fd is blocking. */
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainen io = io_add(IO_WRITE, fd, log_fd_flush_stop, ioloop);
2d1892aaeb63b9774237b6e60d6bb04bf6f8259cTimo Sirainendefault_handler(const char *prefix, int fd, const char *format, va_list args)
2d1892aaeb63b9774237b6e60d6bb04bf6f8259cTimo Sirainen static int recursed = 0;
107659c01b2359b0ee426bde020c8d4e29ede30dTimo Sirainen /* we're being called from some signal handler or we ran
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen out of memory */
107659c01b2359b0ee426bde020c8d4e29ede30dTimo Sirainen /* make sure there's no %n in there and fix %m */
107659c01b2359b0ee426bde020c8d4e29ede30dTimo Sirainen str_vprintfa(str, printf_format_fix(format), args);
c1fc5a97a15332f1253ee13a9cab65a7b4b6cd5fTimo Sirainen ret = log_fd_write(fd, str_data(str), str_len(str));
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenvoid default_fatal_handler(enum log_type type, int status,
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen if (default_handler(failure_log_type_prefixes[type], log_fd, format,
abort();
static int recursed = 0;
if (recursed != 0)
recursed++;
recursed--;
const char *backtrace;
abort();
switch (type) {
case LOG_TYPE_INFO:
case LOG_TYPE_WARNING:
case LOG_TYPE_ERROR:
case LOG_TYPE_FATAL:
case LOG_TYPE_PANIC:
int ret;
T_BEGIN {
} T_END;
return ret;
const char *backtrace;
abort();
void i_set_failure_internal(void)
void failures_deinit(void)