From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG80X-0001UX-KL for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:01:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG80T-0000Fj-4F for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:01:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG80S-0000Em-SJ for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:01:33 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 200887F0B0 for ; Thu, 23 Jun 2016 17:01:32 +0000 (UTC) Date: Thu, 23 Jun 2016 20:01:28 +0300 From: "Michael S. Tsirkin" Message-ID: <20160623194541-mutt-send-email-mst@redhat.com> References: <1466105332-10285-1-git-send-email-marcandre.lureau@redhat.com> <1466105332-10285-4-git-send-email-marcandre.lureau@redhat.com> <20160623073840-mutt-send-email-mst@redhat.com> <20160623074849-mutt-send-email-mst@redhat.com> <934708551.1342481.1466672883154.JavaMail.zimbra@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <934708551.1342481.1466672883154.JavaMail.zimbra@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 3/3] socket: unlink unix socket on remove List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Cc: marcandre lureau , pbonzini@redhat.com, qemu-devel@nongnu.org On Thu, Jun 23, 2016 at 05:08:03AM -0400, Marc-Andr=E9 Lureau wrote: > Hi >=20 > ----- Original Message ----- > > On Thu, Jun 23, 2016 at 07:41:55AM +0300, Michael S. Tsirkin wrote: > > > On Thu, Jun 16, 2016 at 09:28:52PM +0200, marcandre.lureau@redhat.c= om > > > wrote: > > > > From: Marc-Andr=E9 Lureau > > > >=20 > > > > qemu leaves unix socket files behind when removing a listening ch= ardev > > > > or leaving. qemu could clean that up, even if doing so isn't race= -free. > > > >=20 > > > > Fixes: > > > > https://bugzilla.redhat.com/show_bug.cgi?id=3D1347077 > > > >=20 > > > > Signed-off-by: Marc-Andr=E9 Lureau > > >=20 > > > We normally only unlink what we created. >=20 > What do you mean by "we", qemu currently unlink before creating the uni= x socket. No further cleanup. > =20 > > >=20 > > > unlinking files we didn't create > > > looks like a silent change that might easily break > > > existing users. >=20 > That shouldn't remove files we didn't create. But a bad user could recr= eate the unix socket after qemu did, and that would remove it. I don't th= ink that's a valid use case though, so it should be fine. >=20 > > Maybe what you want is a need_unlink feature. > > Set it for unix sockets only, that would make some sense. >=20 > Oh perhaps what you mean is that if the fd was passed, we should cleanu= p the unix socket? Yes, I think we should do that then. I'll update the s= eries. >=20 > thanks I'd like it better contained - that's all. So let's set a flag that says "must unlink" as opposed to "it's listening". > >=20 > > >=20 > > > > --- > > > > include/qemu/sockets.h | 1 + > > > > io/channel-socket.c | 10 ++++++++++ > > > > tests/test-io-channel-socket.c | 2 +- > > > > util/qemu-sockets.c | 18 ++++++++++++++++++ > > > > 4 files changed, 30 insertions(+), 1 deletion(-) > > > >=20 > > > > diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h > > > > index 1bd9218..5dd2648 100644 > > > > --- a/include/qemu/sockets.h > > > > +++ b/include/qemu/sockets.h > > > > @@ -51,6 +51,7 @@ SocketAddress *socket_parse(const char *str, Er= ror > > > > **errp); > > > > int socket_connect(SocketAddress *addr, Error **errp, > > > > NonBlockingConnectHandler *callback, void *op= aque); > > > > int socket_listen(SocketAddress *addr, Error **errp); > > > > +void socket_listen_cleanup(int fd, Error **errp); > > > > int socket_dgram(SocketAddress *remote, SocketAddress *local, Er= ror > > > > **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 1cd5848..6ec87f8 100644 > > > > --- a/io/channel-socket.c > > > > +++ b/io/channel-socket.c > > > > @@ -400,7 +400,17 @@ static void qio_channel_socket_init(Object *= obj) > > > > static void qio_channel_socket_finalize(Object *obj) > > > > { > > > > QIOChannelSocket *ioc =3D QIO_CHANNEL_SOCKET(obj); > > > > + > > > > if (ioc->fd !=3D -1) { > > > > + if (QIO_CHANNEL(ioc)->features & QIO_CHANNEL_FEATURE_LIS= TEN) { > > > > + 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 > > > > diff --git a/tests/test-io-channel-socket.c > > > > b/tests/test-io-channel-socket.c > > > > index 855306b..f73e063 100644 > > > > --- a/tests/test-io-channel-socket.c > > > > +++ b/tests/test-io-channel-socket.c > > > > @@ -383,7 +383,7 @@ static void test_io_channel_unix(bool async) > > > > =20 > > > > qapi_free_SocketAddress(listen_addr); > > > > qapi_free_SocketAddress(connect_addr); > > > > - unlink(TEST_SOCKET); > > > > + g_assert(g_file_test(TEST_SOCKET, G_FILE_TEST_EXISTS) =3D=3D= FALSE); > > > > } > > > > =20 > > > > =20 > > > > diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c > > > > index 0d6cd1f..5d03695 100644 > > > > --- a/util/qemu-sockets.c > > > > +++ b/util/qemu-sockets.c > > > > @@ -997,6 +997,24 @@ 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->type =3D=3D SOCKET_ADDRESS_KIND_UNIX > > > > + && addr->u.q_unix.data->path) { > > > > + if (unlink(addr->u.q_unix.data->path) < 0 && errno !=3D = ENOENT) { > > > > + error_setg_errno(errp, errno, > > > > + "Failed to unlink socket %s", > > > > + addr->u.q_unix.data->path); > > > > + } > > > > + } > > > > + > > > > + g_free(addr); > > > > +} > > > > + > > > > int socket_dgram(SocketAddress *remote, SocketAddress *local, Er= ror > > > > **errp) > > > > { > > > > int fd; > > > > -- > > > > 2.7.4 > > > >=20 > >=20