From patchwork Wed Aug 10 02:44:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: walimis X-Patchwork-Id: 1051592 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 p7A37UKr002076 for ; Wed, 10 Aug 2011 03:07:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753006Ab1HJDCK (ORCPT ); Tue, 9 Aug 2011 23:02:10 -0400 Received: from mail.windriver.com ([147.11.1.11]:54353 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752989Ab1HJDCI (ORCPT ); Tue, 9 Aug 2011 23:02:08 -0400 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca [147.11.189.40]) by mail.windriver.com (8.14.3/8.14.3) with ESMTP id p7A30GoN014071 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 9 Aug 2011 20:00:16 -0700 (PDT) Received: from localhost.localdomain (128.224.162.211) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.1.255.0; Tue, 9 Aug 2011 20:00:15 -0700 From: Liming Wang To: Pekka Enberg CC: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , Asias He , Subject: [PATCH 1/2] kvm tools: convert callback to int and deal with the return value Date: Wed, 10 Aug 2011 10:44:08 +0800 Message-ID: <1312944249-4946-1-git-send-email-walimisdev@gmail.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 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]); Wed, 10 Aug 2011 03:07:33 +0000 (UTC) callback function maybe fail, so we should deal with the return value. Signed-off-by: Liming Wang --- tools/kvm/builtin-debug.c | 7 +++---- tools/kvm/builtin-list.c | 9 ++++----- tools/kvm/builtin-pause.c | 7 +++---- tools/kvm/builtin-resume.c | 7 +++---- tools/kvm/builtin-stop.c | 7 +++---- tools/kvm/include/kvm/kvm.h | 2 +- tools/kvm/kvm.c | 9 ++++++--- 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c index 153badd..4cf3b7c 100644 --- a/tools/kvm/builtin-debug.c +++ b/tools/kvm/builtin-debug.c @@ -7,9 +7,9 @@ #include #include -static void do_debug(const char *name, int pid) +static int do_debug(const char *name, int pid) { - kill(pid, SIGQUIT); + return kill(pid, SIGQUIT); } int kvm_cmd_debug(int argc, const char **argv, const char *prefix) @@ -20,8 +20,7 @@ int kvm_cmd_debug(int argc, const char **argv, const char *prefix) die("Usage: kvm debug [instance name]\n"); if (strcmp(argv[0], "all") == 0) { - kvm__enumerate_instances(do_debug); - return 0; + return kvm__enumerate_instances(do_debug); } pid = kvm__get_pid_by_instance(argv[0]); diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c index 89a0465..43f37f2 100644 --- a/tools/kvm/builtin-list.c +++ b/tools/kvm/builtin-list.c @@ -10,7 +10,7 @@ #define PROCESS_NAME "kvm" -static void print_guest(const char *name, int pid) +static int print_guest(const char *name, int pid) { char proc_name[PATH_MAX]; char *comm = NULL; @@ -31,7 +31,7 @@ static void print_guest(const char *name, int pid) fclose(fd); - return; + return 0; cleanup: if (fd) @@ -40,11 +40,10 @@ cleanup: free(comm); kvm__remove_pidfile(name); + return 0; } int kvm_cmd_list(int argc, const char **argv, const char *prefix) { - kvm__enumerate_instances(print_guest); - - return 0; + return kvm__enumerate_instances(print_guest); } diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c index 827b3b4..f5805e6 100644 --- a/tools/kvm/builtin-pause.c +++ b/tools/kvm/builtin-pause.c @@ -7,9 +7,9 @@ #include #include -static void do_pause(const char *name, int pid) +static int do_pause(const char *name, int pid) { - kill(pid, SIGUSR2); + return kill(pid, SIGUSR2); } int kvm_cmd_pause(int argc, const char **argv, const char *prefix) @@ -20,8 +20,7 @@ int kvm_cmd_pause(int argc, const char **argv, const char *prefix) die("Usage: kvm pause [instance name]\n"); if (strcmp(argv[0], "all") == 0) { - kvm__enumerate_instances(do_pause); - return 0; + return kvm__enumerate_instances(do_pause); } pid = kvm__get_pid_by_instance(argv[0]); diff --git a/tools/kvm/builtin-resume.c b/tools/kvm/builtin-resume.c index 4a85918..a9bf6c5 100644 --- a/tools/kvm/builtin-resume.c +++ b/tools/kvm/builtin-resume.c @@ -7,9 +7,9 @@ #include #include -static void do_resume(const char *name, int pid) +static int do_resume(const char *name, int pid) { - kill(pid, SIGKVMRESUME); + return kill(pid, SIGKVMRESUME); } int kvm_cmd_resume(int argc, const char **argv, const char *prefix) @@ -20,8 +20,7 @@ int kvm_cmd_resume(int argc, const char **argv, const char *prefix) die("Usage: kvm resume [instance name]\n"); if (strcmp(argv[0], "all") == 0) { - kvm__enumerate_instances(do_resume); - return 0; + return kvm__enumerate_instances(do_resume); } pid = kvm__get_pid_by_instance(argv[0]); diff --git a/tools/kvm/builtin-stop.c b/tools/kvm/builtin-stop.c index 7dd2015..46be393 100644 --- a/tools/kvm/builtin-stop.c +++ b/tools/kvm/builtin-stop.c @@ -7,9 +7,9 @@ #include #include -static void do_stop(const char *name, int pid) +static int do_stop(const char *name, int pid) { - kill(pid, SIGKVMSTOP); + return kill(pid, SIGKVMSTOP); } int kvm_cmd_stop(int argc, const char **argv, const char *prefix) @@ -20,8 +20,7 @@ int kvm_cmd_stop(int argc, const char **argv, const char *prefix) die("Usage: kvm stop [instance name]\n"); if (strcmp(argv[0], "all") == 0) { - kvm__enumerate_instances(do_stop); - return 0; + return kvm__enumerate_instances(do_stop); } pid = kvm__get_pid_by_instance(argv[0]); diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 4f12d11..1cbe3c7 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -72,7 +72,7 @@ void kvm__pause(void); 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)); +int kvm__enumerate_instances(int (*callback)(const char *name, int pid)); void kvm__remove_pidfile(const char *name); /* diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 107a922..740851d 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -164,12 +164,13 @@ int kvm__get_pid_by_instance(const char *name) return pid; } -int kvm__enumerate_instances(void (*callback)(const char *name, int pid)) +int kvm__enumerate_instances(int (*callback)(const char *name, int pid)) { char full_name[PATH_MAX]; int pid; DIR *dir; struct dirent entry, *result; + int ret = 0; sprintf(full_name, "%s/%s", HOME_DIR, KVM_PID_FILE_PATH); dir = opendir(full_name); @@ -181,13 +182,15 @@ int kvm__enumerate_instances(void (*callback)(const char *name, int pid)) if (entry.d_type == DT_REG) { entry.d_name[strlen(entry.d_name)-4] = 0; pid = kvm__get_pid_by_instance(entry.d_name); - callback(entry.d_name, pid); + ret = callback(entry.d_name, pid); + if (ret < 0) + break; } } closedir(dir); - return 0; + return ret; } void kvm__delete(struct kvm *kvm)