commit 89e3f7de1ee3de49ac377ee4e1c508f13a2156c9
parent 8105e96873bb5a888eaadcede8f9b645b3a0d20f
Author: Naveen Narayanan <zerous@nocebo.space>
Date: Sat, 23 Oct 2021 16:29:31 +0200
Use SIGHUP to shutdown the daemon
Diffstat:
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/main.c b/main.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -24,6 +25,7 @@
int fd_black;
int fd_white;
int ignore;
+int shutdown;
char *argv0;
static char buf[BUFSZ];
@@ -162,6 +164,12 @@ daemon_init(void)
umask(0);
}
+void
+terminate(int a)
+{
+ shutdown = 1;
+}
+
int
main(int argc, char **argv)
{
@@ -172,7 +180,7 @@ main(int argc, char **argv)
struct attacker *a;
time_t now;
- debug = 0;
+ shutdown = debug = 0;
ARGBEGIN {
case 'd':
@@ -185,6 +193,8 @@ main(int argc, char **argv)
if (!debug)
daemon_init();
+ signal(SIGHUP, terminate);
+
fd = open(sshlog, O_RDONLY);
if (fd == -1)
err(1, "open failed: %s", sshlog);
@@ -249,6 +259,9 @@ main(int argc, char **argv)
now = time(NULL);
for ( ; ; ) {
+ if (shutdown)
+ break;
+
unban(NULL, &head);
if ((line = readline(fd)) == NULL) {
usleep(5);