]> git.puffer.fish Git - mirror/frr.git/commitdiff
2005-02-16 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
authorajs <ajs>
Wed, 16 Feb 2005 16:25:39 +0000 (16:25 +0000)
committerajs <ajs>
Wed, 16 Feb 2005 16:25:39 +0000 (16:25 +0000)
* network.c: (set_nonblocking) Should check return code from
  fcntl(F_GETFL).

lib/ChangeLog
lib/network.c

index ee0243894cda7ed0da3008e8fe1bf7a97d726c92..0627d2067903109503b7d363ac8515509bbc07c2 100644 (file)
@@ -1,3 +1,8 @@
+2005-02-16 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+       * network.c: (set_nonblocking) Should check return code from
+         fcntl(F_GETFL).
+
 2005-02-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
        
        * network.h: Declare new function set_nonblocking.  Indicate that
index 3b296720df22f59c76cf824cf659b6cd16f71931..3373983b3cb83b5f6f8278bdd91f4ce6bee02727 100644 (file)
@@ -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));