aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-04-06 10:26:27 +0100
committerRon Yorston <rmy@pobox.com>2016-04-06 10:50:19 +0100
commit98b290e9b8221b7d7ffbf47da1e8ecce62a75369 (patch)
treec27be593d3fd3525b515c7d7643ba0db59afe2bb /libbb/appletlib.c
parent57f63917f08a8f6b042f8e223c6a6746ea2b6d01 (diff)
downloadbusybox-w32-98b290e9b8221b7d7ffbf47da1e8ecce62a75369.tar.gz
busybox-w32-98b290e9b8221b7d7ffbf47da1e8ecce62a75369.tar.bz2
busybox-w32-98b290e9b8221b7d7ffbf47da1e8ecce62a75369.zip
mingw: enable busybox --install by default
Allow FEATURE_INSTALLER to be configured and enable it in the default configuration. The behaviour is slightly different from upstream BusyBox: symbolic links are not permitted; if no target directory is provided the directory containing the busybox binary is used as the target.
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index b71f2dd7e..4a9d363dd 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -662,6 +662,7 @@ static void check_suid(int applet_no)
662 662
663 663
664# if ENABLE_FEATURE_INSTALLER 664# if ENABLE_FEATURE_INSTALLER
665# if !ENABLE_PLATFORM_MINGW32
665static const char usr_bin [] ALIGN1 = "/usr/bin/"; 666static const char usr_bin [] ALIGN1 = "/usr/bin/";
666static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; 667static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
667static const char *const install_dir[] = { 668static const char *const install_dir[] = {
@@ -706,6 +707,29 @@ static void install_links(const char *busybox, int use_symbolic_links,
706 continue; 707 continue;
707 } 708 }
708} 709}
710# else /* ENABLE_PLATFORM_MINGW32 */
711static void install_links(const char *busybox,
712 int use_symbolic_links UNUSED_PARAM, char *custom_install_dir)
713{
714 char *fpc;
715 const char *appname = applet_names;
716 int rc;
717
718 if (!is_directory(custom_install_dir, FALSE))
719 bb_error_msg_and_die("'%s' is not a directory", custom_install_dir);
720
721 while (*appname) {
722 fpc = xasprintf("%s/%s.exe", custom_install_dir, appname);
723 rc = link(busybox, fpc);
724 if (rc != 0 && errno != EEXIST) {
725 bb_simple_perror_msg(fpc);
726 }
727 free(fpc);
728 while (*appname++ != '\0')
729 continue;
730 }
731}
732# endif
709# else 733# else
710static void install_links(const char *busybox UNUSED_PARAM, 734static void install_links(const char *busybox UNUSED_PARAM,
711 int use_symbolic_links UNUSED_PARAM, 735 int use_symbolic_links UNUSED_PARAM,
@@ -743,9 +767,14 @@ static int busybox_main(char **argv)
743 "copyright notices.\n" 767 "copyright notices.\n"
744 "\n" 768 "\n"
745 "Usage: busybox [function [arguments]...]\n" 769 "Usage: busybox [function [arguments]...]\n"
770 IF_NOT_PLATFORM_MINGW32(
746 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" 771 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n"
772 )
773 IF_PLATFORM_MINGW32(
774 " or: busybox --list\n"
775 )
747 IF_FEATURE_INSTALLER( 776 IF_FEATURE_INSTALLER(
748 " or: busybox --install [-s] [DIR]\n" 777 " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n"
749 ) 778 )
750 " or: function [arguments]...\n" 779 " or: function [arguments]...\n"
751 "\n" 780 "\n"
@@ -799,7 +828,7 @@ static int busybox_main(char **argv)
799 const char *a = applet_names; 828 const char *a = applet_names;
800 dup2(1, 2); 829 dup2(1, 2);
801 while (*a) { 830 while (*a) {
802# if ENABLE_FEATURE_INSTALLER 831# if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32
803 if (argv[1][6]) /* --list-full? */ 832 if (argv[1][6]) /* --list-full? */
804 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); 833 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
805# endif 834# endif
@@ -812,6 +841,7 @@ static int busybox_main(char **argv)
812 } 841 }
813 842
814 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { 843 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
844#if !ENABLE_PLATFORM_MINGW32
815 int use_symbolic_links; 845 int use_symbolic_links;
816 const char *busybox; 846 const char *busybox;
817 847
@@ -832,6 +862,14 @@ static int busybox_main(char **argv)
832 */ 862 */
833 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); 863 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv);
834 install_links(busybox, use_symbolic_links, argv[2]); 864 install_links(busybox, use_symbolic_links, argv[2]);
865#else
866 /* busybox --install [DIR]
867 * where DIR is the directory to install to. If DIR is not
868 * provided put the links in the same directory as busybox.
869 */
870 install_links(bb_busybox_exec_path, FALSE, argv[2] ? argv[2] :
871 dirname(xstrdup(bb_busybox_exec_path)));
872#endif
835 return 0; 873 return 0;
836 } 874 }
837 875