diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index d0b28bf6152..f49bb358db2 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 4db07013cd9..d3eb09a9065 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -445,9 +445,8 @@ static int v_matchproto_(vev_cb_f) mgt_sigint(const struct vev *e, int what) { - (void)e; (void)what; - MGT_Complain(C_ERR, "Manager got %s", e->name); + MGT_Complain(C_ERR, "Manager got %s from PID %jd", e->name, (intmax_t)e->siginfo->si_pid); (void)fflush(stdout); if (MCH_Running()) MCH_Stop_Child(); diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index 9c4e01e9c28..cf437cc609f 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -33,7 +33,10 @@ #include "config.h" +#include +#include #include +#include #include #include #include diff --git a/include/vev.h b/include/vev.h index 197c14882ff..556abc648be 100644 --- a/include/vev.h +++ b/include/vev.h @@ -53,6 +53,7 @@ struct vev { unsigned sig_flags; double timeout; vev_cb_f *callback; + siginfo_t *siginfo; void *priv; /* priv */ diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c index 8ce5837fb1c..8269e751c79 100644 --- a/lib/libvarnish/vev.c +++ b/lib/libvarnish/vev.c @@ -59,6 +59,7 @@ struct vevsig { struct vev *vev; struct sigaction sigact; unsigned char happened; + siginfo_t siginfo[1]; }; static struct vevsig *vev_sigs; @@ -175,15 +176,19 @@ vev_get_sig(int sig) /*--------------------------------------------------------------------*/ static void -vev_sighandler(int sig) +vev_sigaction(int sig, siginfo_t *siginfo, void *ctx) { struct vevsig *es; + (void)ctx; assert(sig < vev_nsig); assert(vev_sigs != NULL); es = &vev_sigs[sig]; - if (!es->happened) + if (!es->happened) { es->vevb->psig++; + memcpy(es->siginfo, siginfo, sizeof *es->siginfo); + es->vev->siginfo = es->siginfo; + } es->happened = 1; } @@ -278,8 +283,8 @@ VEV_Start(struct vev_root *evb, struct vev *e) AZ(es->happened); es->vev = e; es->vevb = evb; - es->sigact.sa_flags = e->sig_flags; - es->sigact.sa_handler = vev_sighandler; + es->sigact.sa_flags = e->sig_flags | SA_SIGINFO; + es->sigact.sa_sigaction = vev_sigaction; } else { es = NULL; } @@ -338,7 +343,7 @@ VEV_Stop(struct vev_root *evb, struct vev *e) assert(es->vev == e); es->vev = NULL; es->vevb = NULL; - es->sigact.sa_flags = e->sig_flags; + es->sigact.sa_flags = 0; es->sigact.sa_handler = SIG_DFL; AZ(sigaction(e->sig, &es->sigact, NULL)); es->happened = 0; @@ -399,6 +404,10 @@ vev_sched_signal(struct vev_root *evb) e = es->vev; assert(e != NULL); i = e->callback(e, VEV__SIG); + if (e->siginfo != NULL) { + e->siginfo = NULL; + memset(es->siginfo, 0, sizeof *es->siginfo); + } if (i) { VEV_Stop(evb, e); free(e);