Received: from eggs.gnu.org ([208.118.235.92]:38770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOUxy-0007d2-C0 for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:51:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOUxs-0007Gw-5L for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:51:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60638) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOUxr-0007Gs-Tq for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:51:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9HEpIdu029532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Oct 2012 10:51:19 -0400 From: Markus Armbruster References: <1349877786-23514-1-git-send-email-pbonzini@redhat.com> <1349877786-23514-12-git-send-email-pbonzini@redhat.com> Date: Wed, 17 Oct 2012 16:51:16 +0200 In-Reply-To: <1349877786-23514-12-git-send-email-pbonzini@redhat.com> (Paolo Bonzini's message of "Wed, 10 Oct 2012 16:02:52 +0200") Message-ID: <87vce9xicb.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 11/25] nbd: ask and print error information from qemu-sockets List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, lcapitulino@redhat.com Paolo Bonzini writes: > Before: > > $ qemu-system-x86_64 nbd:localhost:12345 > inet_connect_opts: connect(ipv4,yakj.usersys.redhat.com,127.0.0.1,12345): Connection refused > qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused > > After: > > $ x86_64-softmmu/qemu-system-x86_64 nbd:localhost:12345 > qemu-system-x86_64: Failed to connect to socket: Connection refused > qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused > > Signed-off-by: Paolo Bonzini > --- > nbd.c | 39 +++++++++++++++++++++++++++++++-------- > 1 file modificato, 31 inserzioni(+), 8 rimozioni(-) > > diff --git a/nbd.c b/nbd.c > index f61a288..cec5a94 100644 > --- a/nbd.c > +++ b/nbd.c > @@ -208,7 +208,14 @@ int tcp_socket_outgoing(const char *address, uint16_t port) > > int tcp_socket_outgoing_spec(const char *address_and_port) > { > - return inet_connect(address_and_port, NULL); > + Error *local_err = NULL; > + int fd = inet_connect(address_and_port, &local_err); > + > + if (local_err != NULL) { > + qerror_report_err(local_err); > + error_free(local_err); > + } > + return fd; > } > > int tcp_socket_incoming(const char *address, uint16_t port) > @@ -220,22 +227,38 @@ int tcp_socket_incoming(const char *address, uint16_t port) > > int tcp_socket_incoming_spec(const char *address_and_port) > { > - char *ostr = NULL; > - int olen = 0; > - return inet_listen(address_and_port, ostr, olen, SOCK_STREAM, 0, NULL); > + Error *local_err = NULL; > + int fd = inet_listen(address_and_port, NULL, 0, SOCK_STREAM, 0, &local_err); > + > + if (local_err != NULL) { > + qerror_report_err(local_err); > + error_free(local_err); > + } > + return fd; > } > > int unix_socket_incoming(const char *path) > { > - char *ostr = NULL; > - int olen = 0; > + Error *local_err = NULL; > + int fd = unix_listen(path, NULL, 0, &local_err); > > - return unix_listen(path, ostr, olen, NULL); > + if (local_err != NULL) { > + qerror_report_err(local_err); > + error_free(local_err); > + } > + return fd; > } > > int unix_socket_outgoing(const char *path) > { > - return unix_connect(path, NULL); > + Error *local_err = NULL; > + int fd = unix_connect(path, &local_err); > + > + if (local_err != NULL) { > + qerror_report_err(local_err); > + error_free(local_err); > + } > + return fd; > } > > /* Basic flow for negotiation The boilerplate pattern Error *local_err = NULL; FOO(..., *local_err); if (local_err) { qerror_report_err(local_err); error_free(local_err); } is spreading. Not quite sure it's worth a macro.