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-stop.h"
15 #include "kvm/builtin-help.h"
16 #include "kvm/kvm-cmd.h"
17 #include "kvm/builtin-run.h"
20 struct cmd_struct kvm_commands
[] = {
21 { "pause", kvm_cmd_pause
, NULL
, 0 },
22 { "resume", kvm_cmd_resume
, NULL
, 0 },
23 { "debug", kvm_cmd_debug
, NULL
, 0 },
24 { "balloon", kvm_cmd_balloon
, NULL
, 0 },
25 { "list", kvm_cmd_list
, NULL
, 0 },
26 { "version", kvm_cmd_version
, NULL
, 0 },
27 { "stop", kvm_cmd_stop
, NULL
, 0 },
28 { "help", kvm_cmd_help
, NULL
, 0 },
29 { "run", kvm_cmd_run
, kvm_run_help
, 0 },
30 { NULL
, NULL
, NULL
, 0 },
34 * kvm_get_command: Searches the command in an array of the commands and
35 * returns a pointer to cmd_struct if a match is found.
38 * command: Array of possible commands. The last entry in the array must be
40 * cmd: A string command to search in the array
43 * NULL: If the cmd is not matched with any of the command in the command array
44 * p: Pointer to cmd_struct of the matching command
46 struct cmd_struct
*kvm_get_command(struct cmd_struct
*command
,
49 struct cmd_struct
*p
= command
;
52 if (!strcmp(p
->cmd
, cmd
))
59 int handle_command(struct cmd_struct
*command
, int argc
, const char **argv
)
62 const char *prefix
= NULL
;
65 if (!argv
|| !*argv
) {
66 p
= kvm_get_command(command
, "help");
68 return p
->fn(argc
, argv
, prefix
);
71 p
= kvm_get_command(command
, argv
[0]);
73 p
= kvm_get_command(command
, "help");
75 p
->fn(0, NULL
, prefix
);
79 ret
= p
->fn(argc
- 1, &argv
[1], prefix
);
82 die("Permission error - are you root?");