Browse Source

SIGHUP handler

Serj Kalichev 6 years ago
parent
commit
143d1c6bc8
1 changed files with 21 additions and 3 deletions
  1. 21 3
      birq.c

+ 21 - 3
birq.c

@@ -43,6 +43,9 @@
 static volatile int sigterm = 0; /* Exit if 1 */
 static void sighandler(int signo);
 
+static volatile int sighup = 0; /* Re-read config file */
+static void sighup_handler(int signo);
+
 static void help(int status, const char *argv0);
 static struct options *opts_init(void);
 static void opts_free(struct options *opts);
@@ -152,6 +155,15 @@ int main(int argc, char **argv)
 	sigaction(SIGINT, &sig_act, NULL);
 	sigaction(SIGQUIT, &sig_act, NULL);
 
+	/* SIGHUP handler */
+	sigemptyset(&sig_set);
+	sigaddset(&sig_set, SIGHUP);
+
+	sig_act.sa_flags = 0;
+	sig_act.sa_mask = sig_set;
+	sig_act.sa_handler = &sighup_handler;
+	sigaction(SIGHUP, &sig_act, NULL);
+
 	/* Randomize */
 	srand(time(NULL));
 
@@ -253,15 +265,21 @@ err:
 }
 
 /*--------------------------------------------------------- */
-/*
- * Signal handler for temination signals (like SIGTERM, SIGINT, ...)
- */
+/* Signal handler for temination signals (like SIGTERM, SIGINT, ...) */
 static void sighandler(int signo)
 {
 	sigterm = 1;
 	signo = signo; /* Happy compiler */
 }
 
+/*--------------------------------------------------------- */
+/* Re-read config file on SIGHUP */
+static void sighup_handler(int signo)
+{
+	sighup = 1;
+	signo = signo; /* Happy compiler */
+}
+
 /*--------------------------------------------------------- */
 /* Initialize option structure by defaults */
 static struct options *opts_init(void)