diff options
author | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2004-04-02 21:44:51 +0000 |
---|---|---|
committer | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2004-04-02 21:44:51 +0000 |
commit | 74c8801d9b976bc2cba5c862318deaedeab5d089 (patch) | |
tree | 02d0dcdb31223263519b35b7c1be10e2d3788404 /usr.sbin/syslogd | |
parent | 7401427ce5e416aeee68c734bdff3fc3b5c6f45d (diff) |
Do not bother closing an fd when we know it has failed.
Based on diff from Moritz Jodeit <moritz at jodeit.org>
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r-- | usr.sbin/syslogd/privsep.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/usr.sbin/syslogd/privsep.c b/usr.sbin/syslogd/privsep.c index 0910101fb7b..be787c81feb 100644 --- a/usr.sbin/syslogd/privsep.c +++ b/usr.sbin/syslogd/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.16 2004/03/14 19:17:05 otto Exp $ */ +/* $OpenBSD: privsep.c,v 1.17 2004/04/02 21:44:50 avsm Exp $ */ /* * Copyright (c) 2003 Anil Madhavapeddy <anil@recoil.org> @@ -208,10 +208,11 @@ priv_init(char *conf, int numeric, int lockfd, int nullfd, char *argv[]) path[path_len - 1] = '\0'; check_tty_name(path, path_len); fd = open(path, O_WRONLY|O_NONBLOCK, 0); + send_fd(socks[0], fd); if (fd < 0) warnx("priv_open_tty failed"); - send_fd(socks[0], fd); - close(fd); + else + close(fd); break; case PRIV_OPEN_LOG: @@ -224,29 +225,32 @@ priv_init(char *conf, int numeric, int lockfd, int nullfd, char *argv[]) path[path_len - 1] = '\0'; check_log_name(path, path_len); fd = open(path, O_WRONLY|O_APPEND|O_NONBLOCK, 0); + send_fd(socks[0], fd); if (fd < 0) warnx("priv_open_log failed"); - send_fd(socks[0], fd); - close(fd); + else + close(fd); break; case PRIV_OPEN_UTMP: dprintf("[priv]: msg PRIV_OPEN_UTMP received\n"); fd = open(_PATH_UTMP, O_RDONLY|O_NONBLOCK, 0); + send_fd(socks[0], fd); if (fd < 0) warnx("priv_open_utmp failed"); - send_fd(socks[0], fd); - close(fd); + else + close(fd); break; case PRIV_OPEN_CONFIG: dprintf("[priv]: msg PRIV_OPEN_CONFIG received\n"); stat(config_file, &cf_info); fd = open(config_file, O_RDONLY|O_NONBLOCK, 0); + send_fd(socks[0], fd); if (fd < 0) warnx("priv_open_config failed"); - send_fd(socks[0], fd); - close(fd); + else + close(fd); break; case PRIV_CONFIG_MODIFIED: |