shell: logging: Fix assertion when shell is overflowed with logging

When shell had too many pending log messages it was attempting to
drop expired messages and retrying to put the new message. There
was an assumption that enough messages are dropped and new message
can be put. It may not be the case if no message expired during
given time. Wrapped the operation in loop to continue until expired
message is freed and new message is enqueued.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2021-04-06 11:44:04 +02:00 committed by Carles Cufí
commit 9a85a89313

View file

@ -92,36 +92,37 @@ static void msg_to_fifo(const struct shell *shell,
struct log_msg *msg) struct log_msg *msg)
{ {
int err; int err;
bool cont;
struct shell_log_backend_msg t_msg = { struct shell_log_backend_msg t_msg = {
.msg = msg, .msg = msg,
.timestamp = k_uptime_get_32() .timestamp = k_uptime_get_32()
}; };
err = k_msgq_put(shell->log_backend->msgq, &t_msg, do {
K_MSEC(shell->log_backend->timeout)); cont = false;
err = k_msgq_put(shell->log_backend->msgq, &t_msg,
K_MSEC(shell->log_backend->timeout));
switch (err) { switch (err) {
case 0: case 0:
break; break;
case -EAGAIN: case -EAGAIN:
case -ENOMSG: case -ENOMSG:
{ {
flush_expired_messages(shell); /* Attempt to drop old message. */
flush_expired_messages(shell);
err = k_msgq_put(shell->log_backend->msgq, &msg, K_NO_WAIT); /* Retry putting message. */
if (err) { cont = true;
/* Unexpected case as we just freed one element and
* there is no other context that puts into the msgq. break;
*/
__ASSERT_NO_MSG(0);
} }
break; default:
} /* Other errors are not expected. */
default: __ASSERT_NO_MSG(0);
/* Other errors are not expected. */ break;
__ASSERT_NO_MSG(0); }
break; } while (cont);
}
} }
void z_shell_log_backend_disable(const struct shell_log_backend *backend) void z_shell_log_backend_disable(const struct shell_log_backend *backend)