From patchwork Tue Aug 9 10:17:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1048862 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 p79AIA4V010211 for ; Tue, 9 Aug 2011 10:18:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753224Ab1HIKSH (ORCPT ); Tue, 9 Aug 2011 06:18:07 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:42842 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753114Ab1HIKSG (ORCPT ); Tue, 9 Aug 2011 06:18:06 -0400 Received: by wyg24 with SMTP id 24so245829wyg.19 for ; Tue, 09 Aug 2011 03:18:05 -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; bh=d+FUL9zLTxR20HJ0ZkTZ+eWCPmtVFpxVhEDHNA8ed0Q=; b=EcRCrH1F0JipNv90Fp1eG0vSRb6U4/dfNt4jDjt7Y1Tyk6Kgu8MjZfJGOWhP9zXR6j j3dRBvcapn62RqOMr2ZUFIw/62/c+GUv9+kp8ec5BDyIfvl31FXKp4hT+NfC9QeJHhm8 Cjfz5xSjHpC+t9eZfx6mfWJ7lFs5SfNOz32WU= Received: by 10.227.24.131 with SMTP id v3mr5421714wbb.11.1312885085405; Tue, 09 Aug 2011 03:18:05 -0700 (PDT) Received: from localhost.localdomain ([31.210.178.149]) by mx.google.com with ESMTPS id o19sm5186855wbh.60.2011.08.09.03.18.02 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 09 Aug 2011 03:18:04 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: psuriset@linux.vnet.ibm.com, mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH] kvm tools: Change method of retrieving process name Date: Tue, 9 Aug 2011 13:17:39 +0300 Message-Id: <1312885059-842-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 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, 09 Aug 2011 10:18:10 +0000 (UTC) This patch changes './kvm list' to retrieve process name from '/proc//stat' instead of '/proc//comm' as it appears the latter does not exist by default on several systems. Reported-by: pradeep Signed-off-by: Sasha Levin --- tools/kvm/builtin-list.c | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c index 2d37ecb..89a0465 100644 --- a/tools/kvm/builtin-list.c +++ b/tools/kvm/builtin-list.c @@ -13,25 +13,32 @@ static void print_guest(const char *name, int pid) { char proc_name[PATH_MAX]; - char comm[sizeof(PROCESS_NAME)]; - int fd; + char *comm = NULL; + FILE *fd; - sprintf(proc_name, "/proc/%d/comm", pid); - fd = open(proc_name, O_RDONLY); - if (fd <= 0) + sprintf(proc_name, "/proc/%d/stat", pid); + fd = fopen(proc_name, "r"); + if (fd == NULL) goto cleanup; - if (read(fd, comm, sizeof(PROCESS_NAME)) == 0) + if (fscanf(fd, "%*u (%as)", &comm) == 0) goto cleanup; if (strncmp(comm, PROCESS_NAME, strlen(PROCESS_NAME))) goto cleanup; printf("%s (PID: %d)\n", name, pid); - close(fd); + free(comm); + + fclose(fd); return; cleanup: + if (fd) + fclose(fd); + if (comm) + free(comm); + kvm__remove_pidfile(name); }