[master] 48a5995 More straigthening out of varnishd teardown path, which means that we now actually *do* get the "child panicked" exit code.
Poul-Henning Kamp
phk at FreeBSD.org
Sun Nov 19 16:30:11 UTC 2017
commit 48a59957c1029f16b970bbfc19dafbedb0b5a5fd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sun Nov 19 16:27:56 2017 +0000
More straigthening out of varnishd teardown path, which means
that we now actually *do* get the "child panicked" exit code.
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 7949d2a..cde0c11 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -78,7 +78,7 @@ void MCH_Cli_Fail(void);
/* mgt_cli.c */
extern struct VCLS *mgt_cls;
-typedef void mgt_cli_close_f(void *priv);
+typedef int mgt_cli_close_f(void *priv);
void mgt_cli_setup(int fdi, int fdo, int auth, const char *ident,
mgt_cli_close_f *close_func, void *priv);
int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index c1a371d..9f0a67d 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -572,13 +572,13 @@ static double M_poll = 0.1;
static VTAILQ_HEAD(,m_addr) m_addr_list =
VTAILQ_HEAD_INITIALIZER(m_addr_list);
-static void __match_proto__(mgt_cli_close_f)
+static int __match_proto__(mgt_cli_close_f)
Marg_closer(void *priv)
{
(void)priv;
- (void)close(M_fd);
M_fd = -1;
+ return(0);
}
static int __match_proto__(vev_cb_f)
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 5b778b5..b7e8251 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -181,25 +181,12 @@ cli_check(const struct cli *cli)
* This function is called when the CLI on stdin is closed.
*/
-static void __match_proto__(mgt_cli_close_f)
+static int __match_proto__(mgt_cli_close_f)
mgt_stdin_close(void *priv)
{
(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);
- exit(0);
- } else {
- VFIL_null_fd(STDIN_FILENO);
- VFIL_null_fd(STDOUT_FILENO);
- VFIL_null_fd(STDERR_FILENO);
- }
+ return (-42);
}
/*--------------------------------------------------------------------
@@ -391,12 +378,13 @@ mgt_uptime(const struct vev *e, int what)
/*--------------------------------------------------------------------*/
-static void __match_proto__(mgt_cli_close_f)
+static int __match_proto__(mgt_cli_close_f)
mgt_I_close(void *priv)
{
(void)priv;
fprintf(stderr, "END of -I file processing\n");
- closefd(&I_fd);
+ I_fd = -1;
+ return (0);
}
/*--------------------------------------------------------------------*/
@@ -897,7 +885,10 @@ main(int argc, char * const *argv)
if (o != 0 && o != -42)
MGT_Complain(C_ERR, "VEV_Loop() = %d", o);
+ MGT_Complain(C_INFO, "manager stopping child");
+ MCH_Stop_Child();
MGT_Complain(C_INFO, "manager dies");
+ mgt_cli_close_all();
VEV_Destroy(&mgt_evb);
(void)VPF_Remove(pfh1);
if (pfh2 != NULL)
diff --git a/bin/varnishtest/tests/c00057.vtc b/bin/varnishtest/tests/c00057.vtc
index fc4a571..4b05a8f 100644
--- a/bin/varnishtest/tests/c00057.vtc
+++ b/bin/varnishtest/tests/c00057.vtc
@@ -49,3 +49,5 @@ client c1 {
txreq
rxresp
} -run
+
+varnish v1 -expectexit 0x20
diff --git a/bin/varnishtest/tests/p00007.vtc b/bin/varnishtest/tests/p00007.vtc
index b0ce377..ddae80d 100644
--- a/bin/varnishtest/tests/p00007.vtc
+++ b/bin/varnishtest/tests/p00007.vtc
@@ -77,3 +77,5 @@ client c1 {
rxresp
expect resp.bodylen == 48
} -run
+
+varnish v1 -expectexit 0x20
diff --git a/bin/varnishtest/tests/t02004.vtc b/bin/varnishtest/tests/t02004.vtc
index 24610d1..cca1faf 100644
--- a/bin/varnishtest/tests/t02004.vtc
+++ b/bin/varnishtest/tests/t02004.vtc
@@ -25,3 +25,5 @@ client c1 {
} -run
varnish v1 -cliok "panic.clear"
+
+varnish v1 -expectexit 0x20
diff --git a/bin/varnishtest/tests/v00010.vtc b/bin/varnishtest/tests/v00010.vtc
index 51f9e65..b948d01 100644
--- a/bin/varnishtest/tests/v00010.vtc
+++ b/bin/varnishtest/tests/v00010.vtc
@@ -84,3 +84,4 @@ client c1 {
} -run
varnish v1 -cliok "panic.clear -z"
+varnish v1 -expectexit 0x20
diff --git a/include/vcli_serve.h b/include/vcli_serve.h
index eff8a4b..67a1792 100644
--- a/include/vcli_serve.h
+++ b/include/vcli_serve.h
@@ -88,7 +88,7 @@ void VCLI_JSON_str(struct cli *cli, const char *str);
void VCLI_JSON_ver(struct cli *cli, unsigned ver, const char * const * av);
void VCLI_SetResult(struct cli *cli, unsigned r);
-typedef void cls_cb_f(void *priv);
+typedef int cls_cb_f(void *priv);
typedef void cls_cbc_f(const struct cli*);
struct VCLS *VCLS_New(struct VCLS *);
void VCLS_SetHooks(struct VCLS *, cls_cbc_f *, cls_cbc_f *);
diff --git a/lib/libvarnish/vcli_serve.c b/lib/libvarnish/vcli_serve.c
index 71c2544..33de8f3 100644
--- a/lib/libvarnish/vcli_serve.c
+++ b/lib/libvarnish/vcli_serve.c
@@ -481,9 +481,10 @@ VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc, void *priv)
return (cfd->cli);
}
-static void
+static int
cls_close_fd(struct VCLS *cs, struct VCLS_fd *cfd)
{
+ int retval = 0;
CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
CHECK_OBJ_NOTNULL(cfd, VCLS_FD_MAGIC);
@@ -491,16 +492,15 @@ cls_close_fd(struct VCLS *cs, struct VCLS_fd *cfd)
VTAILQ_REMOVE(&cs->fds, cfd, list);
cs->nfd--;
VSB_destroy(&cfd->cli->sb);
- if (cfd->closefunc == NULL) {
- (void)close(cfd->fdi);
- if (cfd->fdo != cfd->fdi)
- (void)close(cfd->fdo);
- } else {
- cfd->closefunc(cfd->priv);
- }
+ if (cfd->closefunc != NULL)
+ retval = cfd->closefunc(cfd->priv);
+ (void)close(cfd->fdi);
+ if (cfd->fdo != cfd->fdi)
+ (void)close(cfd->fdo);
if (cfd->cli->ident != NULL)
free(cfd->cli->ident);
FREE_OBJ(cfd);
+ return (retval);
}
void
@@ -575,8 +575,11 @@ VCLS_Poll(struct VCLS *cs, const struct cli *cli, int timeout)
else
k = cls_feed(cfd, buf, buf + i);
}
- if (k)
- cls_close_fd(cs, cfd);
+ if (k) {
+ i = cls_close_fd(cs, cfd);
+ if (i < 0)
+ k = i;
+ }
return (k);
}
@@ -589,7 +592,7 @@ VCLS_Destroy(struct VCLS **csp)
TAKE_OBJ_NOTNULL(cs, csp, VCLS_MAGIC);
VTAILQ_FOREACH_SAFE(cfd, &cs->fds, list, cfd2)
- cls_close_fd(cs, cfd);
+ (void)cls_close_fd(cs, cfd);
while (!VTAILQ_EMPTY(&cs->funcs)) {
clp = VTAILQ_FIRST(&cs->funcs);
More information about the varnish-commit
mailing list