-/* $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>
#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);
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;
} 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;
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;
}
/* Engage! */
- proc_exec(ps, procs, nproc, argc, argv);
+ proc_exec(ps, procs, nproc, debug, argc, argv);
return;
}
-/* $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>
#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);
-/* $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>
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)