Commit-ID: 180948d2e9a80502a5104713bd17d131878b7d2f Gitweb: http://git.kernel.org/tip/180948d2e9a80502a5104713bd17d131878b7d2f Author: Sasha Levin <levinsasha928@xxxxxxxxx> AuthorDate: Tue, 9 Aug 2011 13:17:39 +0300 Committer: Pekka Enberg <penberg@xxxxxxxxxx> CommitDate: Tue, 9 Aug 2011 16:51:07 +0300 kvm tools: Change method of retrieving process name This patch changes './kvm list' to retrieve process name from '/proc/<pid>/stat' instead of '/proc/<pid>/comm' as it appears the latter does not exist by default on several systems. Reported-by: Pradeep Kumar Surisetty <psuriset@xxxxxxxxxxxxxxxxxx> Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx> --- 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); } -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html
![]() |