From 42218e71256cb86b5078c99c931030c7b0ce9bab Mon Sep 17 00:00:00 2001 From: ajs Date: Wed, 16 Feb 2005 16:25:39 +0000 Subject: 2005-02-16 Andrew J. Schorr * network.c: (set_nonblocking) Should check return code from fcntl(F_GETFL). --- lib/network.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/network.c') diff --git a/lib/network.c b/lib/network.c index 3b296720..3373983b 100644 --- a/lib/network.c +++ b/lib/network.c @@ -75,7 +75,17 @@ writen(int fd, const u_char *ptr, int nbytes) int set_nonblocking(int fd) { - if (fcntl(fd, F_SETFL, (fcntl(fd, F_GETFL) | O_NONBLOCK)) < 0) + int flags; + + /* According to the Single UNIX Spec, the return value for F_GETFL should + never be negative. */ + if ((flags = fcntl(fd, F_GETFL)) < 0) + { + zlog_warn("fcntl(F_GETFL) failed for fd %d: %s", + fd, safe_strerror(errno)); + return -1; + } + if (fcntl(fd, F_SETFL, (flags | O_NONBLOCK)) < 0) { zlog_warn("fcntl failed setting fd %d non-blocking: %s", fd, safe_strerror(errno)); -- cgit v1.2.1