shell: Adjust arguments when executing a command of different module
The command callback might not recognize commands if the input comes with the module name as first parameter as both argc and argv will be off by one. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
417dc03aad
commit
81cc89189b
1 changed files with 17 additions and 9 deletions
|
@ -298,10 +298,9 @@ static int exit_module(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static shell_cmd_function_t get_cb(int argc, char *argv[])
|
static shell_cmd_function_t get_cb(int *argc, char *argv[], int *module)
|
||||||
{
|
{
|
||||||
const char *first_string = argv[0];
|
const char *first_string = argv[0];
|
||||||
int module = -1;
|
|
||||||
const struct shell_module *shell_module;
|
const struct shell_module *shell_module;
|
||||||
const char *command;
|
const char *command;
|
||||||
int i;
|
int i;
|
||||||
|
@ -323,17 +322,17 @@ static shell_cmd_function_t get_cb(int argc, char *argv[])
|
||||||
return exit_module;
|
return exit_module;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((argc == 1) && (default_module == -1)) {
|
if ((*argc == 1) && (default_module == -1)) {
|
||||||
printk("Missing parameter\n");
|
printk("Missing parameter\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
command = get_command_and_module(argv, &module);
|
command = get_command_and_module(argv, module);
|
||||||
if ((module == -1) || (command == NULL)) {
|
if ((*module == -1) || (command == NULL)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_module = &__shell_cmd_start[module];
|
shell_module = &__shell_cmd_start[*module];
|
||||||
for (i = 0; shell_module->commands[i].cmd_name; i++) {
|
for (i = 0; shell_module->commands[i].cmd_name; i++) {
|
||||||
if (!strcmp(command, shell_module->commands[i].cmd_name)) {
|
if (!strcmp(command, shell_module->commands[i].cmd_name)) {
|
||||||
return shell_module->commands[i].cb;
|
return shell_module->commands[i].cb;
|
||||||
|
@ -352,7 +351,8 @@ static inline void print_cmd_unknown(char *argv)
|
||||||
int shell_exec(char *line)
|
int shell_exec(char *line)
|
||||||
{
|
{
|
||||||
char *argv[ARGC_MAX + 1];
|
char *argv[ARGC_MAX + 1];
|
||||||
size_t argc;
|
int argc;
|
||||||
|
int module = default_module;
|
||||||
int err;
|
int err;
|
||||||
shell_cmd_function_t cb;
|
shell_cmd_function_t cb;
|
||||||
|
|
||||||
|
@ -361,7 +361,9 @@ int shell_exec(char *line)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cb = get_cb(argc, argv);
|
err = argc;
|
||||||
|
|
||||||
|
cb = get_cb(&argc, argv, &module);
|
||||||
if (!cb) {
|
if (!cb) {
|
||||||
if (app_cmd_handler != NULL) {
|
if (app_cmd_handler != NULL) {
|
||||||
cb = app_cmd_handler;
|
cb = app_cmd_handler;
|
||||||
|
@ -372,7 +374,13 @@ int shell_exec(char *line)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute callback with arguments */
|
/* Execute callback with arguments */
|
||||||
err = cb(argc, argv);
|
if (module != -1 && module != default_module) {
|
||||||
|
/* Ajust parameters to point to the actual command */
|
||||||
|
err = cb(argc - 1, &argv[1]);
|
||||||
|
} else {
|
||||||
|
err = cb(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
show_cmd_help(argv);
|
show_cmd_help(argv);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue