[master] ab3f2b5fc Add a secret handshake where the worker process tells mgt that it got through all the initialization and is now ready to speak CLI.

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 28 10:06:09 UTC 2022


commit ab3f2b5fc5238590e1d54dec07fc03dd3354429b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 28 10:04:30 2022 +0000

    Add a secret handshake where the worker process tells mgt that it
    got through all the initialization and is now ready to speak CLI.

diff --git a/bin/varnishd/cache/cache_cli.c b/bin/varnishd/cache/cache_cli.c
index 06b2e02e6..b261d6bcb 100644
--- a/bin/varnishd/cache/cache_cli.c
+++ b/bin/varnishd/cache/cache_cli.c
@@ -98,6 +98,9 @@ CLI_Run(void)
 
 	add_check = 1;
 
+	/* Tell waiting MGT that we are ready to speak CLI */
+	AZ(VCLI_WriteResult(heritage.cli_out, CLIS_OK, "Ready"));
+
 	cli = VCLS_AddFd(cache_cls,
 	    heritage.cli_in, heritage.cli_out, NULL, NULL);
 	AN(cli);
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 5e7ed7cb1..17c80cf67 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -292,7 +292,7 @@ child_poker(const struct vev *e, int what)
 static void
 mgt_launch_child(struct cli *cli)
 {
-	pid_t pid;
+	pid_t pid, pidr;
 	unsigned u;
 	char *p;
 	struct vev *e;
@@ -414,6 +414,18 @@ mgt_launch_child(struct cli *cli)
 	MCH_Fd_Inherit(heritage.cli_out, NULL);
 	closefd(&heritage.cli_out);
 
+	/* Wait for cache/cache_cli.c::CLI_Run() to check in */
+	if (VCLI_ReadResult(child_cli_in, &u, NULL, mgt_param.cli_timeout)) {
+		assert(u == CLIS_COMMS);
+		pidr = waitpid(pid, &i, 0);
+		assert(pidr == pid);
+		perror("Child failed on launch");
+		exit(1);		// XXX Harsh ?
+	} else {
+		assert(u == CLIS_OK);
+		fprintf(stderr, "Child launched OK\n");
+	}
+
 	child_std_vlu = VLU_New(child_line, NULL, 0);
 	AN(child_std_vlu);
 


More information about the varnish-commit mailing list