From 2269e2921abc0abcac4278cb47ad39da5218de94 Mon Sep 17 00:00:00 2001 From: tobhe Date: Tue, 9 Apr 2024 15:48:01 +0000 Subject: [PATCH] Sync removal of setsid(), setpgid() and a few dup2() from relayd. They are redundant since we call daemon() earlier. ok bluhm@ --- sbin/iked/proc.c | 25 ++++--------------------- usr.sbin/httpd/proc.c | 25 ++++--------------------- usr.sbin/snmpd/proc.c | 25 ++++--------------------- usr.sbin/vmd/proc.c | 25 ++++--------------------- 4 files changed, 16 insertions(+), 84 deletions(-) diff --git a/sbin/iked/proc.c b/sbin/iked/proc.c index 18679918268..337063f76e8 100644 --- a/sbin/iked/proc.c +++ b/sbin/iked/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.43 2024/04/08 12:50:05 tobhe Exp $ */ +/* $OpenBSD: proc.c,v 1.44 2024/04/09 15:48:01 tobhe Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -39,7 +39,7 @@ enum privsep_procid privsep_process; void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int, - int, char **); + char **); void proc_setup(struct privsep *, struct privsep_proc *, unsigned int); void proc_open(struct privsep *, int, int); void proc_accept(struct privsep *, int, enum privsep_procid, @@ -70,7 +70,7 @@ proc_getid(struct privsep_proc *procs, unsigned int nproc, void proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, - int debug, int argc, char **argv) + int argc, char **argv) { unsigned int proc, nargc, i, proc_i; char **nargv; @@ -119,10 +119,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, fatal("%s: fork", __func__); break; case 0: - /* First create a new session */ - if (setsid() == -1) - fatal("setsid"); - /* Prepare parent socket. */ if (fd != PROC_PARENT_SOCK_FILENO) { if (dup2(fd, PROC_PARENT_SOCK_FILENO) @@ -131,16 +127,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } else if (fcntl(fd, F_SETFD, 0) == -1) fatal("fcntl"); - /* Daemons detach from terminal. */ - if (!debug && (fd = - open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close(fd); - } - execvp(argv[0], nargv); fatal("%s: execvp", __func__); break; @@ -260,7 +246,7 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } /* Engage! */ - proc_exec(ps, procs, nproc, debug, argc, argv); + proc_exec(ps, procs, nproc, argc, argv); return; } @@ -546,9 +532,6 @@ proc_run(struct privsep *ps, struct privsep_proc *p, log_procinit(p->p_title); - /* Set the process group of the current process */ - setpgid(0, 0); - if (p->p_id == PROC_CONTROL && ps->ps_instance == 0) { if (control_init(ps, &ps->ps_csock) == -1) fatalx("%s: control_init", __func__); diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c index 58ea14cc09b..6b0461eaf1e 100644 --- a/usr.sbin/httpd/proc.c +++ b/usr.sbin/httpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.44 2024/04/08 12:45:18 tobhe Exp $ */ +/* $OpenBSD: proc.c,v 1.45 2024/04/09 15:48:01 tobhe Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -37,7 +37,7 @@ #include "httpd.h" void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int, - int, char **); + char **); void proc_setup(struct privsep *, struct privsep_proc *, unsigned int); void proc_open(struct privsep *, int, int); void proc_accept(struct privsep *, int, enum privsep_procid, @@ -68,7 +68,7 @@ proc_getid(struct privsep_proc *procs, unsigned int nproc, void proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, - int debug, int argc, char **argv) + int argc, char **argv) { unsigned int proc, nargc, i, proc_i; char **nargv; @@ -117,10 +117,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, fatal("%s: fork", __func__); break; case 0: - /* First create a new session */ - if (setsid() == -1) - fatal("setsid"); - /* Prepare parent socket. */ if (fd != PROC_PARENT_SOCK_FILENO) { if (dup2(fd, PROC_PARENT_SOCK_FILENO) @@ -129,16 +125,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } else if (fcntl(fd, F_SETFD, 0) == -1) fatal("fcntl"); - /* Daemons detach from terminal. */ - if (!debug && (fd = - open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close(fd); - } - execvp(argv[0], nargv); fatal("%s: execvp", __func__); break; @@ -232,7 +218,7 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } /* Engage! */ - proc_exec(ps, procs, nproc, debug, argc, argv); + proc_exec(ps, procs, nproc, argc, argv); return; } @@ -526,9 +512,6 @@ proc_run(struct privsep *ps, struct privsep_proc *p, log_procinit(p->p_title); - /* Set the process group of the current process */ - setpgid(0, 0); - if (p->p_id == PROC_CONTROL && ps->ps_instance == 0) { if (control_init(ps, &ps->ps_csock) == -1) fatalx("%s: control_init", __func__); diff --git a/usr.sbin/snmpd/proc.c b/usr.sbin/snmpd/proc.c index 61355cdb59d..8d5cb109c50 100644 --- a/usr.sbin/snmpd/proc.c +++ b/usr.sbin/snmpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.31 2024/04/08 13:18:54 tobhe Exp $ */ +/* $OpenBSD: proc.c,v 1.32 2024/04/09 15:48:01 tobhe Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -37,7 +37,7 @@ #include "snmpd.h" void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int, - int, char **); + char **); void proc_setup(struct privsep *, struct privsep_proc *, unsigned int); void proc_open(struct privsep *, int, int); void proc_accept(struct privsep *, int, enum privsep_procid, @@ -68,7 +68,7 @@ proc_getid(struct privsep_proc *procs, unsigned int nproc, void proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, - int debug, int argc, char **argv) + int argc, char **argv) { unsigned int proc, nargc, i, proc_i; char **nargv; @@ -117,10 +117,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, fatal("%s: fork", __func__); break; case 0: - /* First create a new session */ - if (setsid() == -1) - fatal("setsid"); - /* Prepare parent socket. */ if (fd != PROC_PARENT_SOCK_FILENO) { if (dup2(fd, PROC_PARENT_SOCK_FILENO) @@ -129,16 +125,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } else if (fcntl(fd, F_SETFD, 0) == -1) fatal("fcntl"); - /* Daemons detach from terminal. */ - if (!debug && (fd = - open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close(fd); - } - execvp(argv[0], nargv); fatal("%s: execvp", __func__); break; @@ -232,7 +218,7 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } /* Engage! */ - proc_exec(ps, procs, nproc, debug, argc, argv); + proc_exec(ps, procs, nproc, argc, argv); return; } @@ -518,9 +504,6 @@ proc_run(struct privsep *ps, struct privsep_proc *p, log_procinit(p->p_title); - /* Set the process group of the current process */ - setpgid(0, 0); - /* Use non-standard user */ if (p->p_pw != NULL) pw = p->p_pw; diff --git a/usr.sbin/vmd/proc.c b/usr.sbin/vmd/proc.c index 6b50501873a..950c17d6e0e 100644 --- a/usr.sbin/vmd/proc.c +++ b/usr.sbin/vmd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.24 2024/04/08 12:48:26 tobhe Exp $ */ +/* $OpenBSD: proc.c,v 1.25 2024/04/09 15:48:01 tobhe Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -37,7 +37,7 @@ #include "proc.h" void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int, - int, char **); + char **); void proc_setup(struct privsep *, struct privsep_proc *, unsigned int); void proc_open(struct privsep *, int, int); void proc_accept(struct privsep *, int, enum privsep_procid, @@ -68,7 +68,7 @@ proc_getid(struct privsep_proc *procs, unsigned int nproc, void proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, - int debug, int argc, char **argv) + int argc, char **argv) { unsigned int proc, nargc, i, proc_i; char **nargv; @@ -117,10 +117,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, fatal("%s: fork", __func__); break; case 0: - /* First create a new session */ - if (setsid() == -1) - fatal("setsid"); - /* Prepare parent socket. */ if (fd != PROC_PARENT_SOCK_FILENO) { if (dup2(fd, PROC_PARENT_SOCK_FILENO) @@ -129,16 +125,6 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } else if (fcntl(fd, F_SETFD, 0) == -1) fatal("fcntl"); - /* Daemons detach from terminal. */ - if (!debug && (fd = - open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close(fd); - } - execvp(argv[0], nargv); fatal("%s: execvp", __func__); break; @@ -232,7 +218,7 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } /* Engage! */ - proc_exec(ps, procs, nproc, debug, argc, argv); + proc_exec(ps, procs, nproc, argc, argv); return; } @@ -519,9 +505,6 @@ proc_run(struct privsep *ps, struct privsep_proc *p, log_procinit("%s", p->p_title); - /* Set the process group of the current process */ - setpgid(0, 0); - if (p->p_id == PROC_CONTROL && ps->ps_instance == 0) { if (control_init(ps, &ps->ps_csock) == -1) fatalx("%s: control_init", __func__); -- 2.20.1