Message ID | 1319797077-25441-2-git-send-email-pbonzini@redhat.com |
---|---|
State | New |
Headers | show |
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; }
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 <pbonzini@redhat.com> --- qemu-nbd.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)