aboutsummaryrefslogtreecommitdiff
path: root/gmid.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-03-20 08:51:17 +0000
committerOmar Polo <op@omarpolo.com>2021-03-20 08:51:17 +0000
commit1d3eb470b0e5961d74cf202567a0e4c0b57f7f12 (patch)
treef66f65155535a68bd5ed7158bad2922139aea575 /gmid.c
parent62e001b06778c96d0deebceddf1913f7b57ab2d6 (diff)
quit every process cleanly when receiving SIGINT or SIGTERM
Diffstat (limited to 'gmid.c')
-rw-r--r--gmid.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/gmid.c b/gmid.c
index 0714df4..cedcc93 100644
--- a/gmid.c
+++ b/gmid.c
@@ -249,15 +249,19 @@ free_config(void)
tls_config_free(tlsconf);
}
-static void
-wait_sighup(void)
+static int
+wait_signal(void)
{
sigset_t mask;
int signo;
sigemptyset(&mask);
sigaddset(&mask, SIGHUP);
+ sigaddset(&mask, SIGINT);
+ sigaddset(&mask, SIGTERM);
sigwait(&mask, &signo);
+
+ return signo == SIGHUP;
}
void
@@ -511,7 +515,9 @@ main(int argc, char **argv)
close(p[1]);
imsg_init(&exibuf, p[0]);
- wait_sighup();
+ if (!wait_signal())
+ break;
+
log_info(NULL, "reloading configuration %s", config_path);
/* close the executor (it'll close the servers too) */
@@ -543,4 +549,12 @@ main(int argc, char **argv)
if (sock6 == -1 && conf.ipv6)
sock6 = make_socket(conf.port, AF_INET6);
}
+
+ imsg_compose(&exibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
+ imsg_flush(&exibuf);
+
+ imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
+ imsg_flush(&logibuf);
+
+ return 0;
}