From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1WmK1n-0000b8-7f for mharc-grub-devel@gnu.org; Mon, 19 May 2014 05:38:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmK1d-0000Tu-2j for grub-devel@gnu.org; Mon, 19 May 2014 05:38:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WmK1R-0001hf-A5 for grub-devel@gnu.org; Mon, 19 May 2014 05:38:29 -0400 Received: from mail-we0-x235.google.com ([2a00:1450:400c:c03::235]:58567) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmK1Q-0001hM-T7 for grub-devel@gnu.org; Mon, 19 May 2014 05:38:17 -0400 Received: by mail-we0-f181.google.com with SMTP id w61so5119346wes.40 for ; Mon, 19 May 2014 02:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=gj6Xk+mAA2qiwQiF8q1865ynkcwJYENzdhv5A0wvvOQ=; b=RP+bsCvX3Xx6MyDrvXj/7nx1GTtifz3+AFPb8823LXvp3HmCiS3EtD/xUUp0CNmNRR 5KnT8MegBlkGrNLIiEQO+fWE6EIzsJgo7cjciqp+6jdYFbA7AC10ZdpOUKEeVMhQUW9s v3ZTGAQGoR5O2dQXH/Fka9njAYr+fZ1XFVcvl1PjEMSlagPyqL9NDtfZJKq9If26DyPs NwdJf0y4MPbzvLNFwWYwqc/O4WG+i7xJqz4nzKhumAxCMcB6fWF0G6KqYLlxyz4xKNjG +HgKjnh3n3213x4MzkpU5r3GcOn3Ko2Hi5s2RAGWZRqtrpSBHlVX7crHg8G7GRZNd6os agUg== X-Received: by 10.180.90.132 with SMTP id bw4mr11923715wib.43.1400492295206; Mon, 19 May 2014 02:38:15 -0700 (PDT) Received: from [192.168.1.100] (ANice-653-1-540-29.w86-205.abo.wanadoo.fr. [86.205.248.29]) by mx.google.com with ESMTPSA id gt4sm14097961wib.11.2014.05.19.02.38.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 May 2014 02:38:14 -0700 (PDT) Message-ID: <5379D105.7070904@gmail.com> Date: Mon, 19 May 2014 11:38:13 +0200 From: Michel Hermier User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: [PATCH] Allow user-defined functions to override builtins. References: <20140519013715.1e36d215@crass-Ideapad-Z570> In-Reply-To: <20140519013715.1e36d215@crass-Ideapad-Z570> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::235 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 May 2014 09:38:38 -0000 Le 19/05/2014 08:37, Glenn Washburn a écrit : > Currently, builtin commands take precedence over user-defined > functions. This patch reverses that precedence, so that users can > "override" builtin commands. Builtin commands may be accessed by > issuing the command prefixed by an '@' character. If you want to go this way, I would have preferred a 'builtin' command like other shell do, instead of reinventing the wheel and invent a new syntax. But this only my opinion as a user, wait for developers opinion. > > My motivation for this change is to hook insmod in loaded configfiles > which set $prefix to a different location than desired. If there are > any changes needed to help get this functionality included, please let > me know. > > Glenn > > --- > grub-core/script/execute.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c > index afd5513..0769151 100644 > --- a/grub-core/script/execute.c > +++ b/grub-core/script/execute.c > @@ -941,14 +941,15 @@ grub_script_execute_cmdline (struct > grub_script_cmd *cmd) args = argv.args + 2; > cmdname = argv.args[1]; > } > - grubcmd = grub_command_find (cmdname); > - if (! grubcmd) > + /* Allow user functions to override built in commands. */ > + func = grub_script_function_find (cmdname); > + if (! func) > { > grub_errno = GRUB_ERR_NONE; > > - /* It's not a GRUB command, try all functions. */ > - func = grub_script_function_find (cmdname); > - if (! func) > + /* It's not a function, check if GRUB command. */ > + grubcmd = grub_command_find ((cmdname[0] == > '@')?(cmdname+1):cmdname); > + if (! grubcmd) > { > /* As a last resort, try if it is an assignment. */ > char *assign = grub_strdup (cmdname); > @@ -977,7 +978,9 @@ grub_script_execute_cmdline (struct grub_script_cmd > *cmd) } > > /* Execute the GRUB command or function. */ > - if (grubcmd) > + if (func) > + ret = grub_script_function_call (func, argc, args); > + else > { > if (grub_extractor_level && !(grubcmd->flags > & GRUB_COMMAND_FLAG_EXTRACTOR)) > @@ -990,8 +993,6 @@ grub_script_execute_cmdline (struct grub_script_cmd > *cmd) else > ret = (grubcmd->func) (grubcmd, argc, args); > } > - else > - ret = grub_script_function_call (func, argc, args); > > if (invert) > {