summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2016-05-10 21:55:00 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2016-05-10 21:55:00 +0000
commitb707df2d11768ca0448716293d3a3a3f0cb13c53 (patch)
treeb211507b0c34f2b60177744c3fb5d6f60ac23096 /sbin
parent044dede1e04ce19911ed3ae812610b9c5aa06a32 (diff)
Do not close the stdio file desciptors in init(8), but dup2(2) them
from /dev/null. The code is taken from daemon(3). Also move this operation to the beginning. OK millert@ deraadt@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/init/init.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/sbin/init/init.c b/sbin/init/init.c
index 5eb65bcbe47..16ac88febef 100644
--- a/sbin/init/init.c
+++ b/sbin/init/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.58 2016/02/01 20:14:51 jca Exp $ */
+/* $OpenBSD: init.c,v 1.59 2016/05/10 21:54:59 bluhm Exp $ */
/* $NetBSD: init.c,v 1.22 1996/05/15 23:29:33 jtc Exp $ */
/*-
@@ -192,7 +192,7 @@ DB *session_db;
int
main(int argc, char *argv[])
{
- int c;
+ int c, fd;
struct sigaction sa;
sigset_t mask;
@@ -209,6 +209,17 @@ main(int argc, char *argv[])
}
/*
+ * Paranoia.
+ */
+ if ((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);
+ }
+
+ /*
* Note that this does NOT open a file...
* Does 'init' deserve its own facility number?
*/
@@ -270,13 +281,6 @@ main(int argc, char *argv[])
(void) sigaction(SIGTTOU, &sa, NULL);
/*
- * Paranoia.
- */
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- /*
* Start the state machine.
*/
transition(requested_transition);