1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00

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@
This commit is contained in:
krw 2016-04-02 19:55:10 +00:00
parent 29088be8b1
commit 7bb95e134a
3 changed files with 10 additions and 9 deletions

View File

@ -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 <anil@recoil.org>
@ -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);
}

View File

@ -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);
}

View File

@ -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 <dirent.h>
#include <errno.h>
#include <event.h>
#include <fcntl.h>
#include <paths.h>
#include <signal.h>
#include <stdio.h>