aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/qemu-sockets.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 87c9bc6c68..22c8c4c5d5 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -729,7 +729,12 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
qemu_opt_set(opts, "path", un.sun_path, &error_abort);
}
- unlink(un.sun_path);
+ if ((access(un.sun_path, F_OK) == 0) &&
+ unlink(un.sun_path) < 0) {
+ error_setg_errno(errp, errno,
+ "Failed to unlink socket %s", un.sun_path);
+ goto err;
+ }
if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
error_setg_errno(errp, errno, "Failed to bind socket to %s", un.sun_path);
goto err;