diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-09-10 10:36:02 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-09-10 10:36:02 +0000 |
commit | a6e0aea87a35e836839da9a92aef8797622d1f68 (patch) | |
tree | d401db7ce5070bd16b34fce5ab1f0fcb75968873 | |
parent | 09154e9c4904db508ba1d50b1709da7faa9bf2ea (diff) |
During the fork+exec implementation, daemon(3) was moved after
proc_init(). As a consequence vmd(8) child processes did not detach
from the terminal anymore. Dup /dev/null to the stdio file descriptors
in the children.
OK mlarkin@ reyk@
-rw-r--r-- | usr.sbin/vmd/proc.c | 21 | ||||
-rw-r--r-- | usr.sbin/vmd/proc.h | 4 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.c | 5 |
3 files changed, 21 insertions, 9 deletions
diff --git a/usr.sbin/vmd/proc.c b/usr.sbin/vmd/proc.c index b37036908cd..fde98994bc1 100644 --- a/usr.sbin/vmd/proc.c +++ b/usr.sbin/vmd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.17 2018/08/05 08:20:54 mestre Exp $ */ +/* $OpenBSD: proc.c,v 1.18 2018/09/10 10:36:01 bluhm Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org> @@ -29,13 +29,14 @@ #include <string.h> #include <errno.h> #include <signal.h> +#include <paths.h> #include <pwd.h> #include <event.h> #include <imsg.h> #include "proc.h" -void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, +void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int, int, char **); void proc_setup(struct privsep *, struct privsep_proc *, unsigned int); void proc_open(struct privsep *, int, int); @@ -80,7 +81,7 @@ proc_getid(struct privsep_proc *procs, unsigned int nproc, void proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, - int argc, char **argv) + int debug, int argc, char **argv) { unsigned int proc, nargc, i, proc_i; char **nargv; @@ -141,6 +142,16 @@ 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; @@ -191,7 +202,7 @@ proc_connect(struct privsep *ps) void proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, - int argc, char **argv, enum privsep_procid proc_id) + int debug, int argc, char **argv, enum privsep_procid proc_id) { struct privsep_proc *p = NULL; struct privsep_pipes *pa, *pb; @@ -231,7 +242,7 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, } /* Engage! */ - proc_exec(ps, procs, nproc, argc, argv); + proc_exec(ps, procs, nproc, debug, argc, argv); return; } diff --git a/usr.sbin/vmd/proc.h b/usr.sbin/vmd/proc.h index 01361076f54..5dfccb9cf09 100644 --- a/usr.sbin/vmd/proc.h +++ b/usr.sbin/vmd/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.15 2018/08/05 08:20:54 mestre Exp $ */ +/* $OpenBSD: proc.h,v 1.16 2018/09/10 10:36:01 bluhm Exp $ */ /* * Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org> @@ -156,7 +156,7 @@ struct privsep_fd { #define PROC_MAX_INSTANCES 32 /* proc.c */ -void proc_init(struct privsep *, struct privsep_proc *, unsigned int, +void proc_init(struct privsep *, struct privsep_proc *, unsigned int, int, int, char **, enum privsep_procid); void proc_kill(struct privsep *); void proc_connect(struct privsep *ps); diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index 2b07a8463b7..ac4d1635bd4 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.98 2018/07/15 14:36:54 reyk Exp $ */ +/* $OpenBSD: vmd.c,v 1.99 2018/09/10 10:36:01 bluhm Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -792,7 +792,8 @@ main(int argc, char **argv) ps->ps_title[proc_id] = title; /* only the parent returns */ - proc_init(ps, procs, nitems(procs), argc0, argv, proc_id); + proc_init(ps, procs, nitems(procs), env->vmd_debug, argc0, argv, + proc_id); log_procinit("parent"); if (!env->vmd_debug && daemon(0, 0) == -1) |