Received: from eggs.gnu.org ([140.186.70.92]:35180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJjVo-0008Np-QF for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:18:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJjVn-0001Ma-LL for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:18:08 -0400 Received: from mail-qy0-f173.google.com ([209.85.216.173]:54587) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJjVn-0001Lz-De for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:18:07 -0400 Received: by mail-qy0-f173.google.com with SMTP id 10so2997058qyk.4 for ; Fri, 28 Oct 2011 03:18:07 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 28 Oct 2011 12:17:54 +0200 Message-Id: <1319797077-25441-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1319797077-25441-1-git-send-email-pbonzini@redhat.com> References: <1319797077-25441-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1/4] qemu-nbd: exit if the child exits before a socket connection is established List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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 #include #include +#include #include #include #include @@ -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