[dovecot-cvs] dovecot/src/lib failures.c, 1.23, 1.24 failures.h, 1.8, 1.9

cras at procontrol.fi cras at procontrol.fi
Mon May 10 19:05:12 EEST 2004


Update of /home/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv10665/lib

Modified Files:
	failures.c failures.h 
Log Message:
Write all logging through master process. Fixes problems with log rotation,
chrooting, etc. Master process also allows max. 10 log messages per second
per child process, it then begins throttling them (eventually making the
child process start blocking on stderr).



Index: failures.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/failures.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- failures.c	8 Sep 2003 01:29:07 -0000	1.23
+++ failures.c	10 May 2004 16:05:10 -0000	1.24
@@ -1,6 +1,8 @@
 /* Copyright (c) 2002-2003 Timo Sirainen */
 
 #include "lib.h"
+#include "str.h"
+#include "write-full.h"
 #include "fd-close-on-exec.h"
 #include "printf-upper-bound.h"
 
@@ -342,6 +344,65 @@
 	log_info_fd = log_fd;
 }
 
+static int internal_handler(char log_type, const char *format, va_list args)
+{
+	string_t *str;
+	int ret;
+
+	t_push();
+	str = t_str_new(512);
+	str_append_c(str, 1);
+	str_append_c(str, log_type);
+	str_vprintfa(str, format, args);
+	str_append_c(str, '\n');
+	ret = write_full(2, str_data(str), str_len(str));
+	t_pop();
+
+	return ret;
+}
+
+static void i_internal_panic_handler(const char *fmt, va_list args)
+	__attr_noreturn__;
+static void i_internal_panic_handler(const char *fmt, va_list args)
+{
+	(void)internal_handler('F', fmt, args);
+        abort();
+}
+
+static void i_internal_fatal_handler(int status, const char *fmt, va_list args)
+	__attr_noreturn__;
+static void i_internal_fatal_handler(int status, const char *fmt, va_list args)
+{
+	if (internal_handler('F', fmt, args) < 0 && status == FATAL_DEFAULT)
+		status = FATAL_LOGERROR;
+	exit(status);
+}
+
+static void i_internal_error_handler(const char *fmt, va_list args)
+{
+	if (internal_handler('E', fmt, args) < 0)
+		exit(FATAL_LOGERROR);
+}
+
+static void i_internal_warning_handler(const char *fmt, va_list args)
+{
+	(void)internal_handler('W', fmt, args);
+}
+
+static void i_internal_info_handler(const char *fmt, va_list args)
+{
+	(void)internal_handler('I', fmt, args);
+}
+
+void i_set_failure_internal(void)
+{
+	i_set_panic_handler(i_internal_panic_handler);
+	i_set_fatal_handler(i_internal_fatal_handler);
+	i_set_error_handler(i_internal_error_handler);
+	i_set_warning_handler(i_internal_warning_handler);
+	i_set_info_handler(i_internal_info_handler);
+}
+
 void i_set_info_file(const char *path)
 {
 	if (log_info_fd == log_fd)

Index: failures.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/failures.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- failures.h	27 Jan 2003 01:59:59 -0000	1.8
+++ failures.h	10 May 2004 16:05:10 -0000	1.9
@@ -47,6 +47,9 @@
 /* Send failures to specified log file instead of stderr. */
 void i_set_failure_file(const char *path, const char *prefix);
 
+/* Send errors to stderr using internal error protocol. */
+void i_set_failure_internal(void);
+
 /* Send informational messages to specified log file. i_set_failure_*()
    functions modify the info file too, so call this function after them. */
 void i_set_info_file(const char *path);



More information about the dovecot-cvs mailing list