Unlink the sockets in the shutdown callback, instead of right before creating a new ones. This makes sure we are unlinking the right sockets. --- src/launch-libvirt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c index 185b44b..8a5d93e 100644 --- a/src/launch-libvirt.c +++ b/src/launch-libvirt.c @@ -397,7 +397,6 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri) */ snprintf (data->guestfsd_path, sizeof data->guestfsd_path, "%s/guestfsd.sock", g->tmpdir); - unlink (data->guestfsd_path); set_socket_create_context (g); @@ -424,7 +423,6 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri) /* For the serial console. */ snprintf (data->console_path, sizeof data->console_path, "%s/console.sock", g->tmpdir); - unlink (data->console_path); console_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); if (console_sock == -1) { @@ -2027,6 +2025,16 @@ shutdown_libvirt (guestfs_h *g, void *datav, int check_for_errors) if (conn != NULL) virConnectClose (conn); + if (data->guestfsd_path[0] != '\0') { + unlink (data->guestfsd_path); + data->guestfsd_path[0] = '\0'; + } + + if (data->console_path[0] != '\0') { + unlink (data->console_path); + data->console_path[0] = '\0'; + } + data->conn = NULL; data->dom = NULL; -- 2.5.0