From patchwork Tue Jul 5 09:35:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 944092 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p659aIcR012523 for ; Tue, 5 Jul 2011 09:36:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754994Ab1GEJgO (ORCPT ); Tue, 5 Jul 2011 05:36:14 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=xBJ16vRDI56JsX6b1jr36vfqiIqh4eKLQRQFPojwuBw=; b=miQhbiNg6QSwLfIPMEP0uhfLYAkizXmkLc10Wut9HwTgqVEgKaImrjG4QBnU9ogVrA xquY5LB95Hd0XG3NQvW+0fBvOLhPsalE9zVtyrILpyT/ccrGFwiE/tCmyp4SAYE5sO9j OuVLuXD4VayaxgzZ3XWXXq61c9vovZjsVu+XA= Received: by 10.216.236.157 with SMTP id w29mr4708201weq.18.1309858567816; Tue, 05 Jul 2011 02:36:07 -0700 (PDT) Received: from localhost.localdomain ([31.210.184.221]) by mx.google.com with ESMTPS id e11sm2944792wbh.36.2011.07.05.02.36.06 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jul 2011 02:36:07 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, gorcunov@gmail.com, kvm@vger.kernel.org, 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> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1309858545-10344-1-git-send-email-levinsasha928@gmail.com> References: <1309858545-10344-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 05 Jul 2011 09:36:18 +0000 (UTC) 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)