libxl: check return values of read/write
authorIan Campbell <ian.campbell@citrix.com>
Thu, 2 Jun 2011 16:26:10 +0000 (17:26 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 2 Jun 2011 16:26:10 +0000 (17:26 +0100)
Some distros enable -D_FORTIFY_SOURCE=2 by default
(https://wiki.ubuntu.com/CompilerFlags) which adds the warn_unused_result
attribute to several functions including read(2) and write(2)

Although we don't really care about error reading or writing the libxl spawn fd
catch them anyway to keep this warning happy.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Tested-by: Olaf Hering <olaf@aepfle.de>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_device.c
tools/libxl/libxl_exec.c

index cc3ae25d1aa933d02470d4ebc37beabd79f77978..ba537bfde84b791bb1a3387c79619685e5f0ed95 100644 (file)
@@ -485,7 +485,9 @@ again:
             }
             if (starting && FD_ISSET(starting->for_spawn->fd, &rfds)) {
                 unsigned char dummy;
-                read(starting->for_spawn->fd, &dummy, sizeof(dummy));
+                if (read(starting->for_spawn->fd, &dummy, sizeof(dummy)) != 1)
+                    LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_DEBUG,
+                                     "failed to read spawn status pipe");
             }
         }
     }
index 4a98f733a6355f7f6c8d15ebc5e8ebd60e177ef2..60d0b51014be1c7b79d47d85c5df714ea98599a5 100644 (file)
@@ -220,8 +220,10 @@ int libxl__spawn_spawn(libxl__gc *gc,
     rc = (WIFEXITED(status) ? WEXITSTATUS(status) :
           WIFSIGNALED(status) && WTERMSIG(status) < 127
           ? WTERMSIG(status)+128 : -1);
-    if (for_spawn)
-        write(pipes[1], &dummy, sizeof(dummy));
+    if (for_spawn) {
+        if (write(pipes[1], &dummy, sizeof(dummy)) != 1)
+            perror("libxl__spawn_spawn: unable to signal child exit to parent");
+    }
     _exit(rc);
 
  err_parent_pipes: