qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 1/4] qemu-nbd: exit if the child exits before a sock


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 1/4] qemu-nbd: exit if the child exits before a socket connection is established
Date: Fri, 28 Oct 2011 12:17:54 +0200

In -c mode qemu-nbd forks with the parent running the in-kernel NBD
client and the child running the server.  The next patch will introduce
a case in which the child fails after forking.  Detect this situation
and exit the parent.

Signed-off-by: Paolo Bonzini <address@hidden>
---
 qemu-nbd.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index d8d3e15..972524d 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <getopt.h>
 #include <err.h>
+#include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -382,7 +383,9 @@ int main(int argc, char **argv)
             do {
                 sock = unix_socket_outgoing(socket);
                 if (sock == -1) {
-                    if (errno != ENOENT && errno != ECONNREFUSED) {
+                    /* If the child exits before we connect, fail.  */
+                    if (waitpid(pid, NULL, WNOHANG) == pid ||
+                        (errno != ENOENT && errno != ECONNREFUSED)) {
                         ret = 1;
                         goto out;
                     }
-- 
1.7.6.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]