netdev-linux: Check return value of set_nonblocking().
authorBen Pfaff <blp@nicira.com>
Thu, 24 Jan 2013 21:22:30 +0000 (13:22 -0800)
committerBen Pfaff <blp@nicira.com>
Fri, 1 Feb 2013 22:27:03 +0000 (14:27 -0800)
It's unlikely to fail but checking it can't hurt.

Found by Coverity.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/netdev-linux.c

index 5de4fa2..4ea7a36 100644 (file)
@@ -4639,7 +4639,11 @@ af_packet_sock(void)
     if (sock == INT_MIN) {
         sock = socket(AF_PACKET, SOCK_RAW, 0);
         if (sock >= 0) {
-            set_nonblocking(sock);
+            int error = set_nonblocking(sock);
+            if (error) {
+                close(sock);
+                sock = -error;
+            }
         } else {
             sock = -errno;
             VLOG_ERR("failed to create packet socket: %s", strerror(errno));