From patchwork Wed Aug 23 16:19:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 805100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3xct9g6WbTz9s9Y for ; Thu, 24 Aug 2017 02:27:03 +1000 (AEST) Received: from localhost ([::1]:44665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYUf-0001iR-Mi for incoming@patchwork.ozlabs.org; Wed, 23 Aug 2017 12:27:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYOb-0005YZ-UC for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:20:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYOZ-000736-JY for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:20:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57942) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkYOZ-00071B-CE for qemu-devel@nongnu.org; Wed, 23 Aug 2017 12:20:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66F281E318; Wed, 23 Aug 2017 16:20:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 66F281E318 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com Received: from localhost (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2CDF51344; Wed, 23 Aug 2017 16:20:41 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 18:19:48 +0200 Message-Id: <20170823162004.27337-12-marcandre.lureau@redhat.com> In-Reply-To: <20170823162004.27337-1-marcandre.lureau@redhat.com> References: <20170823162004.27337-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 23 Aug 2017 16:20:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/27] vhost-user-scsi: simplify unix path cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , changpeng.liu@intel.com, felipe@nutanix.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Always remove the unix path when leaving the program (instead of when freeing scsi_dev). Note that unix_sock_new() also unlink() exisiting path before creating the socket. Signed-off-by: Marc-André Lureau Reviewed-by: Paolo Bonzini --- contrib/vhost-user-scsi/vhost-user-scsi.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c index bb10848cd2..624efc24ca 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -636,24 +636,9 @@ fail: static void vdev_scsi_free(vhost_scsi_dev_t *vdev_scsi) { - if (!vdev_scsi) { - return; - } - if (vdev_scsi->server_sock >= 0) { - struct sockaddr_storage ss; - socklen_t sslen = sizeof(ss); - - if (getsockname(vdev_scsi->server_sock, (struct sockaddr *)&ss, - &sslen) == 0) { - struct sockaddr_un *su = (struct sockaddr_un *)&ss; - (void)unlink(su->sun_path); - } - - (void)close(vdev_scsi->server_sock); - vdev_scsi->server_sock = -1; + close(vdev_scsi->server_sock); } - g_main_loop_unref(vdev_scsi->loop); g_tree_destroy(vdev_scsi->fdmap); g_free(vdev_scsi); @@ -764,7 +749,10 @@ int main(int argc, char **argv) } out: - vdev_scsi_free(vdev_scsi); + if (vdev_scsi) { + vdev_scsi_free(vdev_scsi); + unlink(unix_fn); + } g_free(unix_fn); g_free(iscsi_uri);