[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/2] xenstore: check F_SETFL fcntl invocation in setnonblock



...and check the newly-added result of setnonblock itself where used.

Coverity-ID: 1055103
Signed-off-by: Matthew Daley <mattd@xxxxxxxxxxx>
---
 tools/xenstore/xs.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 184886f..abac788 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -146,20 +146,17 @@ 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;
+       return fcntl(fd, F_SETFL, flags) != -1;
 }
 
 int xs_fileno(struct xs_handle *h)
@@ -369,8 +366,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 +387,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))
+                               return false;
                }
        }
 
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.