]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Cleanup ghost socket files
authorSasha Levin <levinsasha928@gmail.com>
Fri, 28 Oct 2011 09:01:55 +0000 (11:01 +0200)
committerPekka Enberg <penberg@kernel.org>
Sun, 30 Oct 2011 07:20:17 +0000 (09:20 +0200)
Clean ghost socket files as part of the regular connection process.

This fixes the bug of 'kvm list' failing with "Failed connecting to instance"
when ghost socket files existed.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm.c

index d953b945e0a2d9b22bbb88d395a5cc14f29a1516..252bd18e91600576c88b1bc75719dd8b54956e05 100644 (file)
@@ -208,8 +208,13 @@ int kvm__get_sock_by_instance(const char *name)
        len = strlen(local.sun_path) + sizeof(local.sun_family);
 
        r = connect(s, &local, len);
-       if (r < 0)
+       if (r < 0 && errno == ECONNREFUSED) {
+               /* Clean ghost socket file */
+               unlink(sock_file);
+               return -1;
+       } else if (r < 0) {
                die("Failed connecting to instance");
+       }
 
        return s;
 }
@@ -232,6 +237,8 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int fd))
                if (entry.d_type == DT_SOCK) {
                        entry.d_name[strlen(entry.d_name)-5] = 0;
                        sock = kvm__get_sock_by_instance(entry.d_name);
+                       if (sock < 0)
+                               continue;
                        ret = callback(entry.d_name, sock);
                        close(sock);
                        if (ret < 0)