xref: /kvmtool/builtin-pause.c (revision c9cba7910f52a48ecc99c9976bab69883aa3ef58)
1 #include <stdio.h>
2 #include <string.h>
3 #include <signal.h>
4 
5 #include <kvm/util.h>
6 #include <kvm/kvm-cmd.h>
7 #include <kvm/builtin-pause.h>
8 #include <kvm/kvm.h>
9 #include <kvm/parse-options.h>
10 
11 static const char * const pause_usage[] = {
12 	"kvm pause <instance name>",
13 	NULL
14 };
15 
16 static const struct option pause_options[] = {
17 	OPT_END()
18 };
19 
20 static int do_pause(const char *name, int pid)
21 {
22 	return kill(pid, SIGUSR2);
23 }
24 
25 int kvm_cmd_pause(int argc, const char **argv, const char *prefix)
26 {
27 	int pid;
28 
29 	if (argc != 1)
30 		usage_with_options(pause_usage, pause_options);
31 
32 	if (strcmp(argv[0], "all") == 0) {
33 		return kvm__enumerate_instances(do_pause);
34 	}
35 
36 	pid = kvm__get_pid_by_instance(argv[0]);
37 	if (pid < 0)
38 		die("Failed locating instance name");
39 
40 	return kill(pid, SIGUSR2);
41 }
42