summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/smtpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/smtpd/smtpd.c')
-rw-r--r--usr.sbin/smtpd/smtpd.c79
1 files changed, 77 insertions, 2 deletions
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 57820ce4d21..670feb0c199 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.93 2009/12/24 14:19:46 gilles Exp $ */
+/* $OpenBSD: smtpd.c,v 1.94 2010/01/03 14:37:37 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -58,6 +58,7 @@ void parent_dispatch_mfa(int, short, void *);
void parent_dispatch_mta(int, short, void *);
void parent_dispatch_smtp(int, short, void *);
void parent_dispatch_runner(int, short, void *);
+void parent_dispatch_queue(int, short, void *);
void parent_dispatch_control(int, short, void *);
void parent_sig_handler(int, short, void *);
int parent_open_message_file(struct batch *);
@@ -646,6 +647,51 @@ parent_dispatch_smtp(int fd, short event, void *p)
}
void
+parent_dispatch_queue(int sig, short event, void *p)
+{
+ struct smtpd *env = p;
+ struct imsgev *iev;
+ struct imsgbuf *ibuf;
+ struct imsg imsg;
+ ssize_t n;
+
+ iev = env->sc_ievs[PROC_QUEUE];
+ ibuf = &iev->ibuf;
+
+ if (event & EV_READ) {
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("imsg_read_error");
+ if (n == 0) {
+ /* this pipe is dead, so remove the event handler */
+ event_del(&iev->ev);
+ event_loopexit(NULL);
+ return;
+ }
+ }
+
+ if (event & EV_WRITE) {
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("msgbuf_write");
+ }
+
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("parent_dispatch_queue: imsg_get error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_warnx("parent_dispatch_queue: got imsg %d",
+ imsg.hdr.type);
+ fatalx("parent_dispatch_queue: unexpected imsg");
+ }
+ imsg_free(&imsg);
+ }
+ imsg_event_add(iev);
+}
+
+void
parent_dispatch_runner(int sig, short event, void *p)
{
struct smtpd *env = p;
@@ -755,6 +801,31 @@ parent_dispatch_control(int sig, short event, void *p)
imsg_compose_event(iev, IMSG_CONF_RELOAD, 0, 0, -1, r, sizeof(*r));
break;
}
+ case IMSG_CTL_VERBOSE: {
+ int verbose;
+
+ IMSG_SIZE_CHECK(&verbose);
+
+ memcpy(&verbose, imsg.data, sizeof(verbose));
+ log_verbose(verbose);
+
+ /* forward to other processes */
+ imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_CTL_VERBOSE,
+ 0, 0, -1, &verbose, sizeof(verbose));
+ imsg_compose_event(env->sc_ievs[PROC_MDA], IMSG_CTL_VERBOSE,
+ 0, 0, -1, &verbose, sizeof(verbose));
+ imsg_compose_event(env->sc_ievs[PROC_MFA], IMSG_CTL_VERBOSE,
+ 0, 0, -1, &verbose, sizeof(verbose));
+ imsg_compose_event(env->sc_ievs[PROC_MTA], IMSG_CTL_VERBOSE,
+ 0, 0, -1, &verbose, sizeof(verbose));
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE], IMSG_CTL_VERBOSE,
+ 0, 0, -1, &verbose, sizeof(verbose));
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_CTL_VERBOSE,
+ 0, 0, -1, &verbose, sizeof(verbose));
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_CTL_VERBOSE,
+ 0, 0, -1, &verbose, sizeof(verbose));
+ break;
+ }
default:
log_warnx("parent_dispatch_control: got imsg %d",
imsg.hdr.type);
@@ -857,7 +928,7 @@ int
main(int argc, char *argv[])
{
int c;
- int debug;
+ int debug, verbose;
int opts;
const char *conffile = CONF_FILE;
struct smtpd env;
@@ -873,11 +944,13 @@ main(int argc, char *argv[])
{ PROC_MFA, parent_dispatch_mfa },
{ PROC_MTA, parent_dispatch_mta },
{ PROC_SMTP, parent_dispatch_smtp },
+ { PROC_QUEUE, parent_dispatch_queue },
{ PROC_RUNNER, parent_dispatch_runner }
};
opts = 0;
debug = 0;
+ verbose = 0;
log_init(1);
@@ -899,6 +972,7 @@ main(int argc, char *argv[])
conffile = optarg;
break;
case 'v':
+ verbose = 1;
opts |= SMTPD_OPT_VERBOSE;
break;
default:
@@ -932,6 +1006,7 @@ main(int argc, char *argv[])
errx(1, "invalid directory permissions");
log_init(debug);
+ log_verbose(verbose);
if (!debug)
if (daemon(0, 0) == -1)