summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Grunt <pgrunt@redhat.com>2016-10-05 14:33:17 +0200
committerPavel Grunt <pgrunt@redhat.com>2016-10-05 14:58:43 +0200
commita744f9a5ce6cb0719a51ae6249bcfb5d53744702 (patch)
tree890f90665e66343849ccd8662c48bcd135568449
parente73947776d112847f54054097aad0c896c1b472a (diff)
app: Inform user about connection failure
Use errno to get the reason of the failure Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1377100
-rw-r--r--src/virt-viewer-app.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index e8412ac..bf32315 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -35,6 +35,7 @@
#include <gio/gio.h>
#include <glib/gprintf.h>
#include <glib/gi18n.h>
+#include <errno.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
@@ -644,13 +645,14 @@ virt_viewer_app_open_tunnel_ssh(const char *sshhost,
}
static int
-virt_viewer_app_open_unix_sock(const char *unixsock)
+virt_viewer_app_open_unix_sock(const char *unixsock, GError **error)
{
struct sockaddr_un addr;
int fd;
if (strlen(unixsock) + 1 > sizeof(addr.sun_path)) {
- g_warning ("address is too long for unix socket_path: %s", unixsock);
+ g_set_error(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
+ _("Address is too long for unix socket_path: %s"), unixsock);
return -1;
}
@@ -658,10 +660,15 @@ virt_viewer_app_open_unix_sock(const char *unixsock)
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, unixsock);
- if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ g_set_error(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
+ _("Creating unix socket failed: %s"), g_strerror(errno));
return -1;
+ }
if (connect(fd, (struct sockaddr *)&addr, sizeof addr) < 0) {
+ g_set_error(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
+ _("Connecting to unix socket failed: %s"), g_strerror(errno));
close(fd);
return -1;
}
@@ -1194,7 +1201,7 @@ virt_viewer_app_default_activate(VirtViewerApp *self, GError **error)
} else if (priv->unixsock && fd == -1) {
virt_viewer_app_trace(self, "Opening direct UNIX connection to display at %s",
priv->unixsock);
- if ((fd = virt_viewer_app_open_unix_sock(priv->unixsock)) < 0)
+ if ((fd = virt_viewer_app_open_unix_sock(priv->unixsock, error)) < 0)
return FALSE;
}
#endif