summaryrefslogtreecommitdiffstats
path: root/lib/network.c
diff options
context:
space:
mode:
authorajs <ajs>2005-02-16 16:25:39 +0000
committerajs <ajs>2005-02-16 16:25:39 +0000
commit235f12e8f3a929a96d8ef03f7b5909cf0021d5e8 (patch)
tree9ae77dff35301811afc87b0af335ed3199da6b78 /lib/network.c
parentbeedd03aaf4a0b2bd9cc0ea73bb99cc9ce2b7b78 (diff)
downloadquagga-235f12e8f3a929a96d8ef03f7b5909cf0021d5e8.tar.bz2
quagga-235f12e8f3a929a96d8ef03f7b5909cf0021d5e8.tar.xz
2005-02-16 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* network.c: (set_nonblocking) Should check return code from fcntl(F_GETFL).
Diffstat (limited to 'lib/network.c')
-rw-r--r--lib/network.c12
1 files changed, 11 insertions, 1 deletions
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));