Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vev: Log where MGT received its signal from #4139

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/varnishd/mgt/mgt_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
3 changes: 1 addition & 2 deletions bin/varnishd/mgt/mgt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions bin/varnishd/mgt/mgt_vcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

#include "config.h"

#include <errno.h>
cartoush marked this conversation as resolved.
Show resolved Hide resolved
#include <fcntl.h>
#include <fnmatch.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions include/vev.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct vev {
unsigned sig_flags;
double timeout;
vev_cb_f *callback;
siginfo_t *siginfo;
void *priv;

/* priv */
Expand Down
19 changes: 14 additions & 5 deletions lib/libvarnish/vev.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct vevsig {
struct vev *vev;
struct sigaction sigact;
unsigned char happened;
siginfo_t siginfo[1];
nigoroll marked this conversation as resolved.
Show resolved Hide resolved
};

static struct vevsig *vev_sigs;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down