shell: fix log output when CONFIG_LOG_IMMEDIATE=y

With CONFIG_LOG_IMMEDIATE, log output is printed immediately.  If a
shell command is in progress, there's no prompt to erase, nor should
we print a new prompt after the log message is output.

Before this patch, a simple shell command like:

  int cmd_log_erase(const struct shell *shell, size_t argc, char **argv)
  {
          LOG_INF("hello world");
          return 0;
  }

would output something like:

  uart:~$ log erase
  [00:00:02.623,718] <inf> cmd_log: hello world
  uart:~$ loguart:~$

This patch fixes prompt handling while a command is active, and fixes
put_sync_hexdump to behave like put_sync_string.

Signed-off-by: Jim Paris <jim@jtan.com>
This commit is contained in:
Jim Paris 2019-08-07 15:50:22 -04:00 committed by Ioannis Glaropoulos
commit c7d6c310c6

View file

@ -222,10 +222,14 @@ static void put_sync_string(const struct log_backend *const backend,
}
key = irq_lock();
if (!flag_cmd_ctx_get(shell)) {
shell_cmd_line_erase(shell);
}
log_output_string(shell->log_backend->log_output, src_level, timestamp,
fmt, ap, flags);
if (!flag_cmd_ctx_get(shell)) {
shell_print_prompt_and_cmd(shell);
}
irq_unlock(key);
}
@ -234,7 +238,6 @@ static void put_sync_hexdump(const struct log_backend *const backend,
const char *metadata, const u8_t *data, u32_t length)
{
const struct shell *shell = (const struct shell *)backend->cb->ctx;
struct k_poll_signal *signal;
u32_t key;
u32_t flags = LOG_OUTPUT_FLAG_LEVEL |
LOG_OUTPUT_FLAG_TIMESTAMP |
@ -245,18 +248,15 @@ static void put_sync_hexdump(const struct log_backend *const backend,
}
key = irq_lock();
if (!flag_cmd_ctx_get(shell)) {
shell_cmd_line_erase(shell);
}
log_output_hexdump(shell->log_backend->log_output, src_level, timestamp,
metadata, data, length, flags);
irq_unlock(key);
/* Even though log message is handled notify shell thread which
* will print command buffer after the log message.
*/
if (IS_ENABLED(CONFIG_MULTITHREADING)) {
signal = &shell->ctx->signals[SHELL_SIGNAL_LOG_MSG];
k_poll_signal_raise(signal, 0);
if (!flag_cmd_ctx_get(shell)) {
shell_print_prompt_and_cmd(shell);
}
irq_unlock(key);
}
static void panic(const struct log_backend *const backend)