From: Sasha Levin Subject: [PATCH 2/2] kvm tools: Clean ghost pid files in 'kvm list' Date: Tue, 5 Jul 2011 12:35:45 +0300 Message-ID: <1309858545-10344-2-git-send-email-levinsasha928@gmail.com> References: <1309858545-10344-1-git-send-email-levinsasha928@gmail.com> Cc: mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin To: penberg@kernel.org Return-path: Received: from mail-ww0-f44.google.com ([74.125.82.44]:39543 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754763Ab1GEJgJ (ORCPT ); Tue, 5 Jul 2011 05:36:09 -0400 Received: by wwe5 with SMTP id 5so5747207wwe.1 for ; Tue, 05 Jul 2011 02:36:07 -0700 (PDT) In-Reply-To: <1309858545-10344-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: When running 'kvm list', first make sure that the guest process is up and running before printing the entry. Signed-off-by: Sasha Levin --- 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 #include #include +#include + +#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