xenstore: check F_SETFL fcntl invocation in setnonblock
authorMatthew Daley <mattd@bugfuzz.com>
Mon, 2 Dec 2013 12:45:16 +0000 (01:45 +1300)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 13 Dec 2013 16:55:12 +0000 (16:55 +0000)
...and check the newly-added result of setnonblock itself where used.

Coverity-ID: 1055103
Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/xenstore/xs.c

index 261b8413102578537fc5c9494ff818fdbb2e094c..f1f1b9dc13509c2e5015927a291949b25fd442e9 100644 (file)
@@ -146,20 +146,20 @@ struct xs_handle {
 
 static int read_message(struct xs_handle *h, int nonblocking);
 
-static void setnonblock(int fd, int nonblock) {
-       int esave = errno;
+static bool setnonblock(int fd, int nonblock) {
        int flags = fcntl(fd, F_GETFL);
        if (flags == -1)
-               goto out;
+               return false;
 
        if (nonblock)
                flags |= O_NONBLOCK;
        else
                flags &= ~O_NONBLOCK;
 
-       fcntl(fd, F_SETFL, flags);
-out:
-       errno = esave;
+       if (fcntl(fd, F_SETFL, flags) == -1)
+               return false;
+
+       return true;
 }
 
 int xs_fileno(struct xs_handle *h)
@@ -369,8 +369,8 @@ static bool read_all(int fd, void *data, unsigned int len, int nonblocking)
        if (!len)
                return true;
 
-       if (nonblocking)
-               setnonblock(fd, 1);
+       if (nonblocking && !setnonblock(fd, 1))
+               return false;
 
        while (len) {
                int done;
@@ -390,8 +390,9 @@ static bool read_all(int fd, void *data, unsigned int len, int nonblocking)
                len -= done;
 
                if (nonblocking) {
-                       setnonblock(fd, 0);
                        nonblocking = 0;
+                       if (!setnonblock(fd, 0))
+                               goto out_false;
                }
        }