From 75decc80e7b97e394d70a74281c7976e64d678dc Mon Sep 17 00:00:00 2001 From: Thibaut Artis Date: Fri, 12 Apr 2024 17:17:40 +0200 Subject: [PATCH 1/4] vev: use sigaction instead of sighandler --- lib/libvarnish/vev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c index 8ce5837fb1c..c9335e6a14e 100644 --- a/lib/libvarnish/vev.c +++ b/lib/libvarnish/vev.c @@ -175,10 +175,11 @@ 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]; @@ -278,8 +279,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; } From 24c7d154207dcea0e4ace3e933a8464aa6b634df Mon Sep 17 00:00:00 2001 From: Thibaut Artis Date: Fri, 12 Apr 2024 17:37:51 +0200 Subject: [PATCH 2/4] vev: keep a copy of siginfo_t in vevsig (OBE commit message removed during merge/rebase by @nigoroll) --- bin/varnishd/mgt/mgt_cli.c | 1 + bin/varnishd/mgt/mgt_vcl.c | 3 +++ include/vev.h | 1 + lib/libvarnish/vev.c | 10 +++++++++- 4 files changed, 14 insertions(+), 1 deletion(-) 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_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 c9335e6a14e..ff097310da1 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; @@ -183,8 +184,11 @@ vev_sigaction(int sig, siginfo_t *siginfo, 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; } @@ -400,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); From d5ddb5f8ce2f43f88b3963a0e97ba6942fedf017 Mon Sep 17 00:00:00 2001 From: Thibaut Artis Date: Tue, 7 May 2024 16:26:51 +0200 Subject: [PATCH 3/4] mgt_main: print signal PID of origin in mgt_sigint --- bin/varnishd/mgt/mgt_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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(); From 0fa9533594ec90884da09eb2f1642a70d3814b1b Mon Sep 17 00:00:00 2001 From: Thibaut Artis Date: Tue, 30 Apr 2024 11:28:21 +0200 Subject: [PATCH 4/4] vev: Restore a default handler without flags --- lib/libvarnish/vev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c index ff097310da1..8269e751c79 100644 --- a/lib/libvarnish/vev.c +++ b/lib/libvarnish/vev.c @@ -343,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;