From f2c9ac616cd3cf63bf50109aa211cdc11ba3f050 Mon Sep 17 00:00:00 2001
Message-Id: <f2c9ac616cd3cf63bf50109aa211cdc11ba3f050.1374754301.git.minovotn@redhat.com>
In-Reply-To: <5d75a8513d08b33975bdf5971871c0c977167cd1.1374754301.git.minovotn@redhat.com>
References: <5d75a8513d08b33975bdf5971871c0c977167cd1.1374754301.git.minovotn@redhat.com>
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Mon, 24 Jun 2013 07:05:31 +0200
Subject: [PATCH 20/65] qemu-sockets: add error propagation to Unix socket
 functions

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1372057576-26450-21-git-send-email-kraxel@redhat.com>
Patchwork-id: 52143
O-Subject: [RHEL-6.5 qemu-kvm PATCH v2 20/65] qemu-sockets: add error propagation to Unix socket functions
Bugzilla: 676568
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

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

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 58899664de29c250229f8d306fcf04f852cf5cc6)

[ rhel6: use error_setg_errno instead of error_set_errno ]
---
 qemu-sockets.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 qemu-sockets.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/qemu-sockets.c b/qemu-sockets.c
index c34e8b3..2897e36 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -634,7 +634,7 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
 
     sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
     if (sock < 0) {
-        perror("socket(unix)");
+        error_setg_errno(errp, errno, "socket create failed");
         return -1;
     }
 
@@ -659,11 +659,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_setg_errno(errp, errno, "socket bind failed");
         goto err;
     }
     if (listen(sock, 1) < 0) {
-        fprintf(stderr, "listen(unix:%s): %s\n", un.sun_path, strerror(errno));
+        error_setg_errno(errp, errno, "socket listen failed");
         goto err;
     }
 
@@ -683,13 +683,13 @@ 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;
     }
 
     sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
     if (sock < 0) {
-        perror("socket(unix)");
+        error_setg_errno(errp, errno, "socket create failed");
         return -1;
     }
     if (callback != NULL) {
@@ -724,7 +724,7 @@ int unix_connect_opts(QemuOpts *opts, Error **errp,
     }
 
     if (rc < 0) {
-        fprintf(stderr, "connect(unix:%s): %s\n", path, strerror(errno));
+        error_setg_errno(errp, -rc, "socket connect failed");
         close(sock);
         sock = -1;
     }
@@ -737,7 +737,7 @@ int unix_connect_opts(QemuOpts *opts, Error **errp,
 
 int unix_listen_opts(QemuOpts *opts, Error **errp)
 {
-    fprintf(stderr, "unix sockets are not available on windows\n");
+    error_setg(errp, "unix sockets are not available on windows");
     errno = ENOTSUP;
     return -1;
 }
@@ -745,7 +745,7 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
 int unix_connect_opts(QemuOpts *opts, Error **errp,
                       NonBlockingConnectHandler *callback, void *opaque)
 {
-    fprintf(stderr, "unix sockets are not available on windows\n");
+    error_setg(errp, "unix sockets are not available on windows");
     errno = ENOTSUP;
     return -1;
 }
-- 
1.7.11.7

