socket: Undefined variable when setting SO_NOSIGPIPE
authorMarko Kreen <markokr@gmail.com>
Thu, 27 Aug 2009 08:19:43 +0000 (11:19 +0300)
committerMarko Kreen <markokr@gmail.com>
Thu, 27 Aug 2009 08:24:12 +0000 (11:24 +0300)
Reshuffle code to have val defined only when SO_NOSIGPIPE
is available.

Reported-by: Khee Chin
usual/socket.c

index feb255625bf1fe3a70f934e69fa4e1a155d407db..88dd5eaf3a8e9906453431b4c600d19934e3175a 100644 (file)
@@ -67,19 +67,19 @@ bool socket_setup(int sock, bool non_block)
 {
        int res;
 
-       /* close fd on exec */
-       res = fcntl(sock, F_SETFD, FD_CLOEXEC);
-       if (res < 0)
-               return false;
-
 #ifdef SO_NOSIGPIPE
        /* disallow SIGPIPE, if possible */
-       val = 1;
+       int val = 1;
        res = setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(val));
        if (res < 0)
                return false;
 #endif
 
+       /* close fd on exec */
+       res = fcntl(sock, F_SETFD, FD_CLOEXEC);
+       if (res < 0)
+               return false;
+
        /* when no data available, return EAGAIN instead blocking */
        if (!socket_set_nonblocking(sock, non_block))
                return false;