From b607ef5af6e8cb4789f3820224e0c20a3727d708 Mon Sep 17 00:00:00 2001 From: rzalamena Date: Sat, 27 Aug 2016 11:13:16 +0000 Subject: [PATCH] Kill p_instance from proc.c and remove static proc_id unused variables. To keep the debug functionality intact and correct we'll use the pid field in the imsg header to pass the instance number. Remember to always pass 'ps_instance + 1' otherwise libutil will fill imsg header pid field with the imsgbuf pid (which is the current process pid). ok reyk@ --- usr.sbin/httpd/control.c | 10 +++++----- usr.sbin/httpd/httpd.h | 5 ++--- usr.sbin/httpd/logger.c | 6 +----- usr.sbin/httpd/proc.c | 13 ++++++------- usr.sbin/httpd/server.c | 10 +--------- 5 files changed, 15 insertions(+), 29 deletions(-) diff --git a/usr.sbin/httpd/control.c b/usr.sbin/httpd/control.c index c29cd5b9725..e811922cda8 100644 --- a/usr.sbin/httpd/control.c +++ b/usr.sbin/httpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.9 2015/12/05 13:15:27 claudio Exp $ */ +/* $OpenBSD: control.c,v 1.10 2016/08/27 11:13:16 rzalamena Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -273,7 +273,7 @@ control_dispatch_imsg(int fd, short event, void *arg) "client requested notify more than once", __func__); imsg_compose_event(&c->iev, IMSG_CTL_FAIL, - 0, 0, -1, NULL, 0); + 0, env->sc_ps->ps_instance + 1, -1, NULL, 0); break; } c->flags |= CTL_CONN_NOTIFY; @@ -287,7 +287,7 @@ control_dispatch_imsg(int fd, short event, void *arg) proc_forward_imsg(env->sc_ps, &imsg, PROC_SERVER, -1); memcpy(imsg.data, &verbose, sizeof(verbose)); - control_imsg_forward(&imsg); + control_imsg_forward(env->sc_ps, &imsg); log_verbose(verbose); break; default: @@ -302,13 +302,13 @@ control_dispatch_imsg(int fd, short event, void *arg) } void -control_imsg_forward(struct imsg *imsg) +control_imsg_forward(struct privsep *ps, struct imsg *imsg) { struct ctl_conn *c; TAILQ_FOREACH(c, &ctl_conns, entry) if (c->flags & CTL_CONN_NOTIFY) imsg_compose_event(&c->iev, imsg->hdr.type, - 0, imsg->hdr.pid, -1, imsg->data, + 0, ps->ps_instance + 1, -1, imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE); } diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h index 7ba4700382f..93b0d347b84 100644 --- a/usr.sbin/httpd/httpd.h +++ b/usr.sbin/httpd/httpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.h,v 1.110 2016/08/26 12:24:21 rzalamena Exp $ */ +/* $OpenBSD: httpd.h,v 1.111 2016/08/27 11:13:16 rzalamena Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter @@ -266,7 +266,6 @@ struct privsep_proc { pid_t (*p_init)(struct privsep *, struct privsep_proc *); void (*p_shutdown)(void); - unsigned int p_instance; const char *p_chroot; struct privsep *p_ps; struct httpd *p_env; @@ -516,7 +515,7 @@ int control_init(struct privsep *, struct control_sock *); int control_listen(struct control_sock *); void control_cleanup(struct control_sock *); void control_dispatch_imsg(int, short, void *); -void control_imsg_forward(struct imsg *); +void control_imsg_forward(struct privsep *, struct imsg *); struct ctl_conn * control_connbyfd(int); diff --git a/usr.sbin/httpd/logger.c b/usr.sbin/httpd/logger.c index ba2f8b81b2d..463d09c589f 100644 --- a/usr.sbin/httpd/logger.c +++ b/usr.sbin/httpd/logger.c @@ -1,4 +1,4 @@ -/* $OpenBSD: logger.c,v 1.17 2016/08/26 10:46:39 rzalamena Exp $ */ +/* $OpenBSD: logger.c,v 1.18 2016/08/27 11:13:16 rzalamena Exp $ */ /* * Copyright (c) 2014 Reyk Floeter @@ -43,7 +43,6 @@ void logger_init(struct privsep *, struct privsep_proc *p, void *); int logger_start(void); int logger_log(struct imsg *); -int proc_id; static uint32_t last_log_id = 0; static struct privsep_proc procs[] = { @@ -73,9 +72,6 @@ logger_init(struct privsep *ps, struct privsep_proc *p, void *arg) if (config_init(ps->ps_env) == -1) fatal("failed to initialize configuration"); - /* Set to current prefork id */ - proc_id = p->p_instance; - /* We use a custom shutdown callback */ p->p_shutdown = logger_shutdown; diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c index 94f23e2f094..6f6b8db3560 100644 --- a/usr.sbin/httpd/proc.c +++ b/usr.sbin/httpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.16 2016/08/26 12:24:21 rzalamena Exp $ */ +/* $OpenBSD: proc.c,v 1.17 2016/08/27 11:13:16 rzalamena Exp $ */ /* * Copyright (c) 2010 - 2014 Reyk Floeter @@ -247,7 +247,6 @@ proc_listen(struct privsep *ps, struct privsep_proc *procs, size_t nproc) ps->ps_ievs[dst][n].events = EV_READ; ps->ps_ievs[dst][n].proc = &procs[i]; ps->ps_ievs[dst][n].data = &ps->ps_ievs[dst][n]; - procs[i].p_instance = n; event_set(&(ps->ps_ievs[dst][n].ev), ps->ps_ievs[dst][n].ibuf.fd, @@ -391,7 +390,7 @@ proc_run(struct privsep *ps, struct privsep_proc *p, /* Fork child handlers */ for (n = 1; n < ps->ps_instances[p->p_id]; n++) { if (fork() == 0) { - ps->ps_instance = p->p_instance = n; + ps->ps_instance = n; break; } } @@ -478,7 +477,7 @@ proc_dispatch(int fd, short event, void *arg) #if DEBUG > 1 log_debug("%s: %s %d got imsg %d peerid %d from %s %d", __func__, title, ps->ps_instance + 1, - imsg.hdr.type, imsg.hdr.peerid, p->p_title, p->p_instance); + imsg.hdr.type, imsg.hdr.peerid, p->p_title, imsg.hdr.pid); #endif /* @@ -504,7 +503,7 @@ proc_dispatch(int fd, short event, void *arg) "from %s %d", __func__, title, ps->ps_instance + 1, imsg.hdr.type, imsg.hdr.peerid, - p->p_title, p->p_instance); + p->p_title, imsg.hdr.pid); fatalx(__func__); } imsg_free(&imsg); @@ -587,7 +586,7 @@ proc_compose_imsg(struct privsep *ps, enum privsep_procid id, int n, proc_range(ps, id, &n, &m); for (; n < m; n++) { if (imsg_compose_event(&ps->ps_ievs[id][n], - type, peerid, 0, fd, data, datalen) == -1) + type, peerid, ps->ps_instance + 1, fd, data, datalen) == -1) return (-1); } @@ -610,7 +609,7 @@ proc_composev_imsg(struct privsep *ps, enum privsep_procid id, int n, proc_range(ps, id, &n, &m); for (; n < m; n++) if (imsg_composev_event(&ps->ps_ievs[id][n], - type, peerid, 0, fd, iov, iovcnt) == -1) + type, peerid, ps->ps_instance + 1, fd, iov, iovcnt) == -1) return (-1); return (0); diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c index b3099d936c5..e07d33c2986 100644 --- a/usr.sbin/httpd/server.c +++ b/usr.sbin/httpd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.93 2016/08/26 10:46:39 rzalamena Exp $ */ +/* $OpenBSD: server.c,v 1.94 2016/08/27 11:13:16 rzalamena Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter @@ -75,8 +75,6 @@ volatile int server_clients; volatile int server_inflight = 0; uint32_t server_cltid; -int proc_id; - static struct privsep_proc procs[] = { { "parent", PROC_PARENT, server_dispatch_parent }, { "logger", PROC_LOGGER, server_dispatch_logger } @@ -274,9 +272,6 @@ server_init(struct privsep *ps, struct privsep_proc *p, void *arg) if (config_init(ps->ps_env) == -1) fatal("failed to initialize configuration"); - /* Set to current prefork id */ - proc_id = p->p_instance; - /* We use a custom shutdown callback */ p->p_shutdown = server_shutdown; @@ -972,9 +967,6 @@ server_accept(int fd, short event, void *arg) server_clients++; SPLAY_INSERT(client_tree, &srv->srv_clients, clt); - /* Increment the per-relay client counter */ - //srv->srv_stats[proc_id].last++; - /* Pre-allocate output buffer */ clt->clt_output = evbuffer_new(); if (clt->clt_output == NULL) { -- 2.20.1