diff options
author | Ron Yorston <rmy@pobox.com> | 2021-03-01 11:48:04 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-03-01 11:48:04 +0000 |
commit | e2e8e16b465d34759678b8170c44ce62c5b74eb0 (patch) | |
tree | abc31e3e2c1d0de089ae5e1e6d37672394757af9 /libbb | |
parent | b5cd41cdf4e6afd475fe34b755f99578e20b08ca (diff) | |
parent | 9b6bcfda0e11c0e73a966a77110f6c68425cff34 (diff) | |
download | busybox-w32-e2e8e16b465d34759678b8170c44ce62c5b74eb0.tar.gz busybox-w32-e2e8e16b465d34759678b8170c44ce62c5b74eb0.tar.bz2 busybox-w32-e2e8e16b465d34759678b8170c44ce62c5b74eb0.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/appletlib.c | 70 | ||||
-rw-r--r-- | libbb/lineedit.c | 19 | ||||
-rw-r--r-- | libbb/platform.c | 12 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 5 |
4 files changed, 61 insertions, 45 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 1587cf36f..846417d59 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -1034,6 +1034,34 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
1034 | # endif | 1034 | # endif |
1035 | 1035 | ||
1036 | # if NUM_APPLETS > 0 | 1036 | # if NUM_APPLETS > 0 |
1037 | void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv) | ||
1038 | { | ||
1039 | /* Special case. POSIX says "test --help" | ||
1040 | * should be no different from e.g. "test --foo". | ||
1041 | * Thus for "test", we skip --help check. | ||
1042 | * "true" and "false" are also special. | ||
1043 | */ | ||
1044 | if (1 | ||
1045 | # if defined APPLET_NO_test | ||
1046 | && applet_no != APPLET_NO_test | ||
1047 | # endif | ||
1048 | # if defined APPLET_NO_true | ||
1049 | && applet_no != APPLET_NO_true | ||
1050 | # endif | ||
1051 | # if defined APPLET_NO_false | ||
1052 | && applet_no != APPLET_NO_false | ||
1053 | # endif | ||
1054 | # if defined APPLET_NO_busybox | ||
1055 | && applet_no != APPLET_NO_busybox | ||
1056 | # endif | ||
1057 | ) { | ||
1058 | if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) { | ||
1059 | /* Make "foo --help" exit with 0: */ | ||
1060 | xfunc_error_retval = 0; | ||
1061 | bb_show_usage(); | ||
1062 | } | ||
1063 | } | ||
1064 | } | ||
1037 | 1065 | ||
1038 | # if ENABLE_PLATFORM_MINGW32 | 1066 | # if ENABLE_PLATFORM_MINGW32 |
1039 | static int interp = 0; | 1067 | static int interp = 0; |
@@ -1043,11 +1071,13 @@ char bb_command_line[128]; | |||
1043 | 1071 | ||
1044 | void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) | 1072 | void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) |
1045 | { | 1073 | { |
1046 | int argc = string_array_len(argv); | ||
1047 | # if ENABLE_PLATFORM_MINGW32 | 1074 | # if ENABLE_PLATFORM_MINGW32 |
1075 | int argc = string_array_len(argv); | ||
1048 | int i; | 1076 | int i; |
1049 | const char *vmask; | 1077 | const char *vmask; |
1050 | unsigned int mask; | 1078 | unsigned int mask; |
1079 | # else | ||
1080 | int argc; | ||
1051 | # endif | 1081 | # endif |
1052 | 1082 | ||
1053 | /* | 1083 | /* |
@@ -1055,6 +1085,12 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar | |||
1055 | * "-/sbin/halt" -> "halt", for example. | 1085 | * "-/sbin/halt" -> "halt", for example. |
1056 | */ | 1086 | */ |
1057 | applet_name = name; | 1087 | applet_name = name; |
1088 | |||
1089 | show_usage_if_dash_dash_help(applet_no, argv); | ||
1090 | |||
1091 | if (ENABLE_FEATURE_SUID) | ||
1092 | check_suid(applet_no); | ||
1093 | |||
1058 | # if ENABLE_PLATFORM_MINGW32 | 1094 | # if ENABLE_PLATFORM_MINGW32 |
1059 | safe_strncpy(bb_comm, | 1095 | safe_strncpy(bb_comm, |
1060 | interp ? bb_basename(argv[interp]) : applet_name, | 1096 | interp ? bb_basename(argv[interp]) : applet_name, |
@@ -1069,37 +1105,11 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar | |||
1069 | vmask = getenv("BB_UMASK"); | 1105 | vmask = getenv("BB_UMASK"); |
1070 | if (vmask && sscanf(vmask, "%o", &mask) == 1) | 1106 | if (vmask && sscanf(vmask, "%o", &mask) == 1) |
1071 | umask((mode_t)(mask&0777)); | 1107 | umask((mode_t)(mask&0777)); |
1108 | # else | ||
1109 | argc = string_array_len(argv); | ||
1072 | # endif | 1110 | # endif |
1073 | |||
1074 | /* Special case. POSIX says "test --help" | ||
1075 | * should be no different from e.g. "test --foo". | ||
1076 | * Thus for "test", we skip --help check. | ||
1077 | * "true" and "false" are also special. | ||
1078 | */ | ||
1079 | if (1 | ||
1080 | # if defined APPLET_NO_test | ||
1081 | && applet_no != APPLET_NO_test | ||
1082 | # endif | ||
1083 | # if defined APPLET_NO_true | ||
1084 | && applet_no != APPLET_NO_true | ||
1085 | # endif | ||
1086 | # if defined APPLET_NO_false | ||
1087 | && applet_no != APPLET_NO_false | ||
1088 | # endif | ||
1089 | # if defined APPLET_NO_busybox | ||
1090 | && applet_no != APPLET_NO_busybox | ||
1091 | # endif | ||
1092 | ) { | ||
1093 | if (argc == 2 && strcmp(argv[1], "--help") == 0) { | ||
1094 | /* Make "foo --help" exit with 0: */ | ||
1095 | xfunc_error_retval = 0; | ||
1096 | bb_show_usage(); | ||
1097 | } | ||
1098 | } | ||
1099 | if (ENABLE_FEATURE_SUID) | ||
1100 | check_suid(applet_no); | ||
1101 | |||
1102 | xfunc_error_retval = applet_main[applet_no](argc, argv); | 1111 | xfunc_error_retval = applet_main[applet_no](argc, argv); |
1112 | |||
1103 | /* Note: applet_main() may also not return (die on a xfunc or such) */ | 1113 | /* Note: applet_main() may also not return (die on a xfunc or such) */ |
1104 | xfunc_die(); | 1114 | xfunc_die(); |
1105 | } | 1115 | } |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 55141e141..205044630 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -829,8 +829,6 @@ static unsigned path_parse(char ***p) | |||
829 | if (!tmp) | 829 | if (!tmp) |
830 | break; | 830 | break; |
831 | tmp++; | 831 | tmp++; |
832 | if (*tmp == '\0') | ||
833 | break; /* :<empty> */ | ||
834 | npth++; | 832 | npth++; |
835 | } | 833 | } |
836 | 834 | ||
@@ -842,8 +840,6 @@ static unsigned path_parse(char ***p) | |||
842 | if (!tmp) | 840 | if (!tmp) |
843 | break; | 841 | break; |
844 | *tmp++ = '\0'; /* ':' -> '\0' */ | 842 | *tmp++ = '\0'; /* ':' -> '\0' */ |
845 | if (*tmp == '\0') | ||
846 | break; /* :<empty> */ | ||
847 | res[npth++] = tmp; | 843 | res[npth++] = tmp; |
848 | } | 844 | } |
849 | /* special case: "match subdirectories of the current directory" */ | 845 | /* special case: "match subdirectories of the current directory" */ |
@@ -925,9 +921,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
925 | struct dirent *next; | 921 | struct dirent *next; |
926 | struct stat st; | 922 | struct stat st; |
927 | char *found; | 923 | char *found; |
928 | #if ENABLE_PLATFORM_MINGW32 | 924 | const char *lpath; |
929 | char *lpath; | ||
930 | #endif | ||
931 | 925 | ||
932 | if (paths[i] == NULL) { /* path_parse()'s last component? */ | 926 | if (paths[i] == NULL) { /* path_parse()'s last component? */ |
933 | /* in PATH completion, current dir's subdir names | 927 | /* in PATH completion, current dir's subdir names |
@@ -937,12 +931,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
937 | paths[i] = (char *)"."; | 931 | paths[i] = (char *)"."; |
938 | } | 932 | } |
939 | 933 | ||
934 | lpath = *paths[i] ? paths[i] : "."; | ||
940 | #if ENABLE_PLATFORM_MINGW32 | 935 | #if ENABLE_PLATFORM_MINGW32 |
941 | lpath = auto_string(alloc_system_drive(paths[i])); | 936 | lpath = auto_string(alloc_system_drive(lpath)); |
942 | dir = opendir(lpath); | ||
943 | #else | ||
944 | dir = opendir(paths[i]); | ||
945 | #endif | 937 | #endif |
938 | dir = opendir(lpath); | ||
946 | if (!dir) | 939 | if (!dir) |
947 | continue; /* don't print an error */ | 940 | continue; /* don't print an error */ |
948 | 941 | ||
@@ -957,11 +950,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
957 | if (strncmp(basecmd, name_found, baselen) != 0) | 950 | if (strncmp(basecmd, name_found, baselen) != 0) |
958 | continue; /* no */ | 951 | continue; /* no */ |
959 | 952 | ||
960 | #if ENABLE_PLATFORM_MINGW32 | ||
961 | found = concat_path_file(lpath, name_found); | 953 | found = concat_path_file(lpath, name_found); |
962 | #else | ||
963 | found = concat_path_file(paths[i], name_found); | ||
964 | #endif | ||
965 | /* NB: stat() first so that we see is it a directory; | 954 | /* NB: stat() first so that we see is it a directory; |
966 | * but if that fails, use lstat() so that | 955 | * but if that fails, use lstat() so that |
967 | * we still match dangling links */ | 956 | * we still match dangling links */ |
diff --git a/libbb/platform.c b/libbb/platform.c index 329b0237e..7913353e2 100644 --- a/libbb/platform.c +++ b/libbb/platform.c | |||
@@ -166,6 +166,18 @@ char* FAST_FUNC stpcpy(char *p, const char *to_add) | |||
166 | } | 166 | } |
167 | #endif | 167 | #endif |
168 | 168 | ||
169 | #ifndef HAVE_STPNCPY | ||
170 | char* FAST_FUNC stpncpy(char *p, const char *to_add, size_t n) | ||
171 | { | ||
172 | while (n != 0 && (*p = *to_add) != '\0') { | ||
173 | p++; | ||
174 | to_add++; | ||
175 | n--; | ||
176 | } | ||
177 | return p; | ||
178 | } | ||
179 | #endif | ||
180 | |||
169 | #ifndef HAVE_GETLINE | 181 | #ifndef HAVE_GETLINE |
170 | ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) | 182 | ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) |
171 | { | 183 | { |
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 26e1776a4..885c19f1a 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -109,8 +109,13 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) | |||
109 | char *tmp_argv[argc+1]; | 109 | char *tmp_argv[argc+1]; |
110 | memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0])); | 110 | memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0])); |
111 | applet_name = tmp_argv[0]; | 111 | applet_name = tmp_argv[0]; |
112 | |||
113 | /* longjmp's (instead of returning) if --help is seen */ | ||
114 | show_usage_if_dash_dash_help(applet_no, argv); | ||
115 | |||
112 | /* Finally we can call NOFORK applet's main() */ | 116 | /* Finally we can call NOFORK applet's main() */ |
113 | rc = applet_main[applet_no](argc, tmp_argv); | 117 | rc = applet_main[applet_no](argc, tmp_argv); |
118 | |||
114 | /* Important for shells: `which CMD` was failing */ | 119 | /* Important for shells: `which CMD` was failing */ |
115 | fflush_all(); | 120 | fflush_all(); |
116 | } else { | 121 | } else { |