[PATCH 2/2] kvm tools: Clean ghost pid files in 'kvm list'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 tools/kvm/kvm-list.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/kvm-list.c b/tools/kvm/kvm-list.c
index 696c355..40c0e48 100644
--- a/tools/kvm/kvm-list.c
+++ b/tools/kvm/kvm-list.c
@@ -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)
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux