Commit 0b2ae6b0 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Add signal handlers to utilities library for graceful shutdown

parent d72139a6
...@@ -49,6 +49,8 @@ struct VUT { ...@@ -49,6 +49,8 @@ struct VUT {
struct VSLQ *vslq; struct VSLQ *vslq;
FILE *fo; FILE *fo;
struct vpf_fh *pfh; struct vpf_fh *pfh;
int sighup;
int sigint;
}; };
extern struct VUT VUT; extern struct VUT VUT;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include "compat/daemon.h" #include "compat/daemon.h"
#include "vpf.h" #include "vpf.h"
...@@ -61,6 +62,20 @@ vut_vpf_remove(void) ...@@ -61,6 +62,20 @@ vut_vpf_remove(void)
} }
} }
static void
vut_sighup(int sig)
{
(void)sig;
VUT.sighup = 1;
}
static void
vut_sigint(int sig)
{
(void)sig;
VUT.sigint = 1;
}
void void
VUT_Error(int status, const char *fmt, ...) VUT_Error(int status, const char *fmt, ...)
{ {
...@@ -186,6 +201,11 @@ VUT_Setup(void) ...@@ -186,6 +201,11 @@ VUT_Setup(void)
VUT_Error(1, "Query parse error (%s)", VSL_Error(VUT.vsl)); VUT_Error(1, "Query parse error (%s)", VSL_Error(VUT.vsl));
AZ(c); AZ(c);
/* Signal handlers */
(void)signal(SIGHUP, vut_sighup);
(void)signal(SIGINT, vut_sigint);
(void)signal(SIGTERM, vut_sigint);
/* Open PID file */ /* Open PID file */
if (VUT.P_arg) { if (VUT.P_arg) {
AZ(VUT.pfh); AZ(VUT.pfh);
...@@ -238,8 +258,8 @@ VUT_Main(VSLQ_dispatch_f *func, void *priv) ...@@ -238,8 +258,8 @@ VUT_Main(VSLQ_dispatch_f *func, void *priv)
priv = VUT.fo; priv = VUT.fo;
} }
while (1) { while (!VUT.sigint) {
while (VUT.vslq == NULL) { if (VUT.vslq == NULL) {
AZ(VUT.r_arg); AZ(VUT.r_arg);
AN(VUT.vsm); AN(VUT.vsm);
VTIM_sleep(0.1); VTIM_sleep(0.1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment