From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLdfa-0005NN-5n for qemu-devel@nongnu.org; Tue, 09 Oct 2012 13:33:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLdf6-0006Dp-5d for qemu-devel@nongnu.org; Tue, 09 Oct 2012 13:32:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLdf5-0006Cy-T9 for qemu-devel@nongnu.org; Tue, 09 Oct 2012 13:32:08 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q99HW79Y021070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Oct 2012 13:32:07 -0400 Date: Tue, 9 Oct 2012 14:33:01 -0300 From: Luiz Capitulino Message-ID: <20121009143301.77cab9a5@doriath.home> In-Reply-To: <1349275025-5093-19-git-send-email-pbonzini@redhat.com> References: <1349275025-5093-1-git-send-email-pbonzini@redhat.com> <1349275025-5093-19-git-send-email-pbonzini@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 18/18] qemu-sockets: add error propagation to Unix socket functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On Wed, 3 Oct 2012 16:37:05 +0200 Paolo Bonzini wrote: > Before: > > $ qemu-system-x86_64 -monitor unix:/vvv,server=off > connect(unix:/vvv): No such file or directory > chardev: opening backend "socket" failed > > After: > > $ x86_64-softmmu/qemu-system-x86_64 -monitor unix:/vvv,server=off > qemu-system-x86_64: -monitor unix:/vvv,server=off: Failed to connect to socket: No such file or directory > chardev: opening backend "socket" failed > > Signed-off-by: Paolo Bonzini I'm assuming that clients will print the error to stderr: Reviewed-by: Luiz Capitulino > --- > qemu-sockets.c | 12 ++++++------ > 1 file modificato, 6 inserzioni(+), 6 rimozioni(-) > > diff --git a/qemu-sockets.c b/qemu-sockets.c > index 55669e9..e28c63c 100644 > --- a/qemu-sockets.c > +++ b/qemu-sockets.c > @@ -633,7 +633,7 @@ int unix_listen_opts(QemuOpts *opts, Error **errp) > > sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0); > if (sock < 0) { > - perror("socket(unix)"); > + error_set_errno(errp, errno, QERR_SOCKET_CREATE_FAILED); > return -1; > } > > @@ -658,11 +658,11 @@ int unix_listen_opts(QemuOpts *opts, Error **errp) > > unlink(un.sun_path); > if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) { > - fprintf(stderr, "bind(unix:%s): %s\n", un.sun_path, strerror(errno)); > + error_set_errno(errp, errno, QERR_SOCKET_BIND_FAILED); > goto err; > } > if (listen(sock, 1) < 0) { > - fprintf(stderr, "listen(unix:%s): %s\n", un.sun_path, strerror(errno)); > + error_set_errno(errp, errno, QERR_SOCKET_LISTEN_FAILED); > goto err; > } > > @@ -682,7 +682,7 @@ int unix_connect_opts(QemuOpts *opts, Error **errp, > int sock, rc; > > if (NULL == path) { > - fprintf(stderr, "unix connect: no path specified\n"); > + error_setg(errp, "unix connect: no path specified\n"); > return -1; > } > > @@ -694,7 +694,7 @@ int unix_connect_opts(QemuOpts *opts, Error **errp, > > sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0); > if (sock < 0) { > - perror("socket(unix)"); > + error_set_errno(errp, errno, QERR_SOCKET_CREATE_FAILED); > return -1; > } > if (connect_state != NULL) { > @@ -726,7 +726,7 @@ int unix_connect_opts(QemuOpts *opts, Error **errp, > } > > if (rc < 0) { > - fprintf(stderr, "connect(unix:%s): %s\n", path, strerror(errno)); > + error_set_errno(errp, -rc, QERR_SOCKET_CONNECT_FAILED); > close(sock); > return -1; > }