From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Jonas Rebmann <jre@pengutronix.de>,
Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH] commands: dmesg: clear logbuffer fully if not requested otherwise
Date: Fri, 17 Oct 2025 13:17:55 +0200 [thread overview]
Message-ID: <06af30e5-077d-4a4c-95ce-b6abc0530b72@pengutronix.de> (raw)
In-Reply-To: <20251017-dmesg-v1-1-ac9c2fb021f6@pengutronix.de>
Hi,
On 10/17/25 1:04 PM, Jonas Rebmann wrote:
> Previously, `dmesg -c` would clear the logbuffer except for the last 10
> lines. This comes with a fair amount of surprise given linux `dmesg -c`
> clears the whole logbuffer.
>
> Clear the complete logbuffer given `dmesg -c` but with an optional
> argument `dmesg -c [<num>]` to keep <num> lines.
>
> While at it, move the deleteion of log lines to the log_print function
deletion
> to prevent a corner case of lost log message if they arrive between the
> log_print() and log_clean() in dmesg.
>
> If loglevels are selected using -l or -p in addition to cleaning being
> selected using -c, only clean those messages shown by the loglevel
> selection.
Given that this might break test suites, I think it warrants a short
addition to migration-2025.11.0.rst (create if needed).
>
> Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
> ---
> commands/dmesg.c | 17 ++++++++++-------
> common/console_common.c | 20 +++++++++++++++++---
> include/linux/printk.h | 2 +-
> 3 files changed, 28 insertions(+), 11 deletions(-)
>
> diff --git a/commands/dmesg.c b/commands/dmesg.c
> index a93ad5b359..6853f3afc9 100644
> --- a/commands/dmesg.c
> +++ b/commands/dmesg.c
> @@ -77,14 +77,20 @@ static unsigned dmesg_get_levels(const char *__args)
> static int do_dmesg(int argc, char *argv[])
> {
> int opt, ret, i;
> - int delete_buf = 0, emit = 0;
> + int delete_buf = -1, emit = 0;
just make it unsigned and use UINT_MAX?
delete_buf is no longer a good name for the variable IMO.
> unsigned flags = 0, levels = 0;
> char *set = NULL;
>
> - while ((opt = getopt(argc, argv, "ctderl:p:n:")) > 0) {
> + while ((opt = getopt(argc, argv, "c::tderl:p:n:")) > 0) {
> switch (opt) {
> case 'c':
> - delete_buf = 1;
> + if (optarg) {
> + ret = kstrtoint(optarg, 10, &delete_buf);
With type changed above, kstrtouint
> + if (ret || delete_buf < 0)
... which simplifies this condition.
> + return COMMAND_ERROR_USAGE;
> + } else {
> + delete_buf = 0;
You can initialize this right after case '0': and drop the else.
> + }
> break;
> case 't':
> flags |= BAREBOX_LOG_PRINT_TIME;
> @@ -155,13 +161,10 @@ static int do_dmesg(int argc, char *argv[])
> return 0;
> }
>
> - ret = log_print(flags, levels);
> + ret = log_print(flags, levels, delete_buf);
Not sure, we want to overload log_print with this.
How about we switch the ctrlc() to ctrlc_non_interruptible() and then we
are certain that there will be no messages coming in between as there
will be no resched() points (barebox multitasking is completely
cooperative).
> -int log_print(unsigned flags, unsigned levels)
> +/**
Thanks for adding docs :)
> + if (delete_buf >= 0 && barebox_logbuf_num_messages > delete_buf)
If delete_buf were unsigned, it would simplify the condition.
The variable name is suboptimal though, something with keep in it would
be better.
Cheers,
Ahmad
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2025-10-17 11:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 11:04 Jonas Rebmann
2025-10-17 11:17 ` Ahmad Fatoum [this message]
2025-10-20 9:36 ` Sascha Hauer
2025-10-20 12:36 ` Jonas Rebmann
2025-10-20 13:23 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=06af30e5-077d-4a4c-95ce-b6abc0530b72@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jre@pengutronix.de \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox