util: check the return value of fcntl in qemu_set_{block, nonblock}
authorLi Qiang <liq3ea@163.com>
Sat, 15 Dec 2018 12:03:53 +0000 (04:03 -0800)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 15 Jan 2019 00:31:04 +0000 (19:31 -0500)
Assert that the return value is not an error. This is like commit
7e6478e7d4f for qemu_set_cloexec.

Signed-off-by: Li Qiang <liq3ea@163.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
util/oslib-posix.c

index c1bee2a581429bbe4e4a808b42415b2e52b776e1..4ce1ba9ca427495af1c8232a8454ee1e92cd1cdc 100644 (file)
@@ -233,14 +233,18 @@ void qemu_set_block(int fd)
 {
     int f;
     f = fcntl(fd, F_GETFL);
-    fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
+    assert(f != -1);
+    f = fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
+    assert(f != -1);
 }
 
 void qemu_set_nonblock(int fd)
 {
     int f;
     f = fcntl(fd, F_GETFL);
-    fcntl(fd, F_SETFL, f | O_NONBLOCK);
+    assert(f != -1);
+    f = fcntl(fd, F_SETFL, f | O_NONBLOCK);
+    assert(f != -1);
 }
 
 int socket_set_fast_reuse(int fd)