[PATCH 3/3] Do not set $0 in functions

Samuel Mendoza-Jonas sam at mendozajonas.com
Tue Apr 26 13:05:37 AEST 2016


Thanks! Merged with a slight title change as c5cbcf4.

On Wed, Mar 02, 2016 at 08:59:04AM -0800, Alan Dunn wrote:
> GRUB2 does not set $0 in functions, so don't set it in our GRUB2
> script parser.  (As it doesn't have a value in GRUB2 scripts, probably
> no GRUB2 script depends on the value of $0.)  Additionally, dash and
> bash set environment variable 0 to the name of the script (even in
> functions), so the current behavior of $0 doesn't really match shell
> scripts either.
> 
> Tested:
>  Existing tests pass.
> 
> Signed-off-by: Alan Dunn <amdunn at google.com>
> ---
>  discover/grub2/script.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/discover/grub2/script.c b/discover/grub2/script.c
> index 48c963e..ed81a20 100644
> --- a/discover/grub2/script.c
> +++ b/discover/grub2/script.c
> @@ -379,7 +379,7 @@ static int function_invoke(struct grub2_script *script,
>  	int i;
>  
>  	/* set positional parameters */
> -	for (i = 0; i < argc; i++) {
> +	for (i = 1; i < argc; i++) {
>  		name = talloc_asprintf(script, "%d", i);
>  		script_env_set(script, name, argv[i]);
>  	}
> -- 
> 2.7.0.rc3.207.g0ac5344
> 
> _______________________________________________
> Petitboot mailing list
> Petitboot at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/petitboot



More information about the Petitboot mailing list