MINOR: cli: show master information in 'show proc'
Displays the master information in show proc.
diff --git a/include/types/global.h b/include/types/global.h
index be4d7c5..effc51c 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -209,6 +209,8 @@
*/
struct mworker_proc {
int pid;
+ char type; /* m(aster), w(orker) */
+ /* 3 bytes hole here */
int ipc_fd[2]; /* 0 is master side, 1 is worker side */
int relative_pid;
int reloads;
@@ -242,6 +244,7 @@
extern unsigned int warned; /* bitfield of a few warnings to emit just once */
extern volatile unsigned long sleeping_thread_mask;
extern struct list proc_list; /* list of process in mworker mode */
+extern struct mworker_proc *proc_self; /* process structure of current process */
/* bit values to go with "warned" above */
#define WARN_BLOCK_DEPRECATED 0x00000001
diff --git a/src/cli.c b/src/cli.c
index 24cb2a4..4356586 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -1399,6 +1399,7 @@
struct stream_interface *si = appctx->owner;
struct mworker_proc *child;
int old = 0;
+ int up = now.tv_sec - proc_self->timestamp;
if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
return 1;
@@ -1406,13 +1407,16 @@
chunk_reset(&trash);
chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
- chunk_appendf(&trash, "%-15u %-15s %-15u %-15s %s\n", getpid(), "master", 0, "-", "-");
+ chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", getpid(), "master", 0, proc_self->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
/* displays current processes */
chunk_appendf(&trash, "# workers\n");
list_for_each_entry(child, &proc_list, list) {
- int up = now.tv_sec - child->timestamp;
+ up = now.tv_sec - child->timestamp;
+
+ if (child->type != 'w')
+ continue;
if (child->reloads > 0) {
old++;
@@ -1426,7 +1430,11 @@
if (old) {
chunk_appendf(&trash, "# old workers\n");
list_for_each_entry(child, &proc_list, list) {
- int up = now.tv_sec - child->timestamp;
+ up = now.tv_sec - child->timestamp;
+
+ if (child->type != 'w')
+ continue;
+
if (child->reloads > 0)
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
}
@@ -1707,6 +1715,8 @@
if (*errtol != '\0')
return -1;
list_for_each_entry(child, &proc_list, list) {
+ if (child->type != 'w')
+ continue;
if (child->pid == proc_pid){
return child->pid;
}
@@ -1725,6 +1735,8 @@
/* chose the right process, the current one is the one with the
least number of reloads */
list_for_each_entry(child, &proc_list, list) {
+ if (child->type != 'w')
+ continue;
if (child->relative_pid == proc_pid){
if (child->reloads == 0)
return child->pid;
diff --git a/src/haproxy.c b/src/haproxy.c
index 276652b..225dc69 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -219,7 +219,7 @@
int master = 0; /* 1 if in master, 0 if in child */
-struct mworker_proc *proc_self;
+struct mworker_proc *proc_self = NULL;
/* list of the temporarily limited listeners because of lack of resource */
struct list global_listener_queue = LIST_HEAD_INIT(global_listener_queue);
@@ -540,13 +540,10 @@
struct mworker_proc *child;
list_for_each_entry(child, &proc_list, list) {
- if (msg)
- memprintf(&msg, "%s|type=worker;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d", msg, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp);
- else
- memprintf(&msg, "type=worker;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d", child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp);
+ memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d", msg ? msg : "", child->type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp);
}
if (msg)
- setenv("HAPROXY_CHILDREN", msg, 1);
+ setenv("HAPROXY_PROCESSES", msg, 1);
}
/*
@@ -556,7 +553,7 @@
{
char *msg, *token = NULL, *s1;
- msg = getenv("HAPROXY_CHILDREN");
+ msg = getenv("HAPROXY_PROCESSES");
if (!msg)
return;
@@ -573,7 +570,11 @@
token = NULL;
- if (strncmp(subtoken, "fd=", 3) == 0) {
+ if (strncmp(subtoken, "type=", 5) == 0) {
+ child->type = *(subtoken+5);
+ if (child->type == 'm') /* we are in the master, assign it */
+ proc_self = child;
+ } else if (strncmp(subtoken, "fd=", 3) == 0) {
child->ipc_fd[0] = atoi(subtoken+3);
} else if (strncmp(subtoken, "pid=", 4) == 0) {
child->pid = atoi(subtoken+4);
@@ -592,7 +593,7 @@
free(child);
}
- unsetenv("HAPROXY_CHILDREN");
+ unsetenv("HAPROXY_PROCESSES");
}
/*
@@ -1735,9 +1736,29 @@
if (global.mode & MODE_MWORKER) {
int proc;
struct wordlist *it, *c;
+ struct mworker_proc *tmproc;
+
+ if (getenv("HAPROXY_MWORKER_REEXEC") == NULL) {
+
+ tmproc = malloc(sizeof(*tmproc));
+ if (!tmproc) {
+ ha_alert("Cannot allocate process structures.\n");
+ exit(EXIT_FAILURE);
+ }
+ tmproc->type = 'm'; /* master */
+ tmproc->reloads = 0;
+ tmproc->relative_pid = 0;
+ tmproc->pid = pid;
+ tmproc->timestamp = start_date.tv_sec;
+ tmproc->ipc_fd[0] = -1;
+ tmproc->ipc_fd[1] = -1;
+
+ proc_self = tmproc;
+
+ LIST_ADDQ(&proc_list, &tmproc->list);
+ }
for (proc = 0; proc < global.nbproc; proc++) {
- struct mworker_proc *tmproc;
tmproc = malloc(sizeof(*tmproc));
if (!tmproc) {
@@ -1745,6 +1766,7 @@
exit(EXIT_FAILURE);
}
+ tmproc->type = 'w'; /* worker */
tmproc->pid = -1;
tmproc->reloads = 0;
tmproc->timestamp = -1;