From a55e1169da61fa81974081006c42e49a98442ad9 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Sat, 2 Apr 2016 19:55:11 +0000 Subject: Eliminate superfluous 3rd params in fcntl(F_GETFL) calls. ttymsg.c doesn't need to include fcntl.h. Tweak standard fd sanitising to be more like the sanitise_stdfd() used elsewhere, though other uses of 'nullfd' make importing sanitise_stdfd() itself unappetizing. Add a die(0) if dup2() fails. suggestions & ok bluhm@ --- usr.sbin/syslogd/privsep.c | 4 ++-- usr.sbin/syslogd/syslogd.c | 12 +++++++----- usr.sbin/syslogd/ttymsg.c | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/syslogd/privsep.c b/usr.sbin/syslogd/privsep.c index 7700a11a78b..a3cfc170de0 100644 --- a/usr.sbin/syslogd/privsep.c +++ b/usr.sbin/syslogd/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.59 2015/10/20 12:40:19 bluhm Exp $ */ +/* $OpenBSD: privsep.c,v 1.60 2016/04/02 19:55:10 krw Exp $ */ /* * Copyright (c) 2003 Anil Madhavapeddy @@ -446,7 +446,7 @@ open_pipe(char *cmd) } /* make the fd on syslogd's side nonblocking */ - if ((flags = fcntl(fd[1], F_GETFL, 0)) == -1) { + if ((flags = fcntl(fd[1], F_GETFL)) == -1) { warnx("fcntl"); return (-1); } diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index aca84696813..da917502a27 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.204 2016/02/17 18:31:28 bluhm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.205 2016/04/02 19:55:10 krw Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -436,10 +436,12 @@ main(int argc, char *argv[]) logerror("Couldn't open /dev/null"); die(0); } - for (fd = nullfd + 1; fd <= 2; fd++) { - if (fcntl(fd, F_GETFL, 0) == -1) - if (dup2(nullfd, fd) == -1) + for (fd = nullfd + 1; fd <= STDERR_FILENO; fd++) { + if (fcntl(fd, F_GETFL) == -1 && errno == EBADF) + if (dup2(nullfd, fd) == -1) { logerror("dup2"); + die(0); + } } consfile.f_type = F_CONSOLE; @@ -2651,7 +2653,7 @@ cfline(char *line, char *progblock, char *hostblock) f->f_type = F_FILE; /* Clear O_NONBLOCK flag on f->f_file */ - if ((i = fcntl(f->f_file, F_GETFL, 0)) != -1) { + if ((i = fcntl(f->f_file, F_GETFL)) != -1) { i &= ~O_NONBLOCK; fcntl(f->f_file, F_SETFL, i); } diff --git a/usr.sbin/syslogd/ttymsg.c b/usr.sbin/syslogd/ttymsg.c index ef50b3927e2..e899c786973 100644 --- a/usr.sbin/syslogd/ttymsg.c +++ b/usr.sbin/syslogd/ttymsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ttymsg.c,v 1.9 2015/10/23 16:28:52 bluhm Exp $ */ +/* $OpenBSD: ttymsg.c,v 1.10 2016/04/02 19:55:10 krw Exp $ */ /* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */ /* @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3