aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2019-06-07 18:01:20 +0100
committerWill Deacon <will.deacon@arm.com>2019-06-10 13:16:25 +0100
commit67f9f7b70191274274c1b8fae4acece986ad202e (patch)
treee6655424e3e7e7a10adbb0b4d788b2e17eb19608
parenteaeaf60808d6b60fb17adbb8312039f9a7c1abe6 (diff)
downloadkvmtool-67f9f7b70191274274c1b8fae4acece986ad202e.tar.gz
list: Clean up ghost socket files
When kvmtool (or the host kernel) crashes or gets killed, we cannot automatically remove the socket file we created for that VM. A later call of "lkvm list" iterates over all those files and complains about those "ghost socket files", as there is no one listening on the other side. Also sometimes the automatic guest name generation happens to generate the same name again, so an unrelated "lkvm run" later complains and stops, which is bad for automation. As the only code doing a listen() on this socket is kvmtool upon VM *creation*, such an orphaned socket file will never come back to life, so we can as well unlink() those sockets in the code. This spares the user from doing it herself. We keep the message in the code to notify the user of this. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--kvm-ipc.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/kvm-ipc.c b/kvm-ipc.c
index e07ad105..29ea498a 100644
--- a/kvm-ipc.c
+++ b/kvm-ipc.c
@@ -101,9 +101,9 @@ int kvm__get_sock_by_instance(const char *name)
r = connect(s, (struct sockaddr *)&local, len);
if (r < 0 && errno == ECONNREFUSED) {
- /* Tell the user clean ghost socket file */
- pr_err("\"%s\" could be a ghost socket file, please remove it",
- sock_file);
+ /* Clean up the ghost socket file */
+ unlink(local.sun_path);
+ pr_info("Removed ghost socket file \"%s\".", sock_file);
return r;
} else if (r < 0) {
return r;