diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2005-06-10 01:41:44 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2005-06-10 01:41:44 +0000 |
commit | 79cd30c1291e309ddcb4b4db84d8b3f8f9e64f1b (patch) | |
tree | 0f519e5c0ee110d56597040573d89346d0245e29 /usr.sbin/syslogd/syslogd.c | |
parent | c3a12aaf75a5d7edf0e8f2891aef7b64c8055ba3 (diff) |
If any of fds 0-2 are not open, dup them to our /dev/null fd.
Prevents the socket from being closed in this case. OK deraadt@
Diffstat (limited to 'usr.sbin/syslogd/syslogd.c')
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index a3070c03073..70d5b99e2ee 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.91 2005/06/06 23:22:04 djm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.92 2005/06/10 01:41:43 millert Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -39,7 +39,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94"; #else -static const char rcsid[] = "$OpenBSD: syslogd.c,v 1.91 2005/06/06 23:22:04 djm Exp $"; +static const char rcsid[] = "$OpenBSD: syslogd.c,v 1.92 2005/06/10 01:41:43 millert Exp $"; #endif #endif /* not lint */ @@ -287,7 +287,7 @@ main(int argc, char *argv[]) socklen_t len; char *p, *line; char resolve[MAXHOSTNAMELEN]; - int lockpipe[2], nullfd = -1; + int lockpipe[2], nullfd; FILE *fp; while ((ch = getopt(argc, argv, "dnuf:m:p:a:s:")) != -1) @@ -330,6 +330,15 @@ main(int argc, char *argv[]) if (Debug) setlinebuf(stdout); + if ((nullfd = open(_PATH_DEVNULL, O_RDWR)) == -1) { + logerror("Couldn't open /dev/null"); + die(0); + } + while (nullfd < 2) { + dup2(nullfd, nullfd + 1); + nullfd++; + } + consfile.f_type = F_CONSOLE; (void)strlcpy(consfile.f_un.f_fname, ctty, sizeof(consfile.f_un.f_fname)); @@ -435,7 +444,6 @@ main(int argc, char *argv[]) exit(1); case 0: setsid(); - nullfd = open(_PATH_DEVNULL, O_RDWR); close(lockpipe[0]); break; default: |