[BusyBox] Re: overriding builtins

Erik Andersen andersen at lineo.com
Fri Nov 17 18:23:28 UTC 2000


On Fri Nov 17, 2000 at 09:30:51AM -0800, Larry Doolittle wrote:
> Someone could add a "command" builtin if they like.
> I don't see an urgent need.  Although POSIX conformance
> is nice, there are lots more important features to add,
> like real variable expansion.
> 
> All the recent posts got sidetracked by an error of
> mine in the subject line: I'm not really talking about
> "builtin" functions (bg, cd, exec, ...).  Rather, the
> concern is for "applets" (ar, basename, cat, chgrp, ...).
> 
> Here is my (tested) one-liner that makes busybox-0.47
> sh act the way _I_ expect.
> 
>       - Larry Doolittle   <LRDoolittle at lbl.gov>
> 
> --- busybox-0.47/sh.c	Mon Sep 25 14:42:27 2000
> +++ busybox-0.47-lrd/sh.c	Fri Nov 17 09:20:34 2000
> @@ -1203,9 +1203,16 @@
>  				}
>  			}
>  #ifdef BB_FEATURE_SH_STANDALONE_SHELL
> -			/* Check if the command matches any busybox internal commands here */
> +			/* Check if the command matches any busybox internal commands ("applets") here.
> +			 * Following discussions from November 2000 on busybox at busybox.net,
> +			 * don't use get_last_path_component().  This way explicit (with slashes)
> +			 * filenames will never be interpreted as an applet, just like with builtins.
> +			 * This way the user can override an applet with an explicit filename reference.
> +			 * The only downside to this change is that an explicit /bin/foo invocation
> +			 * fill fork and exec /bin/foo, even if /bin/foo is a symlink to busybox.
> +			 */
>  			while (a->name != 0) {
> -				if (strcmp(get_last_path_component(newJob->progs[i].argv[0]), a->name) == 0) {
> +				if (strcmp(newJob->progs[i].argv[0], a->name) == 0) {
>  					int argc_l;
>  					char** argv=newJob->progs[i].argv;
>  					for(argc_l=0;*argv!=NULL; argv++, argc_l++);

Lets do this.  I think this is probably the correct default behavior.  However,
there are cases where the previous behavior is also desirable, so what I will
do is apply your patch, but add in a new feature to let folks decide what they want:

    //When this is enabled, busybox shell builtins can be called using full path
    //names.  This causes builtins (i.e. every single busybox command) to override
    //real commands on the filesystem.  For example, if you run run /bin/cat, it
    //will use BusyBox cat even if /bin/cat exists on the filesystem and is _not_
    //busybox.  Some systems want this, others do not.  Choose wisely.  :-) This
    //only has meaning when BB_FEATURE_SH_STANDALONE_SHELL is enabled.
    //BB_FEATURE_SH_BUILTINS_ALWAYS_WIN

Another good thing about your patch -- it just reminded me that busybox shell
is still doing O(n) { strcmp() } junk to match applets.  We fixed this in
busybox.c to use a binary search, but forgot to propagate the binary search to
the shell.  So your patch is about to indirectly cause busybox sh to become a
lot faster... :-)

 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--





More information about the busybox mailing list