[dovecot-cvs] dovecot/src/lib failures.c, 1.27.2.5, 1.27.2.6 failures.h, 1.9.2.1, 1.9.2.2

tss at dovecot.org tss at dovecot.org
Thu Feb 15 14:25:57 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv28667/lib

Modified Files:
      Tag: branch_1_0
	failures.c failures.h 
Log Message:
Added i_set_failure_exit_callback()



Index: failures.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/failures.c,v
retrieving revision 1.27.2.5
retrieving revision 1.27.2.6
diff -u -d -r1.27.2.5 -r1.27.2.6
--- failures.c	19 Jan 2007 18:25:51 -0000	1.27.2.5
+++ failures.c	15 Feb 2007 14:25:24 -0000	1.27.2.6
@@ -12,6 +12,8 @@
 #include <syslog.h>
 #include <time.h>
 
+static void failure_exit(int status) __attr_noreturn__;
+
 static void default_panic_handler(const char *format, va_list args)
 	__attr_noreturn__ __attr_format__(1, 0);
 static void default_fatal_handler(int status, const char *format, va_list args)
@@ -32,6 +34,7 @@
 static failure_callback_t *error_handler = default_error_handler;
 static failure_callback_t *warning_handler = default_warning_handler;
 static failure_callback_t *info_handler = default_info_handler;
+static void (*failure_exit_callback)(int *) = NULL;
 
 static FILE *log_fd = NULL, *log_info_fd = NULL;
 static char *log_prefix = NULL, *log_stamp_format = NULL;
@@ -45,6 +48,13 @@
 	return log_stamp_format;
 }
 
+static void failure_exit(int status)
+{
+	if (failure_exit_callback != NULL)
+		failure_exit_callback(&status);
+	exit(status);
+}
+
 static void write_prefix(FILE *f)
 {
 	struct tm *tm;
@@ -137,7 +147,7 @@
 	if (fflush(log_fd) < 0 && status == FATAL_DEFAULT)
 		status = FATAL_LOGWRITE;
 
-	exit(status);
+	failure_exit(status);
 }
 
 static void default_error_handler(const char *format, va_list args)
@@ -145,10 +155,10 @@
 	int old_errno = errno;
 
 	if (default_handler("Error: ", log_fd, format, args) < 0)
-		exit(FATAL_LOGERROR);
+		failure_exit(FATAL_LOGERROR);
 
 	if (fflush(log_fd) < 0)
-		exit(FATAL_LOGWRITE);
+		failure_exit(FATAL_LOGWRITE);
 
 	errno = old_errno;
 }
@@ -160,7 +170,7 @@
 	(void)default_handler("Warning: ", log_fd, format, args);
 
 	if (fflush(log_fd) < 0)
-		exit(FATAL_LOGWRITE);
+		failure_exit(FATAL_LOGWRITE);
 
 	errno = old_errno;
 }
@@ -172,7 +182,7 @@
 	(void)default_handler("Info: ", log_info_fd, format, args);
 
 	if (fflush(log_info_fd) < 0)
-		exit(FATAL_LOGWRITE);
+		failure_exit(FATAL_LOGWRITE);
 
 	errno = old_errno;
 }
@@ -301,13 +311,13 @@
 {
 	if (syslog_handler(LOG_CRIT, fmt, args) < 0 && status == FATAL_DEFAULT)
 		status = FATAL_LOGERROR;
-	exit(status);
+	failure_exit(status);
 }
 
 void i_syslog_error_handler(const char *fmt, va_list args)
 {
 	if (syslog_handler(LOG_ERR, fmt, args) < 0)
-		exit(FATAL_LOGERROR);
+		failure_exit(FATAL_LOGERROR);
 }
 
 void i_syslog_warning_handler(const char *fmt, va_list args)
@@ -343,7 +353,7 @@
 		if (*file == NULL) {
 			fprintf(stderr, "Can't open log file %s: %s",
 				path, strerror(errno));
-			exit(FATAL_LOGOPEN);
+			failure_exit(FATAL_LOGOPEN);
 		}
 		fd_close_on_exec(fileno(*file), TRUE);
 	}
@@ -402,13 +412,13 @@
 {
 	if (internal_handler('F', fmt, args) < 0 && status == FATAL_DEFAULT)
 		status = FATAL_LOGERROR;
-	exit(status);
+	failure_exit(status);
 }
 
 static void i_internal_error_handler(const char *fmt, va_list args)
 {
 	if (internal_handler('E', fmt, args) < 0)
-		exit(FATAL_LOGERROR);
+		failure_exit(FATAL_LOGERROR);
 }
 
 static void i_internal_warning_handler(const char *fmt, va_list args)
@@ -445,6 +455,11 @@
         log_stamp_format = i_strdup(fmt);
 }
 
+void i_set_failure_exit_callback(void (*callback)(int *status))
+{
+	failure_exit_callback = callback;
+}
+
 void failures_deinit(void)
 {
 	if (log_info_fd == log_fd)

Index: failures.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/failures.h,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -u -d -r1.9.2.1 -r1.9.2.2
--- failures.h	1 Nov 2006 18:50:14 -0000	1.9.2.1
+++ failures.h	15 Feb 2007 14:25:25 -0000	1.9.2.2
@@ -61,6 +61,9 @@
 /* Prefix failures with a timestamp. fmt is in strftime() format. */
 void i_set_failure_timestamp_format(const char *fmt);
 
+/* Call the callback before exit()ing. The callback may update the status. */
+void i_set_failure_exit_callback(void (*callback)(int *status));
+
 void failures_deinit(void);
 
 #endif



More information about the dovecot-cvs mailing list