From 60d8482348f6ed3bfadd7d9d8f450c1b2c3a5807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Thu, 10 Oct 2024 09:58:54 +0200 Subject: [PATCH] logging: log_cmds: Enable log commands for shell with the logging frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When shell is integrated with the logging frontend then pointer to the logging backend in the shell structure is null. When null pointer is found assume that it is a shell instance with logging frontend integration and use frontend in the logging commands. Signed-off-by: Krzysztof Chruściński --- subsys/logging/Kconfig.misc | 2 +- subsys/logging/log_cmds.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/subsys/logging/Kconfig.misc b/subsys/logging/Kconfig.misc index 1813623b56f..a9c90526e14 100644 --- a/subsys/logging/Kconfig.misc +++ b/subsys/logging/Kconfig.misc @@ -6,7 +6,7 @@ menu "Misc" config LOG_CMDS bool "Shell commands" depends on SHELL - depends on !LOG_FRONTEND_ONLY && !LOG_MODE_MINIMAL + depends on !LOG_MODE_MINIMAL config LOG_TEST_CLEAR_MESSAGE_SPACE bool "Clear message after allocation" diff --git a/subsys/logging/log_cmds.c b/subsys/logging/log_cmds.c index 79e4457184f..fd7997a84bd 100644 --- a/subsys/logging/log_cmds.c +++ b/subsys/logging/log_cmds.c @@ -58,8 +58,8 @@ static const struct log_backend *backend_find(char const *name) static bool shell_state_precheck(const struct shell *sh) { - if (sh->log_backend->control_block->state - == SHELL_LOG_BACKEND_UNINIT) { + if (sh->log_backend && + (sh->log_backend->control_block->state == SHELL_LOG_BACKEND_UNINIT)) { shell_error(sh, "Shell log backend not initialized."); return false; } @@ -142,8 +142,7 @@ static int cmd_log_self_status(const struct shell *sh, return 0; } - log_status(sh, sh->log_backend->backend, argc, argv); - return 0; + return log_status(sh, sh->log_backend ? sh->log_backend->backend : NULL, argc, argv); } static int cmd_log_backend_status(const struct shell *sh, @@ -246,7 +245,7 @@ static int cmd_log_self_enable(const struct shell *sh, return 0; } - return log_enable(sh, sh->log_backend->backend, argc, argv); + return log_enable(sh, sh->log_backend ? sh->log_backend->backend : NULL, argc, argv); } static int cmd_log_backend_enable(const struct shell *sh, @@ -271,7 +270,7 @@ static int cmd_log_self_disable(const struct shell *sh, return 0; } - return log_disable(sh, sh->log_backend->backend, argc, argv); + return log_disable(sh, sh->log_backend ? sh->log_backend->backend : NULL, argc, argv); } static int cmd_log_backend_disable(const struct shell *sh, @@ -327,7 +326,7 @@ static int cmd_log_self_halt(const struct shell *sh, return 0; } - return log_halt(sh, sh->log_backend->backend, argc, argv); + return log_halt(sh, sh->log_backend ? sh->log_backend->backend : NULL, argc, argv); } static int cmd_log_backend_halt(const struct shell *sh, @@ -359,7 +358,7 @@ static int cmd_log_self_go(const struct shell *sh, return 0; } - return log_go(sh, sh->log_backend->backend, argc, argv); + return log_go(sh, sh->log_backend ? sh->log_backend->backend : NULL, argc, argv); } static int cmd_log_backend_go(const struct shell *sh,