All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] kvm tools: Export kvm__remove_pidfile
@ 2011-07-05  9:35 Sasha Levin
  2011-07-05  9:35 ` [PATCH 2/2] kvm tools: Clean ghost pid files in 'kvm list' Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2011-07-05  9:35 UTC (permalink / raw)
  To: penberg; +Cc: mingo, asias.hejun, prasadjoshi124, gorcunov, kvm, Sasha Levin

This will allow cleaning up ghost pid files outside of the module.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/include/kvm/kvm.h |    1 +
 tools/kvm/kvm.c             |    9 +++------
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index da9e12c..5cfb0d8 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -68,6 +68,7 @@ void kvm__continue(void);
 void kvm__notify_paused(void);
 int kvm__get_pid_by_instance(const char *name);
 int kvm__enumerate_instances(void (*callback)(const char *name, int pid));
+void kvm__remove_pidfile(const char *name);
 
 /*
  * Debugging
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 075c8d8..cd3cb19 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -134,14 +134,11 @@ static void kvm__create_pidfile(struct kvm *kvm)
 	close(fd);
 }
 
-static void kvm__remove_pidfile(struct kvm *kvm)
+void kvm__remove_pidfile(const char *name)
 {
 	char full_name[PATH_MAX];
 
-	if (!kvm->name)
-		return;
-
-	sprintf(full_name, "%s/%s/%s.pid", HOME_DIR, KVM_PID_FILE_PATH, kvm->name);
+	sprintf(full_name, "%s/%s/%s.pid", HOME_DIR, KVM_PID_FILE_PATH, name);
 	unlink(full_name);
 }
 
@@ -194,7 +191,7 @@ void kvm__delete(struct kvm *kvm)
 	kvm__stop_timer(kvm);
 
 	munmap(kvm->ram_start, kvm->ram_size);
-	kvm__remove_pidfile(kvm);
+	kvm__remove_pidfile(kvm->name);
 	free(kvm);
 }
 
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] kvm tools: Clean ghost pid files in 'kvm list'
  2011-07-05  9:35 [PATCH 1/2] kvm tools: Export kvm__remove_pidfile Sasha Levin
@ 2011-07-05  9:35 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2011-07-05  9:35 UTC (permalink / raw)
  To: penberg; +Cc: mingo, asias.hejun, prasadjoshi124, gorcunov, kvm, Sasha Levin

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>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-05  9:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-05  9:35 [PATCH 1/2] kvm tools: Export kvm__remove_pidfile Sasha Levin
2011-07-05  9:35 ` [PATCH 2/2] kvm tools: Clean ghost pid files in 'kvm list' Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.