]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mworker: store the leaving state of a process
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 12 Apr 2019 14:09:21 +0000 (16:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Apr 2019 11:26:43 +0000 (13:26 +0200)
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
src/mworker.c

index 306c874226f2a9a59ebbc01c08a450945b825ad0..607ba2d96f11091c04253fb203066ebcadd77c45 100644 (file)
@@ -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;
index ac5d1a0400fb84e88d13e2d48a9ad49e9bb6ac07..214dc79ebd24185a3d9e83ea831dbe2e0c78e124 100644 (file)
@@ -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));
                        }
                }