From patchwork Wed Apr 29 16:37:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 466181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 95F6A140320 for ; Thu, 30 Apr 2015 02:38:39 +1000 (AEST) Received: from localhost ([::1]:40068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnV0P-0003kj-OZ for incoming@patchwork.ozlabs.org; Wed, 29 Apr 2015 12:38:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnUzs-0002Q8-1F for qemu-devel@nongnu.org; Wed, 29 Apr 2015 12:38:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnUzq-0008Js-6W for qemu-devel@nongnu.org; Wed, 29 Apr 2015 12:38:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnUzq-0008Jl-0A for qemu-devel@nongnu.org; Wed, 29 Apr 2015 12:38:02 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3TGc1Y4001867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 29 Apr 2015 12:38:01 -0400 Received: from colepc.redhat.com ([10.3.113.6]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3TGbwBS014609; Wed, 29 Apr 2015 12:38:00 -0400 From: Cole Robinson To: qemu-devel@nongnu.org Date: Wed, 29 Apr 2015 12:37:50 -0400 Message-Id: <3d1c0b890723c377d9aa5c3bf416097e3cea90b3.1430325445.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann , Cole Robinson Subject: [Qemu-devel] [PATCH 3/3] qemu-sockets: Report explicit error if unlink fails X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It's possible via libvirt for a user to request an explicit socket path that qemu lacks permissions to unlink, but the error that's reported is from bind(2), 'Address already in use' bind(2) will fail if the unix socket path already exists, so we need to unlink first. But we should report the unlink failure Signed-off-by: Cole Robinson --- util/qemu-sockets.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 87c9bc6..9ef3f7c 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -729,7 +729,11 @@ 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) && + 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;