On Wed, Jul 26, 2017 at 11:31 AM, Ron Yorston <[email protected]> wrote:
> In standalone shell mode applets can be run from the shell without
> having to install symlinks to them. You don't even need to set PATH.
> Tab-completion also works. This makes minimal deployments of BusyBox
> very easy to set up. For example, a container can be created with just
> the BusyBox binary installed as /bin/sh.
>
> There's one exception: since 'busybox' isn't an applet it won't run
> in standalone shell mode without being installed on the path.
>
> This patch adds special treatment for 'busybox' in standalone shell
> mode so tab-completion and execution from the shell both work.
>
> function old new delta
> tryexec - 175 +175
> add_partial_match - 35 +35
> find_command 952 978 +26
> complete_cmd_dir_file 891 882 -9
> shellexec 498 316 -182
> ------------------------------------------------------------------------------
> (add/remove: 2/0 grow/shrink: 1/2 up/down: 236/-191) Total: 45 bytes
>
> These extra bytes are only required if standalone shell mode is enabled,
> which it isn't in the default configuration.
How about this instead?
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -763,8 +763,21 @@ static void install_links(const char *busybox UNUSED_PARAM,
# if ENABLE_BUSYBOX
static void run_applet_and_exit(const char *name, char **argv) NORETURN;
-/* If we were called as "busybox..." */
-static int busybox_main(char **argv)
+# if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION
+ /*
+ * Insert "busybox" into applet table as well.
+ * This makes standalone shell tab-complete it.
+ */
+//usage:#define busybox_trivial_usage NOUSAGE_STR
+//usage:#define busybox_full_usage ""
+//applet:IF_BUSYBOX(IF_FEATURE_SH_STANDALONE(APPLET(busybox,
BB_DIR_BIN, BB_SUID_MAYBE)))
+int busybox_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE;
+# else
+# define busybox_main(argc,argv) busybox_main(argv)
+static
+# endif
+/* If we were called as "busyboxANY_SUFFIX ..." */
+int busybox_main(int argc UNUSED_PARAM, char **argv)
{
if (!argv[1]) {
/* Called without arguments */
@@ -937,7 +950,7 @@ static NORETURN void run_applet_and_exit(const
char *name, char **argv)
{
# if ENABLE_BUSYBOX
if (is_prefixed_with(name, "busybox"))
- exit(busybox_main(argv));
+ exit(busybox_main(/*unused:*/ 0, argv));
# endif
# if NUM_APPLETS > 0
/* find_applet_by_name() search is more expensive, so goes second */
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox