From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuzSI-0000PL-IX for qemu-devel@nongnu.org; Wed, 20 May 2015 04:34:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuzSF-0007C9-P5 for qemu-devel@nongnu.org; Wed, 20 May 2015 04:34:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuzSF-0007C3-Jh for qemu-devel@nongnu.org; Wed, 20 May 2015 04:34:19 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 43AA1A0B73 for ; Wed, 20 May 2015 08:34:19 +0000 (UTC) From: Gerd Hoffmann Date: Wed, 20 May 2015 10:34:13 +0200 Message-Id: <1432110853-11399-6-git-send-email-kraxel@redhat.com> In-Reply-To: <1432110853-11399-1-git-send-email-kraxel@redhat.com> References: <1432110853-11399-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 5/5] qemu-sockets: Report explicit error if unlink fails List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Cole Robinson From: Cole Robinson 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 Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- util/qemu-sockets.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 87c9bc6..22c8c4c 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; -- 1.8.3.1