diff src/master/login-process.c @ 2000:c7c19f5071c3 HEAD

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).
author Timo Sirainen <tss@iki.fi>
date Mon, 10 May 2004 19:05:09 +0300
parents 1d0985f6bdd9
children 6ae973f60f43
line wrap: on
line diff
--- a/src/master/login-process.c	Mon May 10 18:12:38 2004 +0300
+++ b/src/master/login-process.c	Mon May 10 19:05:09 2004 +0300
@@ -13,6 +13,7 @@
 #include "auth-process.h"
 #include "mail-process.h"
 #include "master-login-interface.h"
+#include "log.h"
 
 #include <unistd.h>
 #include <syslog.h>
@@ -370,7 +371,7 @@
 {
 	struct settings *set = group->set;
 
-	child_process_init_env(set);
+	child_process_init_env();
 
 	/* setup access environment - needs to be done after
 	   clean_child_process() since it clears environment */
@@ -421,8 +422,9 @@
 static pid_t create_login_process(struct login_group *group)
 {
 	static const char *argv[] = { NULL, NULL };
+	const char *prefix;
 	pid_t pid;
-	int fd[2];
+	int fd[2], log_fd;
 
 	if (group->set->login_process_per_connection &&
 	    group->processes - group->listening_processes >=
@@ -435,16 +437,26 @@
 		i_fatal("Login process must not run as root");
 
 	/* create communication to process with a socket pair */
-	if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) {
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
 		i_error("socketpair() failed: %m");
 		return -1;
 	}
 
-	pid = fork();
+	prefix = t_strdup_printf("%s-login: ",
+				 process_names[group->process_type]);
+	log_fd = log_create_pipe(prefix);
+	if (log_fd < 0)
+		pid = -1;
+	else {
+		pid = fork();
+		if (pid < 0)
+			i_error("fork() failed: %m");
+	}
+
 	if (pid < 0) {
 		(void)close(fd[0]);
 		(void)close(fd[1]);
-		i_error("fork() failed: %m");
+		(void)close(log_fd);
 		return -1;
 	}
 
@@ -454,6 +466,7 @@
 		fd_close_on_exec(fd[0], TRUE);
 		(void)login_process_new(group, pid, fd[0]);
 		(void)close(fd[1]);
+		(void)close(log_fd);
 		return pid;
 	}
 
@@ -472,6 +485,10 @@
 		i_fatal("login: dup2(master) failed: %m");
 	fd_close_on_exec(LOGIN_MASTER_SOCKET_FD, FALSE);
 
+	if (dup2(log_fd, 2) < 0)
+		i_fatal("login: dup2(stderr) failed: %m");
+	fd_close_on_exec(2, FALSE);
+
 	(void)close(fd[0]);
 	(void)close(fd[1]);