7 /* user defined header files */
8 #include "kvm/builtin-debug.h"
9 #include "kvm/builtin-pause.h"
10 #include "kvm/builtin-resume.h"
11 #include "kvm/builtin-balloon.h"
12 #include "kvm/builtin-list.h"
13 #include "kvm/builtin-version.h"
14 #include "kvm/builtin-setup.h"
15 #include "kvm/builtin-stop.h"
16 #include "kvm/builtin-stat.h"
17 #include "kvm/builtin-help.h"
18 #include "kvm/kvm-cmd.h"
19 #include "kvm/builtin-run.h"
22 struct cmd_struct kvm_commands
[] = {
23 { "pause", kvm_cmd_pause
, kvm_pause_help
, 0 },
24 { "resume", kvm_cmd_resume
, kvm_resume_help
, 0 },
25 { "debug", kvm_cmd_debug
, kvm_debug_help
, 0 },
26 { "balloon", kvm_cmd_balloon
, kvm_balloon_help
, 0 },
27 { "list", kvm_cmd_list
, kvm_list_help
, 0 },
28 { "version", kvm_cmd_version
, NULL
, 0 },
29 { "--version", kvm_cmd_version
, NULL
, 0 },
30 { "stop", kvm_cmd_stop
, kvm_stop_help
, 0 },
31 { "stat", kvm_cmd_stat
, kvm_stat_help
, 0 },
32 { "help", kvm_cmd_help
, NULL
, 0 },
33 { "setup", kvm_cmd_setup
, kvm_setup_help
, 0 },
34 { "run", kvm_cmd_run
, kvm_run_help
, 0 },
35 { NULL
, NULL
, NULL
, 0 },
39 * kvm_get_command: Searches the command in an array of the commands and
40 * returns a pointer to cmd_struct if a match is found.
43 * command: Array of possible commands. The last entry in the array must be
45 * cmd: A string command to search in the array
48 * NULL: If the cmd is not matched with any of the command in the command array
49 * p: Pointer to cmd_struct of the matching command
51 struct cmd_struct
*kvm_get_command(struct cmd_struct
*command
,
54 struct cmd_struct
*p
= command
;
57 if (!strcmp(p
->cmd
, cmd
))
64 int handle_command(struct cmd_struct
*command
, int argc
, const char **argv
)
67 const char *prefix
= NULL
;
70 if (!argv
|| !*argv
) {
71 p
= kvm_get_command(command
, "help");
73 return p
->fn(argc
, argv
, prefix
);
76 p
= kvm_get_command(command
, argv
[0]);
78 p
= kvm_get_command(command
, "help");
80 p
->fn(0, NULL
, prefix
);
84 ret
= p
->fn(argc
- 1, &argv
[1], prefix
);
87 die("Permission error - are you root?");