-/* $OpenBSD: proc.c,v 1.42 2021/12/30 20:38:43 dv Exp $ */
+/* $OpenBSD: proc.c,v 1.43 2022/09/03 20:07:31 benno Exp $ */
/*
* Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
#include "relayd.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,
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;
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)
} 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;
privsep_process = PROC_PARENT;
proc_setup(ps, procs, nproc);
+ if (!debug && daemon(1, 0) == -1)
+ fatal("failed to daemonize");
+
/*
* Create the children sockets so we can use them
* to distribute the rest of the socketpair()s using
}
/* Engage! */
- proc_exec(ps, procs, nproc, debug, argc, argv);
+ proc_exec(ps, procs, nproc, argc, argv);
return;
}
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__);
-/* $OpenBSD: relayd.c,v 1.188 2022/08/31 16:17:18 dv Exp $ */
+/* $OpenBSD: relayd.c,v 1.189 2022/09/03 20:07:31 benno Exp $ */
/*
* Copyright (c) 2007 - 2016 Reyk Floeter <reyk@openbsd.org>
proc_init(ps, procs, nitems(procs), debug, argc0, argv, proc_id);
log_procinit("parent");
- if (!debug && daemon(1, 0) == -1)
- err(1, "failed to daemonize");
if (ps->ps_noaction == 0)
log_info("startup");