[master] ffcbf13 Santitize the teardown process a little bit.
Poul-Henning Kamp
phk at FreeBSD.org
Sun Nov 19 12:42:07 UTC 2017
commit ffcbf1332a003e2449b5cf5861b7af3303faf85a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sun Nov 19 12:40:29 2017 +0000
Santitize the teardown process a little bit.
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index 973cada..c1a371d 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -666,7 +666,8 @@ mgt_cli_master(const char *M_arg)
error = VSS_resolver(M_arg, NULL, marg_cb, NULL, &err);
if (err != NULL)
- ARGV_ERR("Could not resolve -M argument to address\n\t%s\n", err);
+ ARGV_ERR("Could not resolve -M argument to address\n\t%s\n",
+ err);
AZ(error);
if (VTAILQ_EMPTY(&m_addr_list))
ARGV_ERR("Could not resolve -M argument to address\n");
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index c4f9d94..5b778b5 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -190,6 +190,7 @@ mgt_stdin_close(void *priv)
if (d_flag) {
MCH_Stop_Child();
mgt_cli_close_all();
+ VEV_Destroy(&mgt_evb);
(void)VPF_Remove(pfh1);
if (pfh2 != NULL)
(void)VPF_Remove(pfh2);
@@ -365,11 +366,11 @@ mgt_sigint(const struct vev *e, int what)
(void)e;
(void)what;
- MGT_Complain(C_ERR, "Manager got SIGINT");
+ MGT_Complain(C_ERR, "Manager got %s", e->name);
(void)fflush(stdout);
if (MCH_Running())
MCH_Stop_Child();
- exit(0);
+ return (-42);
}
/*--------------------------------------------------------------------*/
@@ -882,21 +883,22 @@ main(int argc, char * const *argv)
AN(e);
e->sig = SIGTERM;
e->callback = mgt_sigint;
- e->name = "mgt_sigterm";
+ e->name = "SIGTERM";
AZ(VEV_Start(mgt_evb, e));
e = VEV_Alloc();
AN(e);
e->sig = SIGINT;
e->callback = mgt_sigint;
- e->name = "mgt_sigint";
+ e->name = "SIGINT";
AZ(VEV_Start(mgt_evb, e));
o = VEV_Loop(mgt_evb);
- if (o != 0)
+ if (o != 0 && o != -42)
MGT_Complain(C_ERR, "VEV_Loop() = %d", o);
MGT_Complain(C_INFO, "manager dies");
+ VEV_Destroy(&mgt_evb);
(void)VPF_Remove(pfh1);
if (pfh2 != NULL)
(void)VPF_Remove(pfh2);
diff --git a/include/vev.h b/include/vev.h
index 0c92f4b..edd9014 100644
--- a/include/vev.h
+++ b/include/vev.h
@@ -61,12 +61,12 @@ struct vev {
};
struct vev_root *VEV_New(void);
-void VEV_Destroy(struct vev_root *evb);
+void VEV_Destroy(struct vev_root **);
struct vev *VEV_Alloc(void);
-int VEV_Start(struct vev_root *evb, struct vev *e);
-void VEV_Stop(struct vev_root *evb, struct vev *e);
+int VEV_Start(struct vev_root *, struct vev *);
+void VEV_Stop(struct vev_root *, struct vev *);
-int VEV_Once(struct vev_root *evb);
-int VEV_Loop(struct vev_root *evb);
+int VEV_Once(struct vev_root *);
+int VEV_Loop(struct vev_root *);
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index b8f3078..d04a80f 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -215,8 +215,13 @@ VEV_New(void)
/*--------------------------------------------------------------------*/
void
-VEV_Destroy(struct vev_root *evb)
+VEV_Destroy(struct vev_root **evbp)
{
+ struct vev_root *evb;
+
+ AN(evbp);
+ evb = *evbp;
+ *evbp = NULL;
CHECK_OBJ_NOTNULL(evb, VEV_BASE_MAGIC);
assert(evb->thread == pthread_self());
evb->magic = 0;
@@ -369,7 +374,7 @@ vev_sched_timeout(struct vev_root *evb, struct vev *e, double t)
static int
vev_sched_signal(struct vev_root *evb)
{
- int i, j;
+ int i, j, retval = 1;
struct vevsig *es;
struct vev *e;
@@ -386,8 +391,10 @@ vev_sched_signal(struct vev_root *evb)
VEV_Stop(evb, e);
free(e);
}
+ if (i < 0)
+ retval = i;
}
- return (1);
+ return (retval);
}
int
@@ -395,7 +402,7 @@ VEV_Once(struct vev_root *evb)
{
double t;
struct vev *e;
- int i, j, k, tmo;
+ int i, j, k, tmo, retval = 1;
CHECK_OBJ_NOTNULL(evb, VEV_BASE_MAGIC);
assert(evb->thread == pthread_self());
@@ -454,8 +461,10 @@ VEV_Once(struct vev_root *evb)
VEV_Stop(evb, e);
free(e);
}
+ if (k < 0)
+ retval = k;
}
}
AZ(i);
- return (1);
+ return (retval);
}
More information about the varnish-commit
mailing list