[PATCH 4/5] dmesg: implement dmesg -n

Sascha Hauer s.hauer at pengutronix.de
Mon Jun 12 23:54:07 PDT 2023


On Tue, Jun 13, 2023 at 08:45:18AM +0200, Marco Felsch wrote:
> Hi Sascha,
> 
> On 23-06-12, Sascha Hauer wrote:
> > Under Linux dmesg -n can be used to set the console loglevel. Implement
> > the same for barebox.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  commands/dmesg.c | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/commands/dmesg.c b/commands/dmesg.c
> > index 00e5a159e0..953bdb2068 100644
> > --- a/commands/dmesg.c
> > +++ b/commands/dmesg.c
> > @@ -77,8 +77,9 @@ static int do_dmesg(int argc, char *argv[])
> >  	int opt, i;
> >  	int delete_buf = 0, emit = 0;
> >  	unsigned flags = 0, levels = 0;
> > +	char *set = NULL;
> >  
> > -	while ((opt = getopt(argc, argv, "ctderl:")) > 0) {
> > +	while ((opt = getopt(argc, argv, "ctderl:n:")) > 0) {
> >  		switch (opt) {
> >  		case 'c':
> >  			delete_buf = 1;
> > @@ -100,11 +101,25 @@ static int do_dmesg(int argc, char *argv[])
> >  		case 'r':
> >  			flags |= BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME;
> >  			break;
> > +		case 'n':
> > +			set = optarg;
> > +			break;
> >  		default:
> >  			return COMMAND_ERROR_USAGE;
> >  		}
> >  	}
> >  
> > +	if (set) {
> > +		int level = str_to_loglevel(set);
> > +
> > +		if (level < 0)
> > +			return COMMAND_ERROR;
> > +
> > +		barebox_loglevel = level;
> 
> Not really realted to this patch, but should we make 'barebox_loglevel'
> private and use a setter like console_set_loglevel()? Asking because
> console_common.c is the currently the only upstream user.

I asked myself the same question and would likely write it with a setter
nowadays, but I was too lazy to change it ;)

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