diff options
author | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-05-24 14:38:57 +0000 |
---|---|---|
committer | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-05-24 14:38:57 +0000 |
commit | 72f320d789e26f1a6d777dd158641de3038990ac (patch) | |
tree | 6cf0ceac33f100e5f18aa19632727121d498c51c /usr.sbin/smtpd | |
parent | 576522606d25ccb68ce580aa9b2d77ae382c9c2d (diff) |
Parent process forks 3 types of processes, track them all in a single tree
using newly introduced child struct.
Manage process titles centrally in struct smtpd.
ok gilles@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/config.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/control.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/mda.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/mfa.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/runner.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 370 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 25 |
11 files changed, 207 insertions, 224 deletions
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c index 1abb0f70dcc..19a60e45d7f 100644 --- a/usr.sbin/smtpd/config.c +++ b/usr.sbin/smtpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.5 2009/02/16 12:10:25 jacekm Exp $ */ +/* $OpenBSD: config.c,v 1.6 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -104,7 +104,7 @@ purge_config(struct smtpd *env, u_int8_t what) } void -init_peers(struct smtpd *env) +init_pipes(struct smtpd *env) { int i; int j; diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c index 72598b56e54..43a1ed5a795 100644 --- a/usr.sbin/smtpd/control.c +++ b/usr.sbin/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.29 2009/05/24 14:22:23 jacekm Exp $ */ +/* $OpenBSD: control.c,v 1.30 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -144,8 +144,8 @@ control(struct smtpd *env) #warning disabling privilege revocation and chroot in DEBUG MODE #endif - setproctitle("control process"); smtpd_process = PROC_CONTROL; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 2a622f6ad99..3b9a48adcd1 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.50 2009/05/20 16:07:26 gilles Exp $ */ +/* $OpenBSD: lka.c,v 1.51 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -725,8 +725,8 @@ lka(struct smtpd *env) pw = env->sc_pw; - setproctitle("lookup agent"); smtpd_process = PROC_LKA; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c index e81c2e0e106..a46f0c30a04 100644 --- a/usr.sbin/smtpd/mda.c +++ b/usr.sbin/smtpd/mda.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mda.c,v 1.17 2009/05/19 11:24:24 jacekm Exp $ */ +/* $OpenBSD: mda.c,v 1.18 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -417,8 +417,8 @@ mda(struct smtpd *env) #warning disabling privilege revocation and chroot in DEBUG MODE #endif - setproctitle("mail delivery agent"); smtpd_process = PROC_MDA; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c index 2b05b83644c..97759962d46 100644 --- a/usr.sbin/smtpd/mfa.c +++ b/usr.sbin/smtpd/mfa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa.c,v 1.30 2009/05/21 01:07:13 gilles Exp $ */ +/* $OpenBSD: mfa.c,v 1.31 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -463,8 +463,8 @@ mfa(struct smtpd *env) #warning disabling privilege revocation and chroot in DEBUG MODE #endif - setproctitle("mail filter agent"); smtpd_process = PROC_MFA; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index c538636d3fc..8c5f1e8be4f 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.48 2009/05/19 11:24:24 jacekm Exp $ */ +/* $OpenBSD: mta.c,v 1.49 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -500,8 +500,8 @@ mta(struct smtpd *env) #warning disabling privilege revocation and chroot in DEBUG MODE #endif - setproctitle("mail transfer agent"); smtpd_process = PROC_MTA; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index efd11dbe7f7..d8798802375 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.64 2009/05/24 14:22:23 jacekm Exp $ */ +/* $OpenBSD: queue.c,v 1.65 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -563,8 +563,8 @@ queue(struct smtpd *env) #warning disabling privilege revocation and chroot in DEBUG MODE #endif - setproctitle("queue handler"); smtpd_process = PROC_QUEUE; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index c242f44b82b..6f415ebf139 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.47 2009/05/24 14:22:23 jacekm Exp $ */ +/* $OpenBSD: runner.c,v 1.48 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -474,8 +474,8 @@ runner(struct smtpd *env) #warning disabling privilege revocation and chroot in DEBUG MODE #endif - setproctitle("runner"); smtpd_process = PROC_RUNNER; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c index 13b9d79b742..b35ad763b6f 100644 --- a/usr.sbin/smtpd/smtp.c +++ b/usr.sbin/smtpd/smtp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp.c,v 1.49 2009/05/24 14:22:23 jacekm Exp $ */ +/* $OpenBSD: smtp.c,v 1.50 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -619,8 +619,8 @@ smtp(struct smtpd *env) #warning disabling privilege revocation and chroot in DEBUG MODE #endif - setproctitle("smtp server"); smtpd_process = PROC_SMTP; + setproctitle("%s", env->sc_title[smtpd_process]); #ifndef DEBUG if (setgroups(1, &pw->pw_gid) || diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 29db0eb3a1b..2c3d62ca380 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.64 2009/05/24 14:22:24 jacekm Exp $ */ +/* $OpenBSD: smtpd.c,v 1.65 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -51,42 +51,38 @@ #include "smtpd.h" -__dead void usage(void); -void parent_shutdown(void); -void parent_send_config(int, short, void *); -void parent_send_config_listeners(struct smtpd *); -void parent_send_config_ruleset(struct smtpd *, int); -void parent_dispatch_lka(int, short, void *); -void parent_dispatch_mda(int, short, void *); -void parent_dispatch_mfa(int, short, void *); -void parent_dispatch_smtp(int, short, void *); -void parent_dispatch_runner(int, short, void *); -void parent_dispatch_control(int, short, void *); -void parent_sig_handler(int, short, void *); -int parent_open_message_file(struct batch *); -int parent_mailbox_open(char *, struct passwd *, struct batch *); -int parent_filename_open(char *, struct passwd *, struct batch *); -int parent_mailfile_rename(struct batch *, struct path *); -int parent_maildir_open(char *, struct passwd *, struct batch *); -int parent_maildir_init(struct passwd *, char *); -int parent_external_mda(char *, struct passwd *, struct batch *); -int parent_enqueue_offline(struct smtpd *, char *); -int parent_forward_open(char *); -int check_child(pid_t, const char *); -int setup_spool(uid_t, gid_t); -int path_starts_with(char *, char *); +__dead void usage(void); +void parent_shutdown(struct smtpd *); +void parent_send_config(int, short, void *); +void parent_send_config_listeners(struct smtpd *); +void parent_send_config_ruleset(struct smtpd *, int); +void parent_dispatch_lka(int, short, void *); +void parent_dispatch_mda(int, short, void *); +void parent_dispatch_mfa(int, short, void *); +void parent_dispatch_smtp(int, short, void *); +void parent_dispatch_runner(int, short, void *); +void parent_dispatch_control(int, short, void *); +void parent_sig_handler(int, short, void *); +int parent_open_message_file(struct batch *); +int parent_mailbox_open(char *, struct passwd *, struct batch *); +int parent_filename_open(char *, struct passwd *, struct batch *); +int parent_mailfile_rename(struct batch *, struct path *); +int parent_maildir_open(char *, struct passwd *, struct batch *); +int parent_maildir_init(struct passwd *, char *); +int parent_external_mda(char *, struct passwd *, struct batch *); +int parent_enqueue_offline(struct smtpd *, char *); +int parent_forward_open(char *); +int setup_spool(uid_t, gid_t); +int path_starts_with(char *, char *); + +void fork_peers(struct smtpd *); + +void child_add(struct smtpd *, pid_t, int, int); +void child_del(struct smtpd *, pid_t); +struct child *child_lookup(struct smtpd *, pid_t); extern char **environ; -pid_t lka_pid = 0; -pid_t mfa_pid = 0; -pid_t queue_pid = 0; -pid_t mda_pid = 0; -pid_t mta_pid = 0; -pid_t control_pid = 0; -pid_t smtp_pid = 0; -pid_t runner_pid = 0; - int __b64_pton(char const *, unsigned char *, size_t); __dead void @@ -100,32 +96,20 @@ usage(void) } void -parent_shutdown(void) +parent_shutdown(struct smtpd *env) { - u_int i; - pid_t pid; - pid_t pids[] = { - lka_pid, - mfa_pid, - queue_pid, - mda_pid, - mta_pid, - control_pid, - smtp_pid, - runner_pid - }; + struct child *child; + pid_t pid; - for (i = 0; i < nitems(pids); i++) - if (pids[i]) - kill(pids[i], SIGTERM); + SPLAY_FOREACH(child, childtree, &env->children) + if (child->type == CHILD_DAEMON) + kill(child->pid, SIGTERM); do { - if ((pid = wait(NULL)) == -1 && - errno != EINTR && errno != ECHILD) - fatal("wait"); + pid = waitpid(WAIT_MYPGRP, NULL, 0); } while (pid != -1 || (pid == -1 && errno == EINTR)); - log_info("terminating"); + log_warnx("parent terminating"); exit(0); } @@ -675,23 +659,11 @@ parent_dispatch_control(int sig, short event, void *p) void parent_sig_handler(int sig, short event, void *p) { - int i; - int die = 0; - pid_t pid; - struct mdaproc *mdaproc; - struct mdaproc lookup; - struct smtpd *env = p; - struct { pid_t p; const char *s; } procs[] = { - { lka_pid, "lookup agent" }, - { mfa_pid, "mail filter agent" }, - { queue_pid, "mail queue" }, - { mda_pid, "mail delivery agent" }, - { mta_pid, "mail transfer agent" }, - { control_pid, "control process" }, - { smtp_pid, "smtp server" }, - { runner_pid, "runner" }, - { 0, NULL }, - }; + struct smtpd *env = p; + struct child *child; + int die = 0, status, fail; + pid_t pid; + char *cause; switch (sig) { case SIGTERM: @@ -699,67 +671,66 @@ parent_sig_handler(int sig, short event, void *p) die = 1; /* FALLTHROUGH */ case SIGCHLD: - for (i = 0; procs[i].s != NULL; i++) - if (check_child(procs[i].p, procs[i].s)) { - procs[i].p = 0; + do { + pid = waitpid(-1, &status, WNOHANG); + if (pid <= 0) + continue; + + child = child_lookup(env, pid); + if (child == NULL) + fatalx("unexpected SIGCHLD"); + + fail = 0; + if (WIFSIGNALED(status)) { + fail = 1; + asprintf(&cause, "terminated; signal %d", + WTERMSIG(status)); + } else if (WIFEXITED(status)) { + if (WEXITSTATUS(status) != 0) { + fail = 1; + asprintf(&cause, "exited abnormally"); + } else + asprintf(&cause, "exited okay"); + } else + fatalx("unexpected cause of SIGCHLD"); + + switch (child->type) { + case CHILD_DAEMON: die = 1; - } - if (die) - parent_shutdown(); + if (fail) + log_warnx("lost child: %s %s", + env->sc_title[child->title], cause); + break; - do { - int status; + case CHILD_MDA: + if (fail) + log_warnx("external mda %s", cause); + else + log_debug("external mda %s", cause); + break; - pid = waitpid(-1, &status, WNOHANG); - if (pid > 0) { - lookup.pid = pid; - mdaproc = SPLAY_FIND(mdaproctree, &env->mdaproc_queue, &lookup); - if (mdaproc == NULL) - fatalx("unexpected SIGCHLD"); - - if (WIFEXITED(status) && !WIFSIGNALED(status)) { - switch (mdaproc->type) { - case CHILD_ENQUEUE_OFFLINE: - if (WEXITSTATUS(status) == 0) - log_debug("offline enqueue was successful"); - else - log_debug("offline enqueue failed"); - imsg_compose(env->sc_ibufs[PROC_RUNNER], - IMSG_PARENT_ENQUEUE_OFFLINE, 0, 0, -1, - NULL, 0); - break; - case CHILD_MDA: - if (WEXITSTATUS(status) == EX_OK) - log_debug("DEBUG: external mda reported success"); - else if (WEXITSTATUS(status) == EX_TEMPFAIL) - log_debug("DEBUG: external mda reported temporary failure"); - else - log_warnx("external mda returned %d", WEXITSTATUS(status)); - break; - default: - fatalx("invalid child type"); - break; - } - } else { - switch (mdaproc->type) { - case CHILD_ENQUEUE_OFFLINE: - log_warnx("offline enqueue terminated abnormally"); - break; - case CHILD_MDA: - log_warnx("external mda terminated abnormally"); - break; - default: - fatalx("invalid child type"); - break; - } - } - - SPLAY_REMOVE(mdaproctree, &env->mdaproc_queue, - mdaproc); - free(mdaproc); + case CHILD_ENQUEUE_OFFLINE: + if (fail) + log_warnx("couldn't enqueue offline " + "message; smtpctl %s", cause); + else + log_debug("offline message enqueued"); + imsg_compose(env->sc_ibufs[PROC_RUNNER], + IMSG_PARENT_ENQUEUE_OFFLINE, 0, 0, -1, + NULL, 0); + break; + + default: + fatalx("unexpected child type"); } + + child_del(env, child->pid); + + free(cause); } while (pid > 0 || (pid == -1 && errno == EINTR)); + if (die) + parent_shutdown(env); break; default: fatalx("unexpected signal"); @@ -877,29 +848,7 @@ main(int argc, char *argv[]) env.sc_maxconn = (rl.rlim_cur / 4) * 3; log_debug("smtpd: will accept at most %d clients", env.sc_maxconn); - env.sc_instances[PROC_PARENT] = 1; - env.sc_instances[PROC_LKA] = 1; - env.sc_instances[PROC_MFA] = 1; - env.sc_instances[PROC_QUEUE] = 1; - env.sc_instances[PROC_MDA] = 1; - env.sc_instances[PROC_MTA] = 1; - env.sc_instances[PROC_SMTP] = 1; - env.sc_instances[PROC_CONTROL] = 1; - env.sc_instances[PROC_RUNNER] = 1; - - init_peers(&env); - - /* start subprocesses */ - lka_pid = lka(&env); - mfa_pid = mfa(&env); - queue_pid = queue(&env); - mda_pid = mda(&env); - mta_pid = mta(&env); - smtp_pid = smtp(&env); - control_pid = control(&env); - runner_pid = runner(&env); - - SPLAY_INIT(&env.mdaproc_queue); + fork_peers(&env); event_init(); @@ -925,25 +874,79 @@ main(int argc, char *argv[]) return (0); } +void +fork_peers(struct smtpd *env) +{ + SPLAY_INIT(&env->children); + + env->sc_instances[PROC_CONTROL] = 1; + env->sc_instances[PROC_LKA] = 1; + env->sc_instances[PROC_MDA] = 1; + env->sc_instances[PROC_MFA] = 1; + env->sc_instances[PROC_MTA] = 1; + env->sc_instances[PROC_PARENT] = 1; + env->sc_instances[PROC_QUEUE] = 1; + env->sc_instances[PROC_RUNNER] = 1; + env->sc_instances[PROC_SMTP] = 1; + + init_pipes(env); + + env->sc_title[PROC_CONTROL] = "control"; + env->sc_title[PROC_LKA] = "lookup agent"; + env->sc_title[PROC_MDA] = "mail delivery agent"; + env->sc_title[PROC_MFA] = "mail filter agent"; + env->sc_title[PROC_MTA] = "mail transfer agent"; + env->sc_title[PROC_QUEUE] = "queue"; + env->sc_title[PROC_RUNNER] = "runner"; + env->sc_title[PROC_SMTP] = "smtp server"; + + child_add(env, control(env), CHILD_DAEMON, PROC_CONTROL); + child_add(env, lka(env), CHILD_DAEMON, PROC_LKA); + child_add(env, mda(env), CHILD_DAEMON, PROC_MDA); + child_add(env, mfa(env), CHILD_DAEMON, PROC_MFA); + child_add(env, mta(env), CHILD_DAEMON, PROC_MTA); + child_add(env, queue(env), CHILD_DAEMON, PROC_QUEUE); + child_add(env, runner(env), CHILD_DAEMON, PROC_RUNNER); + child_add(env, smtp(env), CHILD_DAEMON, PROC_SMTP); +} -int -check_child(pid_t pid, const char *pname) +void +child_add(struct smtpd *env, pid_t pid, int type, int title) { - int status; + struct child *child; - if (waitpid(pid, &status, WNOHANG) > 0) { - if (WIFEXITED(status)) { - log_warnx("check_child: lost child: %s exited", pname); - return (1); - } - if (WIFSIGNALED(status)) { - log_warnx("check_child: lost child: %s terminated; " - "signal %d", pname, WTERMSIG(status)); - return (1); - } - } + if ((child = calloc(1, sizeof(*child))) == NULL) + fatal(NULL); - return (0); + child->pid = pid; + child->type = type; + child->title = title; + + if (SPLAY_INSERT(childtree, &env->children, child) != NULL) + fatalx("child_add: double insert"); +} + +void +child_del(struct smtpd *env, pid_t pid) +{ + struct child *p; + + p = child_lookup(env, pid); + if (p == NULL) + fatalx("child_del: unknown child"); + + if (SPLAY_REMOVE(childtree, &env->children, p) == NULL) + fatalx("child_del: tree remove failed"); + free(p); +} + +struct child * +child_lookup(struct smtpd *env, pid_t pid) +{ + struct child key; + + key.pid = pid; + return SPLAY_FIND(childtree, &env->children, &key); } int @@ -1120,7 +1123,6 @@ parent_mailbox_open(char *path, struct passwd *pw, struct batch *batchp) { pid_t pid; int pipefd[2]; - struct mdaproc *mdaproc; char sender[MAX_PATH_SIZE]; /* This can never happen, but better safe than sorry. */ @@ -1152,8 +1154,6 @@ parent_mailbox_open(char *path, struct passwd *pw, struct batch *batchp) } if (pid == 0) { - setproctitle("mail.local"); - close(pipefd[0]); close(STDOUT_FILENO); close(STDERR_FILENO); @@ -1166,13 +1166,7 @@ parent_mailbox_open(char *path, struct passwd *pw, struct batch *batchp) if (seteuid(pw->pw_uid) == -1) fatal("privdrop failed"); - mdaproc = calloc(1, sizeof (struct mdaproc)); - if (mdaproc == NULL) - fatal("calloc"); - mdaproc->pid = pid; - mdaproc->type = CHILD_MDA; - - SPLAY_INSERT(mdaproctree, &batchp->env->mdaproc_queue, mdaproc); + child_add(batchp->env, pid, CHILD_MDA, -1); close(pipefd[1]); return pipefd[0]; @@ -1253,7 +1247,6 @@ parent_external_mda(char *path, struct passwd *pw, struct batch *batchp) int pipefd[2]; arglist args; char *word; - struct mdaproc *mdaproc; char *envp[2]; log_debug("executing filter as user: %s", pw->pw_name); @@ -1277,8 +1270,6 @@ parent_external_mda(char *path, struct passwd *pw, struct batch *batchp) } if (pid == 0) { - setproctitle("external MDA"); - if (seteuid(0) == -1) fatal("privraise failed"); if (setgroups(1, &pw->pw_gid) || @@ -1314,13 +1305,7 @@ parent_external_mda(char *path, struct passwd *pw, struct batch *batchp) _exit(1); } - mdaproc = calloc(1, sizeof (struct mdaproc)); - if (mdaproc == NULL) - fatal("calloc"); - mdaproc->pid = pid; - mdaproc->type = CHILD_MDA; - - SPLAY_INSERT(mdaproctree, &batchp->env->mdaproc_queue, mdaproc); + child_add(batchp->env, pid, CHILD_MDA, -1); close(pipefd[0]); return pipefd[1]; @@ -1331,7 +1316,6 @@ parent_enqueue_offline(struct smtpd *env, char *runner_path) { char path[MAXPATHLEN]; struct passwd *pw; - struct mdaproc *mdaproc; struct stat sb; pid_t pid; @@ -1432,13 +1416,7 @@ parent_enqueue_offline(struct smtpd *env, char *runner_path) _exit(1); } - mdaproc = calloc(1, sizeof (struct mdaproc)); - if (mdaproc == NULL) - fatal("calloc"); - mdaproc->pid = pid; - mdaproc->type = CHILD_ENQUEUE_OFFLINE; - - SPLAY_INSERT(mdaproctree, &env->mdaproc_queue, mdaproc); + child_add(env, pid, CHILD_ENQUEUE_OFFLINE, -1); return (1); } @@ -1548,15 +1526,15 @@ path_starts_with(char *file, char *prefix) } int -mdaproc_cmp(struct mdaproc *s1, struct mdaproc *s2) +child_cmp(struct child *c1, struct child *c2) { - if (s1->pid < s2->pid) + if (c1->pid < c2->pid) return (-1); - if (s1->pid > s2->pid) + if (c1->pid > c2->pid) return (1); return (0); } -SPLAY_GENERATE(mdaproctree, mdaproc, mdaproc_nodes, mdaproc_cmp); +SPLAY_GENERATE(childtree, child, entry, child_cmp); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index d8ff2ca2bf4..51a6f667341 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.113 2009/05/24 14:22:24 jacekm Exp $ */ +/* $OpenBSD: smtpd.h,v 1.114 2009/05/24 14:38:56 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -496,15 +496,17 @@ enum batch_flags { enum child_type { CHILD_INVALID, + CHILD_DAEMON, CHILD_MDA, CHILD_ENQUEUE_OFFLINE }; -struct mdaproc { - SPLAY_ENTRY(mdaproc) mdaproc_nodes; +struct child { + SPLAY_ENTRY(child) entry; pid_t pid; enum child_type type; + enum smtp_proc_type title; }; struct batch { @@ -658,6 +660,7 @@ struct smtpd { struct imsgbuf *sc_ibufs[PROC_COUNT]; int sc_instances[PROC_COUNT]; int sc_instance; + char *sc_title[PROC_COUNT]; struct passwd *sc_pw; char sc_hostname[MAXHOSTNAMELEN]; TAILQ_HEAD(listenerlist, listener) sc_listeners; @@ -667,9 +670,9 @@ struct smtpd { SPLAY_HEAD(msgtree, message) sc_messages; SPLAY_HEAD(ssltree, ssl) sc_ssl; - SPLAY_HEAD(batchtree, batch) batch_queue; - SPLAY_HEAD(mdaproctree, mdaproc) mdaproc_queue; - SPLAY_HEAD(lkatree, lkasession) lka_sessions; + SPLAY_HEAD(batchtree, batch) batch_queue; + SPLAY_HEAD(childtree, child) children; + SPLAY_HEAD(lkatree, lkasession) lka_sessions; struct stats *stats; }; @@ -847,6 +850,10 @@ int imsg_get_fd(struct imsgbuf *, struct imsg *); int imsg_flush(struct imsgbuf *); void imsg_clear(struct imsgbuf *); +/* smtpd.c */ +int child_cmp(struct child *, struct child *); +SPLAY_PROTOTYPE(childtree, child, entry, child_cmp); + /* lka.c */ pid_t lka(struct smtpd *); int lkasession_cmp(struct lkasession *, struct lkasession *); @@ -903,8 +910,6 @@ char *map_dblookup(struct smtpd *, char *, char *); /* mda.c */ pid_t mda(struct smtpd *); -int mdaproc_cmp(struct mdaproc *, struct mdaproc *); -SPLAY_PROTOTYPE(mdaproctree, mdaproc, mdaproc_nodes, mdaproc_cmp); /* mta.c */ pid_t mta(struct smtpd *); @@ -953,7 +958,7 @@ int store_message(struct batch *, struct message *, void purge_config(struct smtpd *, u_int8_t); void unconfigure(struct smtpd *); void configure(struct smtpd *); -void init_peers(struct smtpd *); +void init_pipes(struct smtpd *); void config_pipes(struct smtpd *, struct peer *, u_int); void config_peers(struct smtpd *, struct peer *, u_int); @@ -976,7 +981,7 @@ SPLAY_PROTOTYPE(ssltree, ssl, ssl_nodes, ssl_cmp); int ssl_ctx_use_private_key(void *, char *, off_t); int ssl_ctx_use_certificate_chain(void *, char *, off_t); -/* smtpd.c */ +/* map.c */ struct map *map_find(struct smtpd *, objid_t); struct map *map_findbyname(struct smtpd *, const char *); |