summaryrefslogtreecommitdiffstats
path: root/usr.sbin/httpd
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2018-09-09 21:06:51 +0000
committerbluhm <bluhm@openbsd.org>2018-09-09 21:06:51 +0000
commit38b341808c90fc68f4b3301d6743519a6922fd5f (patch)
tree905b8aa6285fd61a2aaed0c436c23146c969b3eb /usr.sbin/httpd
parentEnable the empty as-set and prefix-set tests since that is now allowed again (diff)
downloadwireguard-openbsd-38b341808c90fc68f4b3301d6743519a6922fd5f.tar.xz
wireguard-openbsd-38b341808c90fc68f4b3301d6743519a6922fd5f.zip
During the fork+exec implementation, daemon(3) was moved after
proc_init(). As a consequence httpd(8) and relayd(8) child processes did not detach from the terminal anymore. Dup /dev/null to the stdio file descriptors in the children. OK benno@
Diffstat (limited to 'usr.sbin/httpd')
-rw-r--r--usr.sbin/httpd/httpd.c4
-rw-r--r--usr.sbin/httpd/httpd.h4
-rw-r--r--usr.sbin/httpd/proc.c21
3 files changed, 20 insertions, 9 deletions
diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c
index 6d1d1ff34fe..ae0fa879ef5 100644
--- a/usr.sbin/httpd/httpd.c
+++ b/usr.sbin/httpd/httpd.c
@@ -1,4 +1,4 @@
-/* $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>
@@ -215,7 +215,7 @@ main(int argc, char *argv[])
}
/* 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)
diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h
index 5cfbd996bad..4b1d9d72237 100644
--- a/usr.sbin/httpd/httpd.h
+++ b/usr.sbin/httpd/httpd.h
@@ -1,4 +1,4 @@
-/* $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>
@@ -780,7 +780,7 @@ __dead void fatalx(const char *, ...)
/* 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 *);
diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c
index cd387a17903..729ecff2489 100644
--- a/usr.sbin/httpd/proc.c
+++ b/usr.sbin/httpd/proc.c
@@ -1,4 +1,4 @@
-/* $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>
@@ -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 "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);
@@ -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;
}