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.
diff --git a/include/types/global.h b/include/types/global.h
index 306c874..607ba2d 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -180,6 +180,14 @@
#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 @@
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 ac5d1a0..214dc79 100644
--- a/src/mworker.c
+++ b/src/mworker.c
@@ -66,7 +66,7 @@
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 @@
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 @@
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 @@
if (child->type != 'w')
continue;
- if (child->reloads > 0) {
+ if (child->options & PROC_O_LEAVING) {
old++;
continue;
}
@@ -434,7 +436,7 @@
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 @@
if (child->type != 'e')
continue;
- if (child->reloads > 0) {
+ if (child->options & PROC_O_LEAVING) {
old++;
continue;
}
@@ -466,7 +468,7 @@
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));
}
}