summary refs log tree commit diff stats
path: root/util/qemu-sockets.c
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2015-05-05 11:07:19 -0400
committerGerd Hoffmann <kraxel@redhat.com>2015-05-20 10:23:08 +0200
commit0ef705a2653f09c15e44a644a98b6febc761431e (patch)
treefcfe9ae99e07f523fb55e4c75a0b1794dcb666ff /util/qemu-sockets.c
parentbc119048d7377ec8335ecde5946df629a1b72b46 (diff)
downloadfocaccia-qemu-0ef705a2653f09c15e44a644a98b6febc761431e.tar.gz
focaccia-qemu-0ef705a2653f09c15e44a644a98b6febc761431e.zip
qemu-sockets: Report explicit error if unlink fails
Consider this case:

$ ls -ld ~/root-owned/
drwx--x--x. 2 root root 4096 Apr 29 12:55 /home/crobinso/root-owned/
$ ls -l ~/root-owned/foo.sock
-rwxrwxrwx. 1 crobinso crobinso 0 Apr 29 12:55 /home/crobinso/root-owned/foo.sock

$ qemu-system-x86_64 -vnc unix:~/root-owned/foo.sock
qemu-system-x86_64: -vnc unix:/home/crobinso/root-owned/foo.sock: Failed to start VNC server: Failed to bind socket to /home/crobinso/root-owned/foo.sock: Address already in use

...which is techinically true, but the real error is that we failed to
unlink. So report it.

This may seem pathological but it's a real possibility via libvirt.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'util/qemu-sockets.c')
-rw-r--r--util/qemu-sockets.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 87c9bc6c68..22c8c4c5d5 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -729,7 +729,12 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
         qemu_opt_set(opts, "path", un.sun_path, &error_abort);
     }
 
-    unlink(un.sun_path);
+    if ((access(un.sun_path, F_OK) == 0) &&
+        unlink(un.sun_path) < 0) {
+        error_setg_errno(errp, errno,
+                         "Failed to unlink socket %s", un.sun_path);
+        goto err;
+    }
     if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
         error_setg_errno(errp, errno, "Failed to bind socket to %s", un.sun_path);
         goto err;