From nobody Mon May 6 06:53:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152690111689899.91030482784879; Mon, 21 May 2018 04:11:56 -0700 (PDT) Received: from localhost ([::1]:49849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKijF-00078c-ND for importer@patchew.org; Mon, 21 May 2018 07:11:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKiiH-0006q1-9s for qemu-devel@nongnu.org; Mon, 21 May 2018 07:10:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKiiE-0001CC-3S for qemu-devel@nongnu.org; Mon, 21 May 2018 07:10:49 -0400 Received: from forward106j.mail.yandex.net ([5.45.198.249]:49040) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKiiD-0001AB-H3 for qemu-devel@nongnu.org; Mon, 21 May 2018 07:10:46 -0400 Received: from mxback3j.mail.yandex.net (mxback3j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10c]) by forward106j.mail.yandex.net (Yandex) with ESMTP id 1C7821802FD9 for ; Mon, 21 May 2018 14:10:41 +0300 (MSK) Received: from smtp2j.mail.yandex.net (smtp2j.mail.yandex.net [2a02:6b8:0:801::ac]) by mxback3j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id MG1xdoG7Kj-AetuqSIZ; Mon, 21 May 2018 14:10:41 +0300 Received: by smtp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id itjFGCByJc-AeZW5N9U; Mon, 21 May 2018 14:10:40 +0300 (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=void.so; s=mail; t=1526901041; bh=kncVVpjkW+FntKTtbi7VUO8+0AJJAVTdww5EQAp1n3Y=; h=Date:From:To:Subject:Message-ID; b=rToocay4e2oh3ucj1EswbUYCFVOscEh9c17v+ZiMfJ9vuWuHCIcgPmlJKuq3a6zhd K6jP8I39dopsWOa4MfpJ6xPyFOjcqo9ZNOS3O+wIYJcW2TBC5+GexB2W9eIanolrvp Dj5FMn2+iqqL8GmnR7m6WzQlR1u/GfAYyEB1Nq1Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=void.so; s=mail; t=1526901040; bh=kncVVpjkW+FntKTtbi7VUO8+0AJJAVTdww5EQAp1n3Y=; h=Date:From:To:Subject:Message-ID; b=RqWRjHGRq9nGtWRIX01uq4eM6HkcvpFckbgJb4wsXWU5YMX2NNWucHb/LwnESPSl4 iuOsWCGoaG/r7KiyWvkMq4GmY+s/fQHiyQt3ztTzapvMZtf7PrcHI9W696stdMJU/Y APNijFt4qrfXJgUh9d1cbXwk41O2TeH/VbGH6rrI= Authentication-Results: smtp2j.mail.yandex.net; dkim=pass header.i=@void.so Date: Mon, 21 May 2018 14:10:18 +0300 From: Pavel Balaev To: qemu-devel@nongnu.org Message-ID: <20180521111015.GA26731@rnd> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.5 (2018-04-13) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 5.45.198.249 Subject: [Qemu-devel] [PATCH] Delete AF_UNIX socket after close 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (found 2 invalid signatures) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hello, Since version 2.12.0 AF_UNIX socket created for QMP exchange is not deleted on instance shutdown. This is due to the fact that function qio_channel_socket_finalize() is called after qio_channel_socket_close(). Signed-off-by: Pavel Balaev --- include/qemu/sockets.h | 1 - io/channel-socket.c | 40 +++++++++++++++------------------------- util/qemu-sockets.c | 21 --------------------- 3 files changed, 15 insertions(+), 47 deletions(-) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 8140fea685..a786bd76d7 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -42,7 +42,6 @@ int unix_connect(const char *path, Error **errp); SocketAddress *socket_parse(const char *str, Error **errp); int socket_connect(SocketAddress *addr, Error **errp); int socket_listen(SocketAddress *addr, Error **errp); -void socket_listen_cleanup(int fd, Error **errp); int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp= ); =20 /* Old, ipv4 only bits. Don't use for new code. */ diff --git a/io/channel-socket.c b/io/channel-socket.c index 57cfb4d3a6..3c88ca4130 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -383,30 +383,6 @@ static void qio_channel_socket_init(Object *obj) ioc->fd =3D -1; } =20 -static void qio_channel_socket_finalize(Object *obj) -{ - QIOChannelSocket *ioc =3D QIO_CHANNEL_SOCKET(obj); - - if (ioc->fd !=3D -1) { - QIOChannel *ioc_local =3D QIO_CHANNEL(ioc); - if (qio_channel_has_feature(ioc_local, QIO_CHANNEL_FEATURE_LISTEN)= ) { - Error *err =3D NULL; - - socket_listen_cleanup(ioc->fd, &err); - if (err) { - error_report_err(err); - err =3D NULL; - } - } -#ifdef WIN32 - WSAEventSelect(ioc->fd, NULL, 0); -#endif - closesocket(ioc->fd); - ioc->fd =3D -1; - } -} - - #ifndef WIN32 static void qio_channel_socket_copy_fds(struct msghdr *msg, int **fds, size_t *nfds) @@ -687,6 +663,8 @@ qio_channel_socket_close(QIOChannel *ioc, QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); =20 if (sioc->fd !=3D -1) { + SocketAddress *addr =3D socket_local_address(sioc->fd, errp); + #ifdef WIN32 WSAEventSelect(sioc->fd, NULL, 0); #endif @@ -697,6 +675,19 @@ qio_channel_socket_close(QIOChannel *ioc, return -1; } sioc->fd =3D -1; + + if (addr && addr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX + && addr->u.q_unix.path) { + if (unlink(addr->u.q_unix.path) < 0 && errno !=3D ENOENT) { + error_setg_errno(errp, errno, + "Failed to unlink socket %s", + addr->u.q_unix.path); + } + } + + if (addr) { + qapi_free_SocketAddress(addr); + } } return 0; } @@ -770,7 +761,6 @@ static const TypeInfo qio_channel_socket_info =3D { .name =3D TYPE_QIO_CHANNEL_SOCKET, .instance_size =3D sizeof(QIOChannelSocket), .instance_init =3D qio_channel_socket_init, - .instance_finalize =3D qio_channel_socket_finalize, .class_init =3D qio_channel_socket_class_init, }; =20 diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 8bd8bb64eb..aedcb5b9c0 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1120,27 +1120,6 @@ int socket_listen(SocketAddress *addr, Error **errp) return fd; } =20 -void socket_listen_cleanup(int fd, Error **errp) -{ - SocketAddress *addr; - - addr =3D socket_local_address(fd, errp); - if (!addr) { - return; - } - - if (addr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX - && addr->u.q_unix.path) { - if (unlink(addr->u.q_unix.path) < 0 && errno !=3D ENOENT) { - error_setg_errno(errp, errno, - "Failed to unlink socket %s", - addr->u.q_unix.path); - } - } - - qapi_free_SocketAddress(addr); -} - int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) { int fd; --=20 2.16.1