]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Clean ghost pid files in 'kvm list'
authorSasha Levin <levinsasha928@gmail.com>
Tue, 5 Jul 2011 09:35:45 +0000 (12:35 +0300)
committerPekka Enberg <penberg@kernel.org>
Tue, 5 Jul 2011 18:58:26 +0000 (21:58 +0300)
When running 'kvm list', first make sure that the guest process
is up and running before printing the entry.

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

index 696c355e928aeff5c437a2166e35abc6f292fbba..40c0e48b9a814c6bc6b61cb531c35d7373afe9b1 100644 (file)
@@ -6,10 +6,31 @@
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
+#include <fcntl.h>
+
+#define PROCESS_NAME "kvm"
 
 static void print_guest(const char *name, int pid)
 {
+       char proc_name[PATH_MAX];
+       char comm[sizeof(PROCESS_NAME)];
+       int fd;
+
+       sprintf(proc_name, "/proc/%d/comm", pid);
+       fd = open(proc_name, O_RDONLY);
+       if (fd <= 0)
+               goto cleanup;
+       if (read(fd, comm, sizeof(PROCESS_NAME)) == 0)
+               goto cleanup;
+       if (strncmp(comm, PROCESS_NAME, strlen(PROCESS_NAME)))
+               goto cleanup;
+
        printf("%s (PID: %d)\n", name, pid);
+
+       return;
+
+cleanup:
+       kvm__remove_pidfile(name);
 }
 
 int kvm_cmd_list(int argc, const char **argv, const char *prefix)