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.
This commit is contained in:
William Lallemand 2019-04-12 16:09:21 +02:00 committed by Willy Tarreau
parent 9df86f997e
commit 4528611ed6
2 changed files with 17 additions and 6 deletions

View File

@ -180,6 +180,14 @@ struct global {
#endif #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 * Structure used to describe the processes in master worker mode
*/ */
@ -187,6 +195,7 @@ struct mworker_proc {
int pid; int pid;
char type; /* m(aster), w(orker) */ char type; /* m(aster), w(orker) */
/* 3 bytes hole here */ /* 3 bytes hole here */
int options;
char *id; char *id;
char **command; char **command;
char *path; char *path;

View File

@ -66,7 +66,7 @@ int mworker_current_child(int pid)
struct mworker_proc *child; struct mworker_proc *child;
list_for_each_entry(child, &proc_list, list) { 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 1;
} }
return 0; return 0;
@ -156,6 +156,8 @@ void mworker_env_to_proc_list()
free(child); free(child);
} }
/* this is a process inherited from a reload that should be leaving */
child->options |= PROC_O_LEAVING;
} }
unsetenv("HAPROXY_PROCESSES"); unsetenv("HAPROXY_PROCESSES");
@ -246,7 +248,7 @@ void mworker_catch_sigchld(struct sig_handler *sh)
ha_warning("Process %d exited with code %d (%s)\n", exitpid, status, (status >= 128) ? strsignal(status - 128) : "Exit"); ha_warning("Process %d exited with code %d (%s)\n", exitpid, status, (status >= 128) ? strsignal(status - 128) : "Exit");
} else { } else {
/* check if exited child is a current child */ /* check if exited child is a current child */
if (child->reloads == 0) { if (!(child->options & PROC_O_LEAVING)) {
if (child->type == 'w') 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"); 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') else if (child->type == 'e')
@ -415,7 +417,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
if (child->type != 'w') if (child->type != 'w')
continue; continue;
if (child->reloads > 0) { if (child->options & PROC_O_LEAVING) {
old++; old++;
continue; continue;
} }
@ -434,7 +436,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
if (child->type != 'w') if (child->type != 'w')
continue; continue;
if (child->reloads > 0) { if (child->options & PROC_O_LEAVING) {
memprintf(&msg, "[was: %u]", child->relative_pid); 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)); 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') if (child->type != 'e')
continue; continue;
if (child->reloads > 0) { if (child->options & PROC_O_LEAVING) {
old++; old++;
continue; continue;
} }
@ -466,7 +468,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
if (child->type != 'e') if (child->type != 'e')
continue; 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)); 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));
} }
} }