Commit f3e67485 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Signals must be forwarded to VUTs by programs

This is a first step away from the global VUT symbol, handled outside of
VUT_Setup in preparation for the "unglobalization".
parent 7f9e1e76
......@@ -484,6 +484,12 @@ profile_error(const char *s)
exit(1);
}
static void
vut_sighandler(int sig)
{
VUT_Signaled(&VUT, sig);
}
int
main(int argc, char **argv)
{
......@@ -608,6 +614,7 @@ main(int argc, char **argv)
log_ten = log(10.0);
VUT_Signal(vut_sighandler);
VUT_Setup();
ident = VSM_Dup(VUT.vsm, "Arg", "-i");
if (pthread_create(&thr, NULL, do_curses, NULL) != 0)
......
......@@ -114,6 +114,12 @@ sighup(void)
return (1);
}
static void
vut_sighandler(int sig)
{
VUT_Signaled(&VUT, sig);
}
int
main(int argc, char * const *argv)
{
......@@ -166,6 +172,7 @@ main(int argc, char * const *argv)
LOG.fo = stdout;
VUT.idle_f = flushout;
VUT_Signal(vut_sighandler);
VUT_Setup();
VUT_Main();
VUT_Fini();
......
......@@ -46,6 +46,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <inttypes.h>
#include <limits.h>
......@@ -1108,6 +1109,12 @@ sighup(void)
return (1);
}
static void
vut_sighandler(int sig)
{
VUT_Signaled(&VUT, sig);
}
static char *
read_format(const char *formatfile)
{
......@@ -1228,6 +1235,7 @@ main(int argc, char * const *argv)
CTX.fo = stdout;
VUT.idle_f = flushout;
VUT_Signal(vut_sighandler);
VUT_Setup();
VUT_Main();
VUT_Fini();
......
......@@ -34,6 +34,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
......
......@@ -184,6 +184,12 @@ sighup(void)
return (1);
}
static void
vut_sighandler(int sig)
{
VUT_Signaled(&VUT, sig);
}
static void
update(int p)
{
......@@ -362,6 +368,7 @@ main(int argc, char **argv)
if (optind != argc)
usage(1);
VUT_Signal(vut_sighandler);
VUT_Setup();
ident = VSM_Dup(VUT.vsm, "Arg", "-i");
if (!once) {
......
......@@ -31,6 +31,7 @@
struct vopt_spec;
typedef void VUT_sighandler_f(int);
typedef int VUT_cb_f(void);
struct VUT {
......@@ -75,6 +76,9 @@ int VUT_Arg(int opt, const char *arg);
void VUT_Init(const char *progname, int argc, char * const *argv,
const struct vopt_spec *);
void VUT_Signal(VUT_sighandler_f);
void VUT_Signaled(struct VUT *, int);
void VUT_Setup(void);
int VUT_Main(void);
void VUT_Fini(void);
......@@ -134,6 +134,8 @@ LIBVARNISHAPI_2.0 {
VUT_Init;
VUT_Main;
VUT_Setup;
VUT_Signal;
VUT_Signaled;
local:
*;
......
......@@ -82,15 +82,6 @@ vut_vpf_remove(void)
}
}
static void
vut_signal(int sig)
{
VUT.sighup |= (sig == SIGHUP);
VUT.sigint |= (sig == SIGINT || sig == SIGTERM);
VUT.sigusr1 |= (sig == SIGUSR1);
}
static int __match_proto__(VSLQ_dispatch_f)
vut_dispatch(struct VSL_data *vsl, struct VSL_transaction * const trans[],
void *priv)
......@@ -215,6 +206,27 @@ VUT_Init(const char *progname, int argc, char * const *argv,
VUT.k_arg = -1;
}
void
VUT_Signal(VUT_sighandler_f sig_cb)
{
AN(sig_cb);
(void)signal(SIGHUP, sig_cb);
(void)signal(SIGINT, sig_cb);
(void)signal(SIGTERM, sig_cb);
(void)signal(SIGUSR1, sig_cb);
}
void
VUT_Signaled(struct VUT *vut, int sig)
{
AN(vut);
vut->sighup |= (sig == SIGHUP);
vut->sigint |= (sig == SIGINT || sig == SIGTERM);
vut->sigusr1 |= (sig == SIGUSR1);
}
void
VUT_Setup(void)
{
......@@ -254,12 +266,6 @@ VUT_Setup(void)
// Cursor is handled in VUT_Main()
}
/* Signal handlers */
(void)signal(SIGHUP, vut_signal);
(void)signal(SIGINT, vut_signal);
(void)signal(SIGTERM, vut_signal);
(void)signal(SIGUSR1, vut_signal);
/* Open PID file */
if (VUT.P_arg) {
if (pfh != NULL)
......
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