From: rzalamena Date: Fri, 26 Aug 2016 12:24:21 +0000 (+0000) Subject: Kill the ps_ninstances from proc.c. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=40f5ae168f8c0c09a6d3cadfa6b5ce142aabdf77;p=openbsd Kill the ps_ninstances from proc.c. We got the same information in ps_instances[proc] (more accurate) and we avoid allocating unnecessary memory for pipe storage. ok reyk@ --- diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c index 59ab347d62b..f5682a863d8 100644 --- a/usr.sbin/httpd/httpd.c +++ b/usr.sbin/httpd/httpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.c,v 1.57 2016/08/16 18:41:57 tedu Exp $ */ +/* $OpenBSD: httpd.c,v 1.58 2016/08/26 12:24:21 rzalamena Exp $ */ /* * Copyright (c) 2014 Reyk Floeter @@ -232,7 +232,6 @@ main(int argc, char *argv[]) log_info("startup"); ps->ps_instances[PROC_SERVER] = env->sc_prefork_server; - ps->ps_ninstances = env->sc_prefork_server; if (env->sc_chroot == NULL) env->sc_chroot = ps->ps_pw->pw_dir; diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h index f6e25fc4987..7ba4700382f 100644 --- a/usr.sbin/httpd/httpd.h +++ b/usr.sbin/httpd/httpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.h,v 1.109 2016/08/26 10:46:39 rzalamena Exp $ */ +/* $OpenBSD: httpd.h,v 1.110 2016/08/26 12:24:21 rzalamena Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter @@ -240,7 +240,6 @@ struct privsep { uint8_t ps_what[PROC_MAX]; unsigned int ps_instances[PROC_MAX]; - unsigned int ps_ninstances; unsigned int ps_instance; struct control_sock ps_csock; diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c index 7a6124a302a..94f23e2f094 100644 --- a/usr.sbin/httpd/proc.c +++ b/usr.sbin/httpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.15 2015/12/07 16:05:56 reyk Exp $ */ +/* $OpenBSD: proc.c,v 1.16 2016/08/26 12:24:21 rzalamena Exp $ */ /* * Copyright (c) 2010 - 2014 Reyk Floeter @@ -61,6 +61,12 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc) unsigned int i, j, src, dst; struct privsep_pipes *pp; + for (src = 0; src < PROC_MAX; src++) { + /* Default to 1 process instance */ + if (ps->ps_instances[src] < 1) + ps->ps_instances[src] = 1; + } + /* * Allocate pipes for all process instances (incl. parent) * @@ -76,22 +82,22 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc) */ for (src = 0; src < PROC_MAX; src++) { /* Allocate destination array for each process */ - if ((ps->ps_pipes[src] = calloc(ps->ps_ninstances, + if ((ps->ps_pipes[src] = calloc(ps->ps_instances[src], sizeof(struct privsep_pipes))) == NULL) fatal("proc_init: calloc"); - for (i = 0; i < ps->ps_ninstances; i++) { + for (i = 0; i < ps->ps_instances[src]; i++) { pp = &ps->ps_pipes[src][i]; for (dst = 0; dst < PROC_MAX; dst++) { /* Allocate maximum fd integers */ if ((pp->pp_pipes[dst] = - calloc(ps->ps_ninstances, + calloc(ps->ps_instances[dst], sizeof(int))) == NULL) fatal("proc_init: calloc"); /* Mark fd as unused */ - for (j = 0; j < ps->ps_ninstances; j++) + for (j = 0; j < ps->ps_instances[dst]; j++) pp->pp_pipes[dst][j] = -1; } } @@ -106,12 +112,8 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc) ps->ps_pid[PROC_PARENT] = getpid(); ps->ps_pp = &ps->ps_pipes[privsep_process][0]; - for (i = 0; i < nproc; i++) { - /* Default to 1 process instance */ - if (ps->ps_instances[procs[i].p_id] < 1) - ps->ps_instances[procs[i].p_id] = 1; + for (i = 0; i < nproc; i++) ps->ps_title[procs[i].p_id] = procs[i].p_title; - } proc_open(ps, NULL, procs, nproc);