[dovecot-cvs] dovecot/src/lib failures.c, 1.33, 1.34 failures.h, 1.10, 1.11

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


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

Modified Files:
	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.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- failures.c	19 Jan 2007 18:25:53 -0000	1.33
+++ failures.c	15 Feb 2007 14:25:27 -0000	1.34
@@ -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;
@@ -139,7 +149,7 @@
 	if (fflush(log_fd) < 0 && status == FATAL_DEFAULT)
 		status = FATAL_LOGWRITE;
 
-	exit(status);
+	failure_exit(status);
 }
 
 static void __attr_format__(1, 0)
@@ -148,10 +158,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;
 }
@@ -164,7 +174,7 @@
 	(void)default_handler("Warning: ", log_fd, format, args);
 
 	if (fflush(log_fd) < 0)
-		exit(FATAL_LOGWRITE);
+		failure_exit(FATAL_LOGWRITE);
 
 	errno = old_errno;
 }
@@ -177,7 +187,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;
 }
@@ -307,13 +317,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)
@@ -349,7 +359,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);
 	}
@@ -407,14 +417,14 @@
 {
 	if (internal_handler('F', fmt, args) < 0 && status == FATAL_DEFAULT)
 		status = FATAL_LOGERROR;
-	exit(status);
+	failure_exit(status);
 }
 
 static void __attr_format__(1, 0)
 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 __attr_format__(1, 0)
@@ -453,6 +463,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.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- failures.h	1 Nov 2006 18:47:37 -0000	1.10
+++ failures.h	15 Feb 2007 14:25:28 -0000	1.11
@@ -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