2 #include <kvm/kvm-cmd.h>
3 #include <kvm/builtin-stop.h>
5 #include <kvm/parse-options.h>
12 static pid_t instance_pid
;
13 static const char *instance_name
;
15 static const char * const stop_usage
[] = {
16 "kvm stop [--all] [-n name] [-p pid]",
20 static const struct option stop_options
[] = {
21 OPT_GROUP("General options:"),
22 OPT_BOOLEAN('a', "all", &all
, "Stop all instances"),
23 OPT_STRING('n', "name", &instance_name
, "name", "Instance name"),
24 OPT_INTEGER('p', "pid", &instance_pid
, "Instance pid"),
28 static void parse_stop_options(int argc
, const char **argv
)
31 argc
= parse_options(argc
, argv
, stop_options
, stop_usage
,
32 PARSE_OPT_STOP_AT_NON_OPTION
);
38 void kvm_stop_help(void)
40 usage_with_options(stop_usage
, stop_options
);
43 static int do_stop(const char *name
, int pid
)
45 return kill(pid
, SIGKVMSTOP
);
48 int kvm_cmd_stop(int argc
, const char **argv
, const char *prefix
)
50 parse_stop_options(argc
, argv
);
53 return kvm__enumerate_instances(do_stop
);
55 if (instance_name
== NULL
&&
60 instance_pid
= kvm__get_pid_by_instance(instance_name
);
62 if (instance_pid
<= 0)
63 die("Failed locating instance");
65 return kill(instance_pid
, SIGKVMSTOP
);