From 74b6ce43e3aacbb101018407196fc963e2c39fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 16 Jun 2016 21:28:52 +0200 Subject: socket: unlink unix socket on remove MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu leaves unix socket files behind when removing a listening chardev or leaving. qemu could clean that up, even if doing so isn't race-free. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1347077 Signed-off-by: Marc-André Lureau Message-Id: <1466105332-10285-4-git-send-email-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- util/qemu-sockets.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'util') diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 0d6cd1f4ef..5d03695d10 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -997,6 +997,24 @@ int socket_listen(SocketAddress *addr, Error **errp) return fd; } +void socket_listen_cleanup(int fd, Error **errp) +{ + SocketAddress *addr; + + addr = socket_local_address(fd, errp); + + if (addr->type == SOCKET_ADDRESS_KIND_UNIX + && addr->u.q_unix.data->path) { + if (unlink(addr->u.q_unix.data->path) < 0 && errno != 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, Error **errp) { int fd; -- cgit v1.2.3