-/* $OpenBSD: httpd.c,v 1.67 2017/05/28 10:37:26 benno Exp $ */
+/* $OpenBSD: httpd.c,v 1.68 2018/09/09 21:06:51 bluhm Exp $ */
/*
* Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
}
/* only the parent returns */
- proc_init(ps, procs, nitems(procs), argc0, argv, proc_id);
+ proc_init(ps, procs, nitems(procs), debug, argc0, argv, proc_id);
log_procinit("parent");
if (!debug && daemon(1, 0) == -1)
-/* $OpenBSD: httpd.h,v 1.139 2018/08/19 18:03:35 jasper Exp $ */
+/* $OpenBSD: httpd.h,v 1.140 2018/09/09 21:06:51 bluhm Exp $ */
/*
* Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
/* proc.c */
enum privsep_procid
proc_getid(struct privsep_proc *, unsigned int, const char *);
-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 *);
-/* $OpenBSD: proc.c,v 1.37 2017/05/28 10:37:26 benno Exp $ */
+/* $OpenBSD: proc.c,v 1.38 2018/09/09 21:06:51 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 "httpd.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.c,v 1.39 2017/05/28 10:39:15 benno Exp $ */
+/* $OpenBSD: proc.c,v 1.40 2018/09/09 21:06:51 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 "relayd.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: relayd.c,v 1.173 2018/09/01 18:09:14 bluhm Exp $ */
+/* $OpenBSD: relayd.c,v 1.174 2018/09/09 21:06:51 bluhm Exp $ */
/*
* Copyright (c) 2007 - 2016 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), debug, argc0, argv, proc_id);
log_procinit("parent");
if (!debug && daemon(1, 0) == -1)
-/* $OpenBSD: relayd.h,v 1.250 2018/08/06 17:31:31 benno Exp $ */
+/* $OpenBSD: relayd.h,v 1.251 2018/09/09 21:06:51 bluhm Exp $ */
/*
* Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org>
enum privsep_procid
proc_getid(struct privsep_proc *, unsigned int, const char *);
int proc_flush_imsg(struct privsep *, enum privsep_procid, int);
-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 *);