diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-25 18:25:24 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-25 18:25:24 +0000 |
| commit | 737d131e5e7a795ef771f987d7b02cbf4fa670d6 (patch) | |
| tree | 0a7acc833d9ee4fa873ec4c15ff60b692bef420e | |
| parent | 52226771760063acdc89ef4f8e531b595ae4232b (diff) | |
| download | busybox-w32-737d131e5e7a795ef771f987d7b02cbf4fa670d6.tar.gz busybox-w32-737d131e5e7a795ef771f987d7b02cbf4fa670d6.tar.bz2 busybox-w32-737d131e5e7a795ef771f987d7b02cbf4fa670d6.zip | |
support "#!/bin/busybox"-style wrappers. Needed for SELinux.
Patch by Yuichi Nakamura <ynakam@hitachisoft.jp>
| -rw-r--r-- | Config.in | 29 | ||||
| -rw-r--r-- | Makefile.custom | 11 | ||||
| -rw-r--r-- | applets/applets.c | 7 | ||||
| -rwxr-xr-x | applets/install.sh | 82 | ||||
| -rw-r--r-- | libbb/getopt32.c | 2 |
5 files changed, 94 insertions, 37 deletions
| @@ -465,6 +465,11 @@ config INSTALL_APPLET_HARDLINKS | |||
| 465 | Install applets as hard-links to the busybox binary. This might count | 465 | Install applets as hard-links to the busybox binary. This might count |
| 466 | on a filesystem with few inodes. | 466 | on a filesystem with few inodes. |
| 467 | 467 | ||
| 468 | config INSTALL_APPLET_SCRIPT_WRAPPERS | ||
| 469 | bool "as script wrappers" | ||
| 470 | help | ||
| 471 | Install applets as script wrappers that call the busybox binary. | ||
| 472 | |||
| 468 | config INSTALL_APPLET_DONT | 473 | config INSTALL_APPLET_DONT |
| 469 | bool "not installed" | 474 | bool "not installed" |
| 470 | depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS | 475 | depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS |
| @@ -474,6 +479,30 @@ config INSTALL_APPLET_DONT | |||
| 474 | 479 | ||
| 475 | endchoice | 480 | endchoice |
| 476 | 481 | ||
| 482 | choice | ||
| 483 | prompt "/bin/sh applet link" | ||
| 484 | default INSTALL_SH_APPLET_SYMLINK | ||
| 485 | depends on INSTALL_APPLET_SCRIPT_WRAPPERS | ||
| 486 | help | ||
| 487 | Choose how you install /bin/sh applet link. | ||
| 488 | |||
| 489 | config INSTALL_SH_APPLET_SYMLINK | ||
| 490 | bool "as soft-link" | ||
| 491 | help | ||
| 492 | Install /bin/sh applet as soft-link to the busybox binary. | ||
| 493 | |||
| 494 | config INSTALL_SH_APPLET_HARDLINK | ||
| 495 | bool "as hard-link" | ||
| 496 | help | ||
| 497 | Install /bin/sh applet as hard-link to the busybox binary. | ||
| 498 | |||
| 499 | config INSTALL_SH_APPLET_SCRIPT_WRAPPER | ||
| 500 | bool "as script wrapper" | ||
| 501 | help | ||
| 502 | Install /bin/sh applet as script wrapper that call the busybox binary. | ||
| 503 | |||
| 504 | endchoice | ||
| 505 | |||
| 477 | config PREFIX | 506 | config PREFIX |
| 478 | string "BusyBox installation prefix" | 507 | string "BusyBox installation prefix" |
| 479 | default "./_install" | 508 | default "./_install" |
diff --git a/Makefile.custom b/Makefile.custom index a011d53fd..5562ba396 100644 --- a/Makefile.custom +++ b/Makefile.custom | |||
| @@ -12,6 +12,17 @@ endif | |||
| 12 | ifeq ($(CONFIG_INSTALL_APPLET_HARDLINKS),y) | 12 | ifeq ($(CONFIG_INSTALL_APPLET_HARDLINKS),y) |
| 13 | INSTALL_OPTS:= --hardlinks | 13 | INSTALL_OPTS:= --hardlinks |
| 14 | endif | 14 | endif |
| 15 | ifeq ($(CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS),y) | ||
| 16 | ifeq ($(CONFIG_INSTALL_SH_APPLET_SYMLINK),y) | ||
| 17 | INSTALL_OPTS:= --sw-sh-sym | ||
| 18 | endif | ||
| 19 | ifeq ($(CONFIG_INSTALL_SH_APPLET_HARDLINK),y) | ||
| 20 | INSTALL_OPTS:= --sw-sh-hard | ||
| 21 | endif | ||
| 22 | ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y) | ||
| 23 | INSTALL_OPTS:= --scriptwrapper | ||
| 24 | endif | ||
| 25 | endif | ||
| 15 | install: $(srctree)/applets/install.sh busybox busybox.links | 26 | install: $(srctree)/applets/install.sh busybox busybox.links |
| 16 | $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \ | 27 | $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \ |
| 17 | $(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS) | 28 | $(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS) |
diff --git a/applets/applets.c b/applets/applets.c index 6de6db3cd..c2040b9a3 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
| @@ -600,9 +600,10 @@ static int busybox_main(char **argv) | |||
| 600 | /* "busybox <applet> arg1 arg2 ..." */ | 600 | /* "busybox <applet> arg1 arg2 ..." */ |
| 601 | argv++; | 601 | argv++; |
| 602 | } | 602 | } |
| 603 | /* we want "<argv[0]>: applet not found", not "busybox: ..." */ | 603 | /* We support "busybox /a/path/to/applet args..." too. Allows for |
| 604 | applet_name = argv[0]; | 604 | * "#!/bin/busybox"-style wrappers */ |
| 605 | run_applet_and_exit(argv[0], argv); | 605 | applet_name = bb_get_last_path_component(argv[0]); |
| 606 | run_applet_and_exit(applet_name, argv); | ||
| 606 | bb_error_msg_and_die("applet not found"); | 607 | bb_error_msg_and_die("applet not found"); |
| 607 | } | 608 | } |
| 608 | 609 | ||
diff --git a/applets/install.sh b/applets/install.sh index b02350262..e94b2b98e 100755 --- a/applets/install.sh +++ b/applets/install.sh | |||
| @@ -5,19 +5,23 @@ export LC_CTYPE=POSIX | |||
| 5 | 5 | ||
| 6 | prefix=${1} | 6 | prefix=${1} |
| 7 | if [ -z "$prefix" ]; then | 7 | if [ -z "$prefix" ]; then |
| 8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks]" | 8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]" |
| 9 | exit 1; | 9 | exit 1; |
| 10 | fi | 10 | fi |
| 11 | h=`sort busybox.links | uniq` | 11 | h=`sort busybox.links | uniq` |
| 12 | scriptwrapper="n" | ||
| 12 | cleanup="0" | 13 | cleanup="0" |
| 13 | noclobber="0" | 14 | noclobber="0" |
| 14 | case "$2" in | 15 | case "$2" in |
| 15 | --hardlinks) linkopts="-f";; | 16 | --hardlinks) linkopts="-f";; |
| 16 | --symlinks) linkopts="-fs";; | 17 | --symlinks) linkopts="-fs";; |
| 17 | --cleanup) cleanup="1";; | 18 | --scriptwrapper) scriptwrapper="y";swrapall="y";; |
| 18 | --noclobber) noclobber="1";; | 19 | --sw-sh-hard) scriptwrapper="y";linkopts="-f";; |
| 19 | "") h="";; | 20 | --sw-sh-sym) scriptwrapper="y";linkopts="-fs";; |
| 20 | *) echo "Unknown install option: $2"; exit 1;; | 21 | --cleanup) cleanup="1";; |
| 22 | --noclobber) noclobber="1";; | ||
| 23 | "") h="";; | ||
| 24 | *) echo "Unknown install option: $2"; exit 1;; | ||
| 21 | esac | 25 | esac |
| 22 | 26 | ||
| 23 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then | 27 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then |
| @@ -52,6 +56,7 @@ if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then | |||
| 52 | cd "$pd" | 56 | cd "$pd" |
| 53 | done | 57 | done |
| 54 | ` | 58 | ` |
| 59 | exit 0 | ||
| 55 | fi | 60 | fi |
| 56 | 61 | ||
| 57 | rm -f $prefix/bin/busybox || exit 1 | 62 | rm -f $prefix/bin/busybox || exit 1 |
| @@ -61,33 +66,44 @@ install -m 755 busybox $prefix/bin/busybox || exit 1 | |||
| 61 | for i in $h; do | 66 | for i in $h; do |
| 62 | appdir=`dirname $i` | 67 | appdir=`dirname $i` |
| 63 | mkdir -p $prefix/$appdir || exit 1 | 68 | mkdir -p $prefix/$appdir || exit 1 |
| 64 | if [ "$2" = "--hardlinks" ]; then | 69 | if [ "$scriptwrapper" = "y" ]; then |
| 65 | bb_path="$prefix/bin/busybox" | 70 | if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then |
| 66 | else | 71 | ln $linkopts busybox $prefix$i || exit 1 |
| 67 | case "$appdir" in | 72 | else |
| 68 | /) | 73 | rm -f $prefix$i |
| 69 | bb_path="bin/busybox" | 74 | echo "#!/bin/busybox" > $prefix$i |
| 70 | ;; | 75 | chmod +x $prefix/$i |
| 71 | /bin) | 76 | fi |
| 72 | bb_path="busybox" | 77 | echo " $prefix$i" |
| 73 | ;; | ||
| 74 | /sbin) | ||
| 75 | bb_path="../bin/busybox" | ||
| 76 | ;; | ||
| 77 | /usr/bin|/usr/sbin) | ||
| 78 | bb_path="../../bin/busybox" | ||
| 79 | ;; | ||
| 80 | *) | ||
| 81 | echo "Unknown installation directory: $appdir" | ||
| 82 | exit 1 | ||
| 83 | ;; | ||
| 84 | esac | ||
| 85 | fi | ||
| 86 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then | ||
| 87 | echo " $prefix$i -> $bb_path" | ||
| 88 | ln $linkopts $bb_path $prefix$i || exit 1 | ||
| 89 | else | 78 | else |
| 90 | echo " $prefix$i already exists" | 79 | if [ "$2" = "--hardlinks" ]; then |
| 80 | bb_path="$prefix/bin/busybox" | ||
| 81 | else | ||
| 82 | case "$appdir" in | ||
| 83 | /) | ||
| 84 | bb_path="bin/busybox" | ||
| 85 | ;; | ||
| 86 | /bin) | ||
| 87 | bb_path="busybox" | ||
| 88 | ;; | ||
| 89 | /sbin) | ||
| 90 | bb_path="../bin/busybox" | ||
| 91 | ;; | ||
| 92 | /usr/bin|/usr/sbin) | ||
| 93 | bb_path="../../bin/busybox" | ||
| 94 | ;; | ||
| 95 | *) | ||
| 96 | echo "Unknown installation directory: $appdir" | ||
| 97 | exit 1 | ||
| 98 | ;; | ||
| 99 | esac | ||
| 100 | fi | ||
| 101 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then | ||
| 102 | echo " $prefix$i -> $bb_path" | ||
| 103 | ln $linkopts $bb_path $prefix$i || exit 1 | ||
| 104 | else | ||
| 105 | echo " $prefix$i already exists" | ||
| 106 | fi | ||
| 91 | fi | 107 | fi |
| 92 | done | 108 | done |
| 93 | 109 | ||
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index bcb7ea6a0..318f08059 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
| @@ -268,7 +268,7 @@ Special characters: | |||
| 268 | max 3 args; count uses of '-2'; min 2 args; if there is | 268 | max 3 args; count uses of '-2'; min 2 args; if there is |
| 269 | a '-2' option then unset '-3', '-X' and '-a'; if there is | 269 | a '-2' option then unset '-3', '-X' and '-a'; if there is |
| 270 | a '-2' and after it a '-x' then error out. | 270 | a '-2' and after it a '-x' then error out. |
| 271 | But it's far too obfuscated. Use ':' to separate groups. | 271 | But it's far too obfuscated. Use ':' to separate groups. |
| 272 | */ | 272 | */ |
| 273 | 273 | ||
| 274 | /* Code here assumes that 'unsigned' is at least 32 bits wide */ | 274 | /* Code here assumes that 'unsigned' is at least 32 bits wide */ |
