summaryrefslogtreecommitdiff
path: root/usr.sbin/httpd
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2018-09-09 21:06:52 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2018-09-09 21:06:52 +0000
commit5725108b9339c0c05b971624621b2ef4b0e3586d (patch)
treead8cc2b1651710f04df1f0313f1494ad23eb1719 /usr.sbin/httpd
parentbfac918fb2c452e0c87e05fe6d1bf923e12068fb (diff)
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;
}