From 1dc69630867aaeba81f463e80ef64f15021df224 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Wed, 12 Jun 2019 19:11:33 +0200 Subject: [PATCH] MINOR: mworker: add the HAProxy version in "show proc" Displays the HAProxy version so you can compare the version of old processes and new ones. --- doc/management.txt | 10 +++++----- include/types/global.h | 1 + src/haproxy.c | 1 + src/mworker.c | 21 ++++++++++++++------- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/doc/management.txt b/doc/management.txt index 7cc1d75f9e..616a040b7d 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -2612,13 +2612,13 @@ processes: Example: $ echo 'show proc' | socat /var/run/haproxy-master.sock - - # - 1162 master 0 5 0d 00h02m07s + # + 1162 master 0 5 0d00h02m07s 2.0-dev7-0124c9-7 # workers - 1271 worker 1 0 0d 00h00m00s - 1272 worker 2 0 0d 00h00m00s + 1271 worker 1 0 0d00h00m00s 2.0-dev7-0124c9-7 + 1272 worker 2 0 0d00h00m00s 2.0-dev7-0124c9-7 # old workers - 1233 worker [was: 1] 3 0d 00h00m43s + 1233 worker [was: 1] 3 0d00h00m43s 2.0-dev3-6019f6-289 In this example, the master has been reloaded 5 times but one of the old diff --git a/include/types/global.h b/include/types/global.h index 5fca648af2..f9ab4c29d3 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -208,6 +208,7 @@ struct mworker_proc { char *id; char **command; char *path; + char *version; int ipc_fd[2]; /* 0 is master side, 1 is worker side */ int relative_pid; int reloads; diff --git a/src/haproxy.c b/src/haproxy.c index c9370a3231..0c1d5a2636 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -3039,6 +3039,7 @@ int main(int argc, char **argv) child->reloads == 0 && child->options & PROC_O_TYPE_WORKER) { child->timestamp = now.tv_sec; child->pid = ret; + child->version = strdup(haproxy_version); break; } } diff --git a/src/mworker.c b/src/mworker.c index cd88723536..6a4f1f5755 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -121,7 +122,7 @@ void mworker_proc_list_to_env() type = 'w'; if (child->pid > -1) - memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d;id=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp, child->id ? child->id : ""); + memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp, child->id ? child->id : "", child->version); } if (msg) setenv("HAPROXY_PROCESSES", msg, 1); @@ -177,6 +178,8 @@ void mworker_env_to_proc_list() child->timestamp = atoi(subtoken+10); } else if (strncmp(subtoken, "id=", 3) == 0) { child->id = strdup(subtoken+3); + } else if (strncmp(subtoken, "version=", 8) == 0) { + child->version = strdup(subtoken+8); } } if (child->pid) { @@ -444,9 +447,9 @@ static int cli_io_handler_show_proc(struct appctx *appctx) chunk_reset(&trash); - chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s\n", "", "", "", "", ""); + chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s %-15s\n", "", "", "", "", "", ""); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); - chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", getpid(), "master", 0, proc_self->reloads, uptime); + chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", getpid(), "master", 0, proc_self->reloads, uptime, haproxy_version); free(uptime); uptime = NULL; @@ -464,7 +467,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) continue; } memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); - chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime); + chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime, child->version); free(uptime); uptime = NULL; } @@ -484,7 +487,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) if (child->options & PROC_O_LEAVING) { memprintf(&msg, "[was: %u]", child->relative_pid); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); - chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, "worker", msg, child->reloads, uptime); + chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, "worker", msg, child->reloads, uptime, child->version); free(uptime); uptime = NULL; } @@ -506,7 +509,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) continue; } memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); - chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime); + chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-"); free(uptime); uptime = NULL; } @@ -521,7 +524,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) if (child->options & PROC_O_LEAVING) { memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); - chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime); + chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-"); free(uptime); uptime = NULL; } @@ -599,6 +602,10 @@ void mworker_free_child(struct mworker_proc *child) free(child->id); child->id = NULL; } + if (child->version) { + free(child->version); + child->version = NULL; + } free(child); }