diff mbox

[09/25] qemu-nbd: fork() can fail

Message ID 1424887718-10800-10-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Feb. 25, 2015, 6:08 p.m. UTC
It is very unlikely, but it is possible.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 qemu-nbd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/qemu-nbd.c b/qemu-nbd.c
index 9b9d40d..c9ed003 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -638,7 +638,9 @@  int main(int argc, char **argv)
          * print errors and exit with the proper status code.
          */
         pid = fork();
-        if (pid == 0) {
+        if (pid < 0) {
+            err(EXIT_FAILURE, "Failed to fork");
+        } else if (pid == 0) {
             close(stderr_fd[0]);
             ret = qemu_daemon(1, 0);