[master] 0b2ae6b Add signal handlers to utilities library for graceful shutdown
Martin Blix Grydeland
martin at varnish-cache.org
Thu Jun 13 12:41:24 CEST 2013
commit 0b2ae6b06614cab268393ad6d506dcfbe9a16314
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Mon May 27 16:31:28 2013 +0200
Add signal handlers to utilities library for graceful shutdown
diff --git a/include/vut.h b/include/vut.h
index a016994..0fdf8de 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -49,6 +49,8 @@ struct VUT {
struct VSLQ *vslq;
FILE *fo;
struct vpf_fh *pfh;
+ int sighup;
+ int sigint;
};
extern struct VUT VUT;
diff --git a/lib/libvarnishtools/vut.c b/lib/libvarnishtools/vut.c
index f4f99c0..05e7ff5 100644
--- a/lib/libvarnishtools/vut.c
+++ b/lib/libvarnishtools/vut.c
@@ -38,6 +38,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <signal.h>
#include "compat/daemon.h"
#include "vpf.h"
@@ -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
VUT_Error(int status, const char *fmt, ...)
{
@@ -186,6 +201,11 @@ VUT_Setup(void)
VUT_Error(1, "Query parse error (%s)", VSL_Error(VUT.vsl));
AZ(c);
+ /* Signal handlers */
+ (void)signal(SIGHUP, vut_sighup);
+ (void)signal(SIGINT, vut_sigint);
+ (void)signal(SIGTERM, vut_sigint);
+
/* Open PID file */
if (VUT.P_arg) {
AZ(VUT.pfh);
@@ -238,8 +258,8 @@ VUT_Main(VSLQ_dispatch_f *func, void *priv)
priv = VUT.fo;
}
- while (1) {
- while (VUT.vslq == NULL) {
+ while (!VUT.sigint) {
+ if (VUT.vslq == NULL) {
AZ(VUT.r_arg);
AN(VUT.vsm);
VTIM_sleep(0.1);
More information about the varnish-commit
mailing list