This is an automated email from the ASF dual-hosted git repository.
kasjer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 53ed93aa4 shell: Fix static command registration
53ed93aa4 is described below
commit 53ed93aa4f874675e2df546ef5e6118109f3db09
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Wed Jun 17 13:30:52 2026 +0200
shell: Fix static command registration
Command registered to module via link table
created variable that did not include module
name. This resulted in name collision if
second module tried to make command with same
name.
Collision would happen in following case:
SHELL_MODULE_CMD(module1, test, cmd1, NULL);
SHELL_MODULE_CMD(module2, test, cmd2, NULL);
While two modules do have different name, same command
name would not build.
Now internal variable that is created has module embedded
to prevent collision.
Adjustment in shell.c for compat command is applied.
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
sys/shell/include/shell/shell.h | 15 ++++++++-------
sys/shell/src/shell.c | 7 ++++---
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/sys/shell/include/shell/shell.h b/sys/shell/include/shell/shell.h
index 691489b16..9b572f796 100644
--- a/sys/shell/include/shell/shell.h
+++ b/sys/shell/include/shell/shell.h
@@ -210,13 +210,14 @@ LINK_TABLE(shell_mod_t, shell_modules)
* @param func_ - function to execute
* @param help_ - help structure for function
*/
-#define SHELL_MODULE_CMD_WITH_NAME(mod_, cmd_, name_, ext_, func_, help_)
\
- const struct shell_cmd shell_cmd_##cmd_ SHELL_MODULE_CMD_SECTION(mod_,
cmd_) = { \
- .sc_ext = ext_,
\
- .sc_cmd_ext_func = (shell_cmd_ext_func_t)(func_),
\
- .sc_cmd = name_,
\
- .help = SHELL_HELP_(help_),
\
- };
+#define SHELL_MODULE_CMD_WITH_NAME(mod_, cmd_, name_, ext_, func_, help_) \
+ const struct shell_cmd SHELL_MODULE_CMD_SECTION(mod_, cmd_) \
+ shell_cmd_##mod_##_##cmd_ = { \
+ .sc_ext = ext_, \
+ .sc_cmd_ext_func = (shell_cmd_ext_func_t)(func_), \
+ .sc_cmd = name_, \
+ .help = SHELL_HELP_(help_), \
+ };
/**
* Create command for module
diff --git a/sys/shell/src/shell.c b/sys/shell/src/shell.c
index 358875f78..476b58669 100644
--- a/sys/shell/src/shell.c
+++ b/sys/shell/src/shell.c
@@ -448,11 +448,11 @@ shell_find_cmd(int argc, char *argv[], struct streamer
*streamer)
}
if (!strcmp(first_string, "help")) {
- return &shell_cmd_help;
+ return &shell_cmd_compat_help;
}
if (!strcmp(first_string, "select")) {
- return &shell_cmd_select;
+ return &shell_cmd_compat_select;
}
if ((argc == 1) && (def_module == NULL)) {
@@ -501,7 +501,8 @@ shell_exec(int argc, char **argv, struct streamer *streamer)
/* Allow invoking a cmd with module name as a prefix; a command should
* not know how it was invoked (with or without prefix)
*/
- if (def_module == NULL && cmd != &shell_cmd_select && cmd !=
&shell_cmd_help) {
+ if (def_module == NULL && cmd != &shell_cmd_compat_select &&
+ cmd != &shell_cmd_compat_help) {
argc_offset = 1;
}