failures.c revision 7fb80bfee23825f544a2c22717da14f7b162a6d2
/* Copyright (c) 2002-2007 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "str.h"
#include "backtrace-string.h"
#include "printf-format-fix.h"
#include "write-full.h"
#include "fd-close-on-exec.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <syslog.h>
#include <time.h>
static const char *log_type_prefixes[] = {
"Info: ",
"Warning: ",
"Error: ",
"Fatal: ",
"Panic: "
};
static char log_type_internal_chars[] = {
'I', 'W', 'E', 'F', 'P'
};
/* Initialize working defaults */
static void (*failure_exit_callback)(int *) = NULL;
/* kludgy .. we want to trust log_stamp_format with -Wformat-nonliteral */
static const char *get_log_stamp_format(const char *unused)
ATTR_FORMAT_ARG(1);
{
return log_stamp_format;
}
static void failure_exit(int status)
{
if (failure_exit_callback != NULL)
}
{
char buf[256];
if (log_prefix != NULL)
if (log_stamp_format != NULL) {
}
}
{
}
{
if (ret > 0) {
/* some was written, continue.. */
continue;
}
if (ret == 0) {
/* out of disk space? */
return -1;
}
return -1;
/* wait until we can write more. this can happen at least
when writing to terminal, even if fd is blocking. */
ioloop = io_loop_create();
}
return 0;
}
static int ATTR_FORMAT(3, 0)
{
static int recursed = 0;
if (recursed >= 2) {
/* we're being called from some signal handler or we ran
out of memory */
return 0;
}
recursed++;
t_push();
/* make sure there's no %n in there and fix %m */
t_pop();
recursed--;
return ret;
}
static void ATTR_FORMAT(3, 0)
{
const char *backtrace;
if (type == LOG_TYPE_PANIC) {
if (backtrace_get(&backtrace) == 0)
}
if (type == LOG_TYPE_PANIC)
abort();
else
}
static void ATTR_FORMAT(2, 0)
{
}
{
if (type == LOG_TYPE_INFO)
else
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
static int ATTR_FORMAT(2, 0)
{
static int recursed = 0;
if (recursed != 0)
return -1;
recursed++;
/* make sure there's no %n in there. vsyslog() supports %m, but since
we'll convert it ourself anyway, we might as well it */
recursed--;
return 0;
}
{
const char *backtrace;
if (type == LOG_TYPE_PANIC) {
if (backtrace_get(&backtrace) == 0)
abort();
} else {
}
}
{
switch (type) {
case LOG_TYPE_INFO:
break;
case LOG_TYPE_WARNING:
level = LOG_WARNING;
break;
case LOG_TYPE_ERROR:
break;
case LOG_TYPE_FATAL:
case LOG_TYPE_PANIC:
break;
}
}
{
}
{
if (*fd != STDERR_FILENO) {
"close(%d) failed: %m", *fd);
}
}
*fd = STDERR_FILENO;
else {
if (*fd == -1) {
*fd = STDERR_FILENO;
"Can't open log file %s: %m", path);
}
}
}
{
if (close(log_info_fd) < 0)
}
}
void i_set_failure_prefix(const char *prefix)
{
}
static int ATTR_FORMAT(2, 0)
{
int ret;
t_push();
t_pop();
return ret;
}
{
const char *backtrace;
status == FATAL_DEFAULT)
if (type == LOG_TYPE_PANIC) {
if (backtrace_get(&backtrace) == 0)
abort();
} else {
}
}
static void ATTR_FORMAT(2, 0)
{
}
void i_set_failure_internal(void)
{
}
void i_set_info_file(const char *path)
{
if (log_info_fd == log_fd)
}
void i_set_failure_timestamp_format(const char *fmt)
{
}
{
}
void failures_deinit(void)
{
if (log_info_fd == log_fd)
if (log_fd != STDERR_FILENO) {
}
if (log_info_fd != STDERR_FILENO) {
(void)close(log_info_fd);
}
}