@@ -7,9 +7,9 @@
#include <string.h>
#include <signal.h>
-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]);
@@ -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);
}
@@ -7,9 +7,9 @@
#include <kvm/builtin-pause.h>
#include <kvm/kvm.h>
-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]);
@@ -7,9 +7,9 @@
#include <kvm/builtin-resume.h>
#include <kvm/kvm.h>
-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]);
@@ -7,9 +7,9 @@
#include <string.h>
#include <signal.h>
-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]);
@@ -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);
/*
@@ -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)
callback function maybe fail, so we should deal with the return value. Signed-off-by: Liming Wang <walimisdev@gmail.com> --- 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(-)