Mercurial > dovecot > original-hg > dovecot-1.2
changeset 2046:6ae973f60f43 HEAD
logging cleanups.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 23 May 2004 22:23:57 +0300 |
parents | c7b50945591e |
children | 55e3412ae995 |
files | src/master/auth-process.c src/master/log.c src/master/log.h src/master/login-process.c src/master/mail-process.c |
diffstat | 5 files changed, 63 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/master/auth-process.c Sun May 23 20:02:50 2004 +0300 +++ b/src/master/auth-process.c Sun May 23 22:23:57 2004 +0300 @@ -254,6 +254,7 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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++)
--- a/src/master/log.c Sun May 23 20:02:50 2004 +0300 +++ b/src/master/log.c Sun May 23 22:23:57 2004 +0300 @@ -82,6 +82,8 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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;
--- a/src/master/log.h Sun May 23 20:02:50 2004 +0300 +++ b/src/master/log.h Sun May 23 22:23:57 2004 +0300 @@ -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);
--- a/src/master/login-process.c Sun May 23 20:02:50 2004 +0300 +++ b/src/master/login-process.c Sun May 23 22:23:57 2004 +0300 @@ -422,6 +422,7 @@ 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 @@ 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 @@ 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 @@ 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]);
--- a/src/master/mail-process.c Sun May 23 20:02:50 2004 +0300 +++ b/src/master/mail-process.c Sun May 23 22:23:57 2004 +0300 @@ -150,10 +150,11 @@ struct ip_addr *ip, struct auth_master_reply *reply, const char *data) { + struct settings *set = group->set; const char *argv[4]; - struct settings *set = group->set; 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 @@ 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 @@ 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) */