Mailing List Archive

[6.0] f7854267e Expose the master and worker PIDs via the CLI
commit f7854267ef7ce2bf52517a801dc9896bb9336f88
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Mon Dec 30 16:38:05 2019 +0100

Expose the master and worker PIDs via the CLI

The change in u00011.vtc is the result of having two commands starting
with "pi", breaking auto-completion. Fortunately "pin\t" still does the
trick.

diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index fdcdfd830..bc5c00ec2 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -670,6 +670,31 @@ MCH_Running(void)
* CLI commands
*/

+static void v_matchproto_(cli_func_t)
+mch_pid(struct cli *cli, const char * const *av, void *priv)
+{
+
+ (void)av;
+ (void)priv;
+ VCLI_Out(cli, "Master: %10jd\n", (intmax_t)getpid());
+ if (!MCH_Running())
+ return;
+ VCLI_Out(cli, "Worker: %10jd\n", (intmax_t)child_pid);
+}
+
+static void v_matchproto_(cli_func_t)
+mch_pid_json(struct cli *cli, const char * const *av, void *priv)
+{
+
+ (void)priv;
+ VCLI_JSON_begin(cli, 2, av);
+ VCLI_Out(cli, ",\n {\"master\": %jd", (intmax_t)getpid());
+ if (MCH_Running())
+ VCLI_Out(cli, ", \"worker\": %jd", (intmax_t)child_pid);
+ VCLI_Out(cli, "}");
+ VCLI_JSON_end(cli);
+}
+
static void v_matchproto_(cli_func_t)
mch_cli_server_start(struct cli *cli, const char * const *av, void *priv)
{
@@ -729,6 +754,7 @@ static struct cli_proto cli_mch[] = {
{ CLICMD_PANIC_SHOW, "", mch_cli_panic_show,
mch_cli_panic_show_json },
{ CLICMD_PANIC_CLEAR, "", mch_cli_panic_clear },
+ { CLICMD_PID, "", mch_pid, mch_pid_json },
{ NULL }
};

diff --git a/bin/varnishtest/tests/b00071.vtc b/bin/varnishtest/tests/b00071.vtc
new file mode 100644
index 000000000..e69a92510
--- /dev/null
+++ b/bin/varnishtest/tests/b00071.vtc
@@ -0,0 +1,9 @@
+varnishtest "varnish-cli pid command"
+
+varnish v1 -cliexpect "^Master: +[0-9]+\n$" pid
+varnish v1 -cliok "pid -j"
+
+varnish v1 -vcl {backend be none;} -start
+
+varnish v1 -cliexpect "^Master: +[0-9]+\nWorker: +[0-9]+\n$" pid
+varnish v1 -cliok "pid -j"
diff --git a/bin/varnishtest/tests/u00011.vtc b/bin/varnishtest/tests/u00011.vtc
index b53a9ba7b..bb9701db4 100644
--- a/bin/varnishtest/tests/u00011.vtc
+++ b/bin/varnishtest/tests/u00011.vtc
@@ -18,7 +18,7 @@ process p1 -log {varnishadm -n ${v1_name}} -start

process p1 -expect-text 0 1 "Type 'quit' to close CLI session."

-process p1 -write "pi\t\r"
+process p1 -write "pin\t\r"

process p1 -expect-text 0 1 "PONG"

diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h
index 732522736..bf95a7901 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -348,6 +348,14 @@ CLI_CMD(STORAGE_LIST,
0, 0
)

+CLI_CMD(PID,
+ "pid",
+ "pid [-j]",
+ "Show the pid of the master process, and the worker if it's running.",
+ " ``-j`` specifies JSON output.",
+ 0, 0
+)
+
#undef CLI_CMD

/*lint -restore */
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit