mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2] common: add custom autoboot_abort_key
Date: Mon, 4 Nov 2024 12:55:18 +0100	[thread overview]
Message-ID: <Zyi2JpuQYAb_yHCW@pengutronix.de> (raw)
In-Reply-To: <20241102144342.2464331-1-johannes.schneider@leica-geosystems.com>

On Sat, Nov 02, 2024 at 03:43:42PM +0100, Johannes Schneider wrote:
> Extend the autoboot_abort_key handling to alow custom
> abort keys.
> 
> Allowed values to set in the env/nv/autoboot_abort_key
> are any single ascii charater corresponding to the desired keyboard
> key, or the strings 'any' or 'ctrl-c'
> 
> Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
> ---
>  common/startup.c | 53 ++++++++++++++++++++++++++++--------------------
>  1 file changed, 31 insertions(+), 22 deletions(-)
> 
> diff --git a/common/startup.c b/common/startup.c
> index 47b70a7..125bcf1 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -93,11 +93,7 @@ static int load_environment(void)
>  }
>  environment_initcall(load_environment);
>  
> -static int global_autoboot_abort_key;
> -static const char * const global_autoboot_abort_keys[] = {
> -	"any",
> -	"ctrl-c",
> -};
> +static char *global_autoboot_abort_key;
>  static int global_autoboot_timeout = 3;
>  
>  static const char * const global_autoboot_states[] = {
> @@ -187,24 +183,22 @@ enum autoboot_state do_autoboot_countdown(void)
>  	menu_exists = stat(MENUFILE, &s) == 0;
>  
>  	if (menu_exists) {
> -		printf("\nHit m for menu or %s to stop autoboot: ",
> -		       global_autoboot_abort_keys[global_autoboot_abort_key]);
>  		abortkeys = "m";
> -	} else {
> -		printf("\nHit %s to stop autoboot: ",
> -		       global_autoboot_abort_keys[global_autoboot_abort_key]);
>  	}
>  
> -	switch (global_autoboot_abort_key) {
> -	case 0:
> +	if (!global_autoboot_abort_key ||
> +	    !strcmp(global_autoboot_abort_key, "any"))
>  		flags |= CONSOLE_COUNTDOWN_ANYKEY;
> -		break;
> -	case 1:
> +	else if (!strcmp(global_autoboot_abort_key, "ctrl-c"))
>  		flags |= CONSOLE_COUNTDOWN_CTRLC;
> -		break;
> -	default:
> -		break;
> -	}
> +	else
> +		abortkeys = xasprintf("%s%s",
> +		                      (abortkeys)?abortkeys:"",
> +		                      global_autoboot_abort_key);

This memory is never freed. I converted it into a static array 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 |



  parent reply	other threads:[~2024-11-04 12:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-02 14:43 Johannes Schneider
2024-11-04 11:54 ` Sascha Hauer
2024-11-04 11:55 ` Sascha Hauer [this message]
2024-11-04 12:55   ` SCHNEIDER Johannes

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=Zyi2JpuQYAb_yHCW@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=johannes.schneider@leica-geosystems.com \
    /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