From 4528611ed66d8bfa344782f6c7f1e7151cf48bf5 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Fri, 12 Apr 2019 16:09:21 +0200 Subject: [PATCH] MEDIUM: mworker: store the leaving state of a process Previously we were assuming than a process was in a leaving state when its number of reload was greater than 0. With mworker programs it's not the case anymore so we need to store a leaving state. --- include/types/global.h | 9 +++++++++ src/mworker.c | 14 ++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/types/global.h b/include/types/global.h index 306c87422..607ba2d96 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -180,6 +180,14 @@ struct global { #endif }; +/* options for mworker_proc */ + +#define PROC_O_TYPE_MASTER 0x00000001 +#define PROC_O_TYPE_WORKER 0x00000002 +#define PROC_O_TYPE_PROG 0x00000004 +/* 0x00000008 unused */ +#define PROC_O_LEAVING 0x00000010 /* this process should be leaving */ + /* * Structure used to describe the processes in master worker mode */ @@ -187,6 +195,7 @@ struct mworker_proc { int pid; char type; /* m(aster), w(orker) */ /* 3 bytes hole here */ + int options; char *id; char **command; char *path; diff --git a/src/mworker.c b/src/mworker.c index ac5d1a040..214dc79eb 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -66,7 +66,7 @@ int mworker_current_child(int pid) struct mworker_proc *child; list_for_each_entry(child, &proc_list, list) { - if ((child->type == 'w' || child->type == 'e') && (child->reloads == 0) && (child->pid == pid)) + if ((child->type == 'w' || child->type == 'e') && (!(child->options & PROC_O_LEAVING)) && (child->pid == pid)) return 1; } return 0; @@ -156,6 +156,8 @@ void mworker_env_to_proc_list() free(child); } + /* this is a process inherited from a reload that should be leaving */ + child->options |= PROC_O_LEAVING; } unsetenv("HAPROXY_PROCESSES"); @@ -246,7 +248,7 @@ restart_wait: ha_warning("Process %d exited with code %d (%s)\n", exitpid, status, (status >= 128) ? strsignal(status - 128) : "Exit"); } else { /* check if exited child is a current child */ - if (child->reloads == 0) { + if (!(child->options & PROC_O_LEAVING)) { if (child->type == 'w') ha_alert("Current worker #%d (%d) exited with code %d (%s)\n", child->relative_pid, exitpid, status, (status >= 128) ? strsignal(status - 128) : "Exit"); else if (child->type == 'e') @@ -415,7 +417,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) if (child->type != 'w') continue; - if (child->reloads > 0) { + if (child->options & PROC_O_LEAVING) { old++; continue; } @@ -434,7 +436,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) if (child->type != 'w') continue; - if (child->reloads > 0) { + if (child->options & PROC_O_LEAVING) { memprintf(&msg, "[was: %u]", child->relative_pid); chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", msg, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); } @@ -451,7 +453,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) if (child->type != 'e') continue; - if (child->reloads > 0) { + if (child->options & PROC_O_LEAVING) { old++; continue; } @@ -466,7 +468,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) if (child->type != 'e') continue; - if (child->reloads > 0) { + if (child->options & PROC_O_LEAVING) { chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, child->id, "-", child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); } }