diff options
| author | Ron Yorston <rmy@pobox.com> | 2021-03-02 12:02:04 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2021-03-02 12:02:04 +0000 |
| commit | 61e53aa93d3d6c6fcbea93c2a959836f51ef35e8 (patch) | |
| tree | 7ba668733c5ccb8a3ee75c23f0c12ff536bcc29a | |
| parent | 633e3a5eae29c5074ada2655caac74902df1acc0 (diff) | |
| download | busybox-w32-FRP-3902-g61e53aa93.tar.gz busybox-w32-FRP-3902-g61e53aa93.tar.bz2 busybox-w32-FRP-3902-g61e53aa93.zip | |
busybox: allow '--install' to install symlinksFRP-3902-g61e53aa93
Restore the '--install -s' option which allows BusyBox to install
symbolic links. Of course, this will only work if the user has
permission to create symlinks.
| -rw-r--r-- | libbb/appletlib.c | 82 |
1 files changed, 39 insertions, 43 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 846417d59..251dc1bbe 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
| @@ -672,7 +672,6 @@ static const char *const install_dir[] = { | |||
| 672 | # endif | 672 | # endif |
| 673 | }; | 673 | }; |
| 674 | 674 | ||
| 675 | # if !ENABLE_PLATFORM_MINGW32 | ||
| 676 | /* create (sym)links for each applet */ | 675 | /* create (sym)links for each applet */ |
| 677 | static void install_links(const char *busybox, int use_symbolic_links, | 676 | static void install_links(const char *busybox, int use_symbolic_links, |
| 678 | char *custom_install_dir) | 677 | char *custom_install_dir) |
| @@ -685,34 +684,8 @@ static void install_links(const char *busybox, int use_symbolic_links, | |||
| 685 | const char *appname = applet_names; | 684 | const char *appname = applet_names; |
| 686 | unsigned i; | 685 | unsigned i; |
| 687 | int rc; | 686 | int rc; |
| 688 | 687 | # if ENABLE_PLATFORM_MINGW32 | |
| 689 | lf = link; | ||
| 690 | if (use_symbolic_links) | ||
| 691 | lf = symlink; | ||
| 692 | |||
| 693 | for (i = 0; i < ARRAY_SIZE(applet_main); i++) { | ||
| 694 | fpc = concat_path_file( | ||
| 695 | custom_install_dir ? custom_install_dir : install_dir[APPLET_INSTALL_LOC(i)], | ||
| 696 | appname); | ||
| 697 | // debug: bb_error_msg("%slinking %s to busybox", | ||
| 698 | // use_symbolic_links ? "sym" : "", fpc); | ||
| 699 | rc = lf(busybox, fpc); | ||
| 700 | if (rc != 0 && errno != EEXIST) { | ||
| 701 | bb_simple_perror_msg(fpc); | ||
| 702 | } | ||
| 703 | free(fpc); | ||
| 704 | while (*appname++ != '\0') | ||
| 705 | continue; | ||
| 706 | } | ||
| 707 | } | ||
| 708 | # else /* ENABLE_PLATFORM_MINGW32 */ | ||
| 709 | static void install_links(const char *busybox, | ||
| 710 | int use_symbolic_links UNUSED_PARAM, char *custom_install_dir) | ||
| 711 | { | ||
| 712 | char *fpc; | ||
| 713 | const char *appname = applet_names; | ||
| 714 | const char *sd = NULL; | 688 | const char *sd = NULL; |
| 715 | int i, rc; | ||
| 716 | 689 | ||
| 717 | if (custom_install_dir != NULL) { | 690 | if (custom_install_dir != NULL) { |
| 718 | bb_make_directory(custom_install_dir, 0755, FILEUTILS_RECUR); | 691 | bb_make_directory(custom_install_dir, 0755, FILEUTILS_RECUR); |
| @@ -725,14 +698,26 @@ static void install_links(const char *busybox, | |||
| 725 | free(fpc); | 698 | free(fpc); |
| 726 | } | 699 | } |
| 727 | } | 700 | } |
| 701 | # endif | ||
| 702 | |||
| 703 | lf = link; | ||
| 704 | if (use_symbolic_links) | ||
| 705 | lf = symlink; | ||
| 728 | 706 | ||
| 729 | for (i = 0; i < ARRAY_SIZE(applet_main); i++) { | 707 | for (i = 0; i < ARRAY_SIZE(applet_main); i++) { |
| 708 | # if ENABLE_PLATFORM_MINGW32 | ||
| 730 | fpc = xasprintf("%s%s/%s.exe", sd ?: "", | 709 | fpc = xasprintf("%s%s/%s.exe", sd ?: "", |
| 731 | custom_install_dir ?: install_dir[APPLET_INSTALL_LOC(i)], | 710 | custom_install_dir ?: install_dir[APPLET_INSTALL_LOC(i)], |
| 732 | appname); | 711 | appname); |
| 733 | rc = link(busybox, fpc); | 712 | # else |
| 734 | if (rc != 0 && (errno != EEXIST || | 713 | fpc = concat_path_file( |
| 735 | strcmp("busybox.exe", bb_basename(fpc)) != 0)) { | 714 | custom_install_dir ? custom_install_dir : install_dir[APPLET_INSTALL_LOC(i)], |
| 715 | appname); | ||
| 716 | # endif | ||
| 717 | // debug: bb_error_msg("%slinking %s to busybox", | ||
| 718 | // use_symbolic_links ? "sym" : "", fpc); | ||
| 719 | rc = lf(busybox, fpc); | ||
| 720 | if (rc != 0 && errno != EEXIST) { | ||
| 736 | bb_simple_perror_msg(fpc); | 721 | bb_simple_perror_msg(fpc); |
| 737 | } | 722 | } |
| 738 | free(fpc); | 723 | free(fpc); |
| @@ -740,7 +725,6 @@ static void install_links(const char *busybox, | |||
| 740 | continue; | 725 | continue; |
| 741 | } | 726 | } |
| 742 | } | 727 | } |
| 743 | # endif | ||
| 744 | # elif ENABLE_BUSYBOX | 728 | # elif ENABLE_BUSYBOX |
| 745 | static void install_links(const char *busybox UNUSED_PARAM, | 729 | static void install_links(const char *busybox UNUSED_PARAM, |
| 746 | int use_symbolic_links UNUSED_PARAM, | 730 | int use_symbolic_links UNUSED_PARAM, |
| @@ -852,7 +836,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
| 852 | " or: busybox --install [-s] [DIR]\n" | 836 | " or: busybox --install [-s] [DIR]\n" |
| 853 | ) | 837 | ) |
| 854 | IF_PLATFORM_MINGW32( | 838 | IF_PLATFORM_MINGW32( |
| 855 | " or: busybox --install [-u|DIR]\n" | 839 | " or: busybox --install [-s] [-u|DIR]\n" |
| 856 | " or: busybox --uninstall [-n] file\n" | 840 | " or: busybox --uninstall [-n] file\n" |
| 857 | ) | 841 | ) |
| 858 | ) | 842 | ) |
| @@ -949,8 +933,8 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
| 949 | } | 933 | } |
| 950 | 934 | ||
| 951 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { | 935 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { |
| 952 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 953 | int use_symbolic_links; | 936 | int use_symbolic_links; |
| 937 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 954 | const char *busybox; | 938 | const char *busybox; |
| 955 | 939 | ||
| 956 | busybox = xmalloc_readlink(bb_busybox_exec_path); | 940 | busybox = xmalloc_readlink(bb_busybox_exec_path); |
| @@ -971,23 +955,35 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
| 971 | use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); | 955 | use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); |
| 972 | install_links(busybox, use_symbolic_links, argv[2]); | 956 | install_links(busybox, use_symbolic_links, argv[2]); |
| 973 | #else | 957 | #else |
| 974 | char *target = NULL; | 958 | char *target; |
| 959 | uint32_t opt; | ||
| 960 | enum { OPT_s = (1 << 0), OPT_u = (1 << 1) }; | ||
| 975 | 961 | ||
| 976 | /* busybox --install [-u|DIR] | 962 | /* busybox --install [-s] [-u|DIR] |
| 963 | * -s: make symlinks | ||
| 977 | * -u: install to Unix-style directories in system drive | 964 | * -u: install to Unix-style directories in system drive |
| 978 | * DIR: directory to install links to | 965 | * DIR: directory to install links to |
| 979 | * If no argument is provided put the links in the same directory | 966 | * If no argument is provided put the links in the same directory |
| 980 | * as busybox. | 967 | * as busybox. |
| 981 | */ | 968 | */ |
| 982 | if (argv[2]) { | 969 | argv += 1; |
| 983 | if (strcmp(argv[2], "-u") != 0) | 970 | opt = getopt32(argv, "!su"); |
| 984 | target = argv[2]; | 971 | argv += optind; |
| 985 | } | 972 | |
| 986 | else { | 973 | if (opt == (uint32_t)-1 || |
| 974 | (*argv != NULL && (opt & OPT_u || *(argv + 1) != NULL))) | ||
| 975 | bb_simple_error_msg_and_die("busybox --install [-s] [-u|DIR]"); | ||
| 976 | |||
| 977 | if (opt & OPT_u) | ||
| 978 | target = NULL; | ||
| 979 | else if (*argv != NULL) | ||
| 980 | target = *argv; | ||
| 981 | else | ||
| 987 | target = dirname(xstrdup(bb_busybox_exec_path)); | 982 | target = dirname(xstrdup(bb_busybox_exec_path)); |
| 988 | } | 983 | |
| 984 | use_symbolic_links = opt & OPT_s; | ||
| 989 | /* NULL target -> install to Unix-style dirs */ | 985 | /* NULL target -> install to Unix-style dirs */ |
| 990 | install_links(bb_busybox_exec_path, FALSE, target); | 986 | install_links(bb_busybox_exec_path, use_symbolic_links, target); |
| 991 | #endif | 987 | #endif |
| 992 | return 0; | 988 | return 0; |
| 993 | } | 989 | } |
