]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
logging cleanups.
authorTimo Sirainen <tss@iki.fi>
Sun, 23 May 2004 19:23:57 +0000 (22:23 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 23 May 2004 19:23:57 +0000 (22:23 +0300)
--HG--
branch : HEAD

src/master/auth-process.c
src/master/log.c
src/master/log.h
src/master/login-process.c
src/master/mail-process.c

index 3dceaf79c7caba8d06dba8592e256a3bb3270ed4..e6b0fb07d19730ea2c0274c051d863a754ab47d3 100644 (file)
@@ -254,6 +254,7 @@ static pid_t create_auth_process(struct auth_process_group *group)
 {
        static char *argv[] = { NULL, NULL };
        const char *prefix;
+       struct log_io *log;
        pid_t pid;
        int fd[2], log_fd, i;
 
@@ -263,8 +264,7 @@ static pid_t create_auth_process(struct auth_process_group *group)
                return -1;
        }
 
-       prefix = t_strdup_printf("auth(%s): ", group->set->name);
-       log_fd = log_create_pipe(prefix);
+       log_fd = log_create_pipe(&log);
        if (log_fd < 0)
                pid = -1;
        else {
@@ -282,6 +282,9 @@ static pid_t create_auth_process(struct auth_process_group *group)
 
        if (pid != 0) {
                /* master */
+               prefix = t_strdup_printf("auth(%s): ", group->set->name);
+               log_set_prefix(log, prefix);
+
                net_set_nonblock(fd[0], TRUE);
                fd_close_on_exec(fd[0], TRUE);
                auth_process_new(pid, fd[0], group);
@@ -290,19 +293,22 @@ static pid_t create_auth_process(struct auth_process_group *group)
                return pid;
        }
 
+       prefix = t_strdup_printf("master-auth(%s): ", group->set->name);
+       log_set_prefix(log, prefix);
+
        /* move master communication handle to 0 */
        if (dup2(fd[1], 0) < 0)
-               i_fatal("auth: dup2(stdin) failed: %m");
+               i_fatal("dup2(stdin) failed: %m");
 
        (void)close(fd[0]);
        (void)close(fd[1]);
 
        /* set stdout to /dev/null, so anything written into it gets ignored. */
        if (dup2(null_fd, 1) < 0)
-               i_fatal("auth: dup2(stdout) failed: %m");
+               i_fatal("dup2(stdout) failed: %m");
 
        if (dup2(log_fd, 2) < 0)
-               i_fatal("auth: dup2(stderr) failed: %m");
+               i_fatal("dup2(stderr) failed: %m");
 
        child_process_init_env();
 
@@ -310,7 +316,7 @@ static pid_t create_auth_process(struct auth_process_group *group)
           sure it's not closed afterwards. */
        if (group->listen_fd != 3) {
                if (dup2(group->listen_fd, 3) < 0)
-                       i_fatal("auth: dup2() failed: %m");
+                       i_fatal("dup2() failed: %m");
        }
 
        for (i = 0; i <= 3; i++)
index c80069586278b2ce2f6c5c5a5616e121bc3c0a4b..15c1513ac9c428409b0fc89f69091239d41e3230 100644 (file)
@@ -82,6 +82,8 @@ static void log_unthrottle(struct log_io *log_io)
 
 static int log_it(struct log_io *log_io, const char *line, int continues)
 {
+       const char *prefix;
+
        if (log_io->next_log_type == '\0') {
                if (line[0] == 1 && line[1] != '\0') {
                        /* our internal protocol.
@@ -94,15 +96,16 @@ static int log_it(struct log_io *log_io, const char *line, int continues)
        }
 
        t_push();
+       prefix = log_io->prefix != NULL ? log_io->prefix : "";
        switch (log_io->next_log_type) {
        case 'I':
-               i_info("%s%s", log_io->prefix, line);
+               i_info("%s%s", prefix, line);
                break;
        case 'W':
-               i_warning("%s%s", log_io->prefix, line);
+               i_warning("%s%s", prefix, line);
                break;
        default:
-               i_error("%s%s", log_io->prefix, line);
+               i_error("%s%s", prefix, line);
                break;
        }
        t_pop();
@@ -152,7 +155,7 @@ static void log_read(void *context)
                log_unthrottle(log_io);
 }
 
-int log_create_pipe(const char *prefix)
+int log_create_pipe(struct log_io **log_r)
 {
        struct log_io *log_io;
        int fd[2];
@@ -166,7 +169,6 @@ int log_create_pipe(const char *prefix)
        fd_close_on_exec(fd[1], TRUE);
 
        log_io = i_new(struct log_io, 1);
-       log_io->prefix = i_strdup(prefix);
        log_io->stream = i_stream_create_file(fd[0], default_pool, 1024, TRUE);
 
        throttle_count++;
@@ -177,9 +179,17 @@ int log_create_pipe(const char *prefix)
        log_io->next = log_ios;
        log_ios = log_io;
 
+       if (log_r != NULL)
+               *log_r = log_io;
        return fd[1];
 }
 
+void log_set_prefix(struct log_io *log, const char *prefix)
+{
+       i_free(log->prefix);
+       log->prefix = i_strdup(prefix);
+}
+
 static void log_io_free(struct log_io *log_io)
 {
        const unsigned char *data;
index f8083e9234c7e9e417aa2b66a5fcbbd4c63ff189..1adad0edec1107617ae2d6cd222c650aab7fb9fe 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef __LOG_H
 #define __LOG_H
 
-int log_create_pipe(const char *prefix);
+struct log_io;
+
+int log_create_pipe(struct log_io **log_r);
+void log_set_prefix(struct log_io *log, const char *prefix);
+
 void log_init(void);
 void log_deinit(void);
 
index cfcdb7f51d516bc9e5c614fb43cde5b742954c2e..d89744e860cc8fc36e551ff40eef13f407794e81 100644 (file)
@@ -422,6 +422,7 @@ static void login_process_init_env(struct login_group *group, pid_t pid)
 static pid_t create_login_process(struct login_group *group)
 {
        static const char *argv[] = { NULL, NULL };
+       struct log_io *log;
        const char *prefix;
        pid_t pid;
        int fd[2], log_fd;
@@ -442,9 +443,7 @@ static pid_t create_login_process(struct login_group *group)
                return -1;
        }
 
-       prefix = t_strdup_printf("%s-login: ",
-                                process_names[group->process_type]);
-       log_fd = log_create_pipe(prefix);
+       log_fd = log_create_pipe(&log);
        if (log_fd < 0)
                pid = -1;
        else {
@@ -462,6 +461,10 @@ static pid_t create_login_process(struct login_group *group)
 
        if (pid != 0) {
                /* master */
+               prefix = t_strdup_printf("%s-login: ",
+                                        process_names[group->process_type]);
+               log_set_prefix(log, prefix);
+
                net_set_nonblock(fd[0], TRUE);
                fd_close_on_exec(fd[0], TRUE);
                (void)login_process_new(group, pid, fd[0]);
@@ -470,23 +473,27 @@ static pid_t create_login_process(struct login_group *group)
                return pid;
        }
 
+       prefix = t_strdup_printf("master-%s-login: ",
+                                process_names[group->process_type]);
+       log_set_prefix(log, prefix);
+
        /* move the listen handle */
        if (dup2(group->set->listen_fd, LOGIN_LISTEN_FD) < 0)
-               i_fatal("login: dup2(listen_fd) failed: %m");
+               i_fatal("dup2(listen_fd) failed: %m");
        fd_close_on_exec(LOGIN_LISTEN_FD, FALSE);
 
        /* move the SSL listen handle */
        if (dup2(group->set->ssl_listen_fd, LOGIN_SSL_LISTEN_FD) < 0)
-               i_fatal("login: dup2(ssl_listen_fd) failed: %m");
+               i_fatal("dup2(ssl_listen_fd) failed: %m");
        fd_close_on_exec(LOGIN_SSL_LISTEN_FD, FALSE);
 
        /* move communication handle */
        if (dup2(fd[1], LOGIN_MASTER_SOCKET_FD) < 0)
-               i_fatal("login: dup2(master) failed: %m");
+               i_fatal("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");
+               i_fatal("dup2(stderr) failed: %m");
        fd_close_on_exec(2, FALSE);
 
        (void)close(fd[0]);
index f8af74b5b7f3be69886c15676bcb0ba8cb62277d..4adbd965aa67e895d1081494b8a38eaaab5188bf 100644 (file)
@@ -150,10 +150,11 @@ int create_mail_process(struct login_group *group, int socket,
                        struct ip_addr *ip,
                        struct auth_master_reply *reply, const char *data)
 {
-       const char *argv[4];
        struct settings *set = group->set;
+       const char *argv[4];
        const char *addr, *mail, *user, *chroot_dir, *home_dir, *full_home_dir;
        const char *executable, *p, *prefix;
+       struct log_io *log;
        char title[1024];
        pid_t pid;
        int i, err, ret, log_fd;
@@ -179,9 +180,7 @@ int create_mail_process(struct login_group *group, int socket,
                return FALSE;
        }
 
-       prefix = t_strdup_printf("%s(%s): ", process_names[group->process_type],
-                                data + reply->virtual_user_idx);
-       log_fd = log_create_pipe(prefix);
+       log_fd = log_create_pipe(&log);
 
        pid = fork();
        if (pid < 0) {
@@ -192,25 +191,35 @@ int create_mail_process(struct login_group *group, int socket,
 
        if (pid != 0) {
                /* master */
+               prefix = t_strdup_printf("%s(%s): ",
+                                        process_names[group->process_type],
+                                        data + reply->virtual_user_idx);
+               log_set_prefix(log, prefix);
+
                mail_process_count++;
                PID_ADD_PROCESS_TYPE(pid, group->process_type);
                (void)close(log_fd);
                return TRUE;
        }
 
+       prefix = t_strdup_printf("master-%s(%s): ",
+                                process_names[group->process_type],
+                                data + reply->virtual_user_idx);
+       log_set_prefix(log, prefix);
+
        child_process_init_env();
 
        /* move the client socket into stdin and stdout fds */
        fd_close_on_exec(socket, FALSE);
        if (dup2(socket, 0) < 0)
-               i_fatal("mail: dup2(stdin) failed: %m");
+               i_fatal("dup2(stdin) failed: %m");
        if (dup2(socket, 1) < 0)
-               i_fatal("mail: dup2(stdout) failed: %m");
+               i_fatal("dup2(stdout) failed: %m");
        if (dup2(log_fd, 2) < 0)
-               i_fatal("mail: dup2(stderr) failed: %m");
+               i_fatal("dup2(stderr) failed: %m");
 
        if (close(socket) < 0)
-               i_error("mail: close(mail client) failed: %m");
+               i_error("close(mail client) failed: %m");
 
        /* setup environment - set the most important environment first
           (paranoia about filling up environment without noticing) */