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;
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++;
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));
}
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;
}
/* 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;
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);
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);
}
/*
{
char *msg, *token = NULL, *s1;
- msg = getenv("HAPROXY_CHILDREN");
+ msg = getenv("HAPROXY_PROCESSES");
if (!msg)
return;
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);
free(child);
}
- unsetenv("HAPROXY_CHILDREN");
+ unsetenv("HAPROXY_PROCESSES");
}
/*
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) {
exit(EXIT_FAILURE);
}
+ tmproc->type = 'w'; /* worker */
tmproc->pid = -1;
tmproc->reloads = 0;
tmproc->timestamp = -1;