summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/ca.c
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2016-09-08 12:06:44 +0000
committerEric Faurot <eric@cvs.openbsd.org>2016-09-08 12:06:44 +0000
commitd395347ea04d4bf7be26f062247eea77349335bb (patch)
tree1821fd13620ca90cfccec374a83afc212d80c6bd /usr.sbin/smtpd/ca.c
parent9fef4d3d3850b07b7e25b2a09438cb9ccd9f4eb2 (diff)
Streamline the daemon shutdown sequence.
Only the parent process handles SIGTERM and SIGINT. Upon receiving one of those, it closes all imsg sockets and waitpid() for the children. It fatal()s if one of the sockets is closed unexpectedly. Other processes exit() "normally" when one of the imsg sockets is closed. ok gilles@ sunil@
Diffstat (limited to 'usr.sbin/smtpd/ca.c')
-rw-r--r--usr.sbin/smtpd/ca.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/usr.sbin/smtpd/ca.c b/usr.sbin/smtpd/ca.c
index 0ae36844821..a7e7b03013a 100644
--- a/usr.sbin/smtpd/ca.c
+++ b/usr.sbin/smtpd/ca.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ca.c,v 1.24 2016/09/04 16:10:31 eric Exp $ */
+/* $OpenBSD: ca.c,v 1.25 2016/09/08 12:06:43 eric Exp $ */
/*
* Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
@@ -66,29 +66,14 @@ static uint64_t rsae_reqid = 0;
static void
ca_shutdown(void)
{
- log_info("info: ca agent exiting");
+ log_debug("debug: ca agent exiting");
_exit(0);
}
-static void
-ca_sig_handler(int sig, short event, void *p)
-{
- switch (sig) {
- case SIGINT:
- case SIGTERM:
- ca_shutdown();
- break;
- default:
- fatalx("ca_sig_handler: unexpected signal");
- }
-}
-
int
ca(void)
{
struct passwd *pw;
- struct event ev_sigint;
- struct event ev_sigterm;
purge_config(PURGE_LISTENERS|PURGE_TABLES|PURGE_RULES);
@@ -110,10 +95,8 @@ ca(void)
imsg_callback = ca_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, ca_sig_handler, NULL);
- signal_set(&ev_sigterm, SIGTERM, ca_sig_handler, NULL);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
+ signal(SIGINT, SIG_IGN);
+ signal(SIGTERM, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
@@ -243,6 +226,9 @@ ca_imsg(struct mproc *p, struct imsg *imsg)
uint64_t id;
int v;
+ if (imsg == NULL)
+ ca_shutdown();
+
if (p->proc == PROC_PARENT) {
switch (imsg->hdr.type) {
case IMSG_CONF_START: