[PATCH v2] commands: dmesg: clear logbuffer fully if not requested otherwise
Sascha Hauer
s.hauer at pengutronix.de
Mon Nov 3 00:51:41 PST 2025
On Wed, Oct 29, 2025 at 02:18:27PM +0100, 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, add documentation for log_print(), and switch it from
> ctrlc() to ctrlc_non_interruptible(). This ensures that the complete
> execution of the dmesg command has no resched() point so that no other
> thread can intermittently modify the logbuffer, and that no message
> could arrive from another thread during log_print() and be interleaved
> with the dmesg output.
>
> If loglevels are selected using -l or -p in addition to clearing being
> selected using -c, then messages of any loglevel are cleared.
>
> Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
> ---
> Changes in v2:
> - Switch from ctrlc() to ctrlc_non_interruptible() instead of clearing
> in log_print() (Thanks, Ahmad)
> - Improve documentation
> - Always clear all loglevels regardless of -l/-p (Thanks, Sascha)
> - Style improvements (Thanks, Ahmad)
> - Link to v1: https://lore.barebox.org/barebox/20251017-dmesg-v1-1-ac9c2fb021f6@pengutronix.de
> ---
> .../migration-guides/migration-2025.11.0.rst | 9 ++++++++
> commands/dmesg.c | 25 ++++++++++++----------
> common/console_common.c | 12 ++++++++++-
> 3 files changed, 34 insertions(+), 12 deletions(-)
>
> diff --git a/Documentation/migration-guides/migration-2025.11.0.rst b/Documentation/migration-guides/migration-2025.11.0.rst
> index a9c7abb66e..2649923bbc 100644
> --- a/Documentation/migration-guides/migration-2025.11.0.rst
> +++ b/Documentation/migration-guides/migration-2025.11.0.rst
> @@ -18,3 +18,12 @@ Karo TX6X
> The barebox update handler for this SoM no longer unconditionally updates
> /dev/mmc3.boot0, but instead it now updates the inactive boot partition
> on /dev/mmc3 and then sets it as active allowing for power-fail safety.
> +
> +Shell
> +-----
> +
> +* An optional parameter was added to the `-c` option of `dmesg` allowing
> + configuration of the number of lines to remain in the log buffer after
> + clearing. When no parameter is provided to `-c`, zero is assumed, and no
> + lines are retained. Earlier versions always left 10 lines of logs remain in
> + the log buffer.
Moved this to the migration guide for v2025.12.0. while applying.
Sascha
--
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 |
More information about the barebox
mailing list