{
static char *argv[] = { NULL, NULL };
const char *prefix;
+ struct log_io *log;
pid_t pid;
int fd[2], log_fd, i;
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 {
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);
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();
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++)
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.
}
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();
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];
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++;
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;
#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);
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;
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 {
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]);
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]);
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;
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) {
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) */