aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-11-28 10:28:18 +0000
committerRon Yorston <rmy@pobox.com>2018-11-28 10:28:18 +0000
commit2a69a2200a141c1504b662eca64b802cdab71b12 (patch)
treeeab0cc01852db237a26052a83c8f582ed92b7cd9 /libbb
parent97ca1f4b955f486cd26461cb09185335483d2921 (diff)
parent572dfb8e78323b9837f7c5e3369ee233a440b8f2 (diff)
downloadbusybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.tar.gz
busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.tar.bz2
busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c125
-rw-r--r--libbb/hash_md5_sha.c5
-rw-r--r--libbb/progress.c5
-rw-r--r--libbb/u_signal_names.c82
4 files changed, 152 insertions, 65 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index add609b78..3cbb5699c 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -59,6 +59,17 @@
59 59
60#include "usage_compressed.h" 60#include "usage_compressed.h"
61 61
62#if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS
63# define DEFINE_SCRIPT_DATA 1
64# include "embedded_scripts.h"
65#else
66# define NUM_SCRIPTS 0
67#endif
68#if NUM_SCRIPTS > 0
69# define BB_ARCHIVE_PUBLIC
70# include "bb_archive.h"
71static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS };
72#endif
62 73
63/* "Do not compress usage text if uncompressed text is small 74/* "Do not compress usage text if uncompressed text is small
64 * and we don't include bunzip2 code for other reasons" 75 * and we don't include bunzip2 code for other reasons"
@@ -105,36 +116,10 @@ static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
105#if ENABLE_FEATURE_COMPRESS_USAGE 116#if ENABLE_FEATURE_COMPRESS_USAGE
106 117
107static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; 118static const char packed_usage[] ALIGN1 = { PACKED_USAGE };
108#define BB_ARCHIVE_PUBLIC 119# define BB_ARCHIVE_PUBLIC
109# include "bb_archive.h" 120# include "bb_archive.h"
110static const char *unpack_usage_messages(void) 121# define unpack_usage_messages() \
111{ 122 unpack_bz2_data(packed_usage, sizeof(packed_usage), sizeof(UNPACKED_USAGE))
112 char *outbuf = NULL;
113 bunzip_data *bd;
114 int i;
115 jmp_buf jmpbuf;
116
117 /* Setup for I/O error handling via longjmp */
118 i = setjmp(jmpbuf);
119 if (i == 0) {
120 i = start_bunzip(&jmpbuf,
121 &bd,
122 /* src_fd: */ -1,
123 /* inbuf: */ packed_usage,
124 /* len: */ sizeof(packed_usage)
125 );
126 }
127 /* read_bunzip can longjmp and end up here with i != 0
128 * on read data errors! Not trivial */
129 if (i == 0) {
130 /* Cannot use xmalloc: will leak bd in NOFORK case! */
131 outbuf = malloc_or_warn(sizeof(UNPACKED_USAGE));
132 if (outbuf)
133 read_bunzip(bd, outbuf, sizeof(UNPACKED_USAGE));
134 }
135 dealloc_bunzip(bd);
136 return outbuf;
137}
138# define dealloc_usage_messages(s) free(s) 123# define dealloc_usage_messages(s) free(s)
139 124
140#else 125#else
@@ -152,21 +137,23 @@ void FAST_FUNC bb_show_usage(void)
152 /* Imagine that this applet is "true". Dont suck in printf! */ 137 /* Imagine that this applet is "true". Dont suck in printf! */
153 const char *usage_string = unpack_usage_messages(); 138 const char *usage_string = unpack_usage_messages();
154 139
155 if (*usage_string == '\b') { 140 if (usage_string) {
156 full_write2_str("No help available.\n\n"); 141 if (*usage_string == '\b') {
157 } else { 142 full_write2_str("No help available.\n\n");
158 full_write2_str("Usage: "SINGLE_APPLET_STR" "); 143 } else {
159 full_write2_str(usage_string); 144 full_write2_str("Usage: "SINGLE_APPLET_STR" ");
160 full_write2_str("\n\n"); 145 full_write2_str(usage_string);
146 full_write2_str("\n\n");
147 }
148 if (ENABLE_FEATURE_CLEAN_UP)
149 dealloc_usage_messages((char*)usage_string);
161 } 150 }
162 if (ENABLE_FEATURE_CLEAN_UP)
163 dealloc_usage_messages((char*)usage_string);
164#else 151#else
165 const char *p; 152 const char *p;
166 const char *usage_string = p = unpack_usage_messages(); 153 const char *usage_string = p = unpack_usage_messages();
167 int ap = find_applet_by_name(applet_name); 154 int ap = find_applet_by_name(applet_name);
168 155
169 if (ap < 0) /* never happens, paranoia */ 156 if (ap < 0 || usage_string == NULL)
170 xfunc_die(); 157 xfunc_die();
171 while (ap) { 158 while (ap) {
172 while (*p++) continue; 159 while (*p++) continue;
@@ -808,6 +795,50 @@ static void install_links(const char *busybox UNUSED_PARAM,
808 795
809static void run_applet_and_exit(const char *name, char **argv) NORETURN; 796static void run_applet_and_exit(const char *name, char **argv) NORETURN;
810 797
798# if NUM_SCRIPTS > 0
799static int find_script_by_name(const char *name)
800{
801 int i;
802 int applet = find_applet_by_name(name);
803
804 if (applet >= 0) {
805 for (i = 0; i < NUM_SCRIPTS; ++i)
806 if (applet_numbers[i] == applet)
807 return i;
808 }
809 return -1;
810}
811
812int scripted_main(int argc UNUSED_PARAM, char **argv)
813{
814 int script = find_script_by_name(applet_name);
815 if (script >= 0)
816#if ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH
817 exit(ash_main(-script - 1, argv));
818#elif ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH
819 exit(hush_main(-script - 1, argv));
820#else
821 return 1;
822#endif
823 return 0;
824}
825
826char* FAST_FUNC
827get_script_content(unsigned n)
828{
829 char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts),
830 UNPACKED_SCRIPTS_LENGTH);
831 if (t) {
832 while (n != 0) {
833 while (*t++ != '\0')
834 continue;
835 n--;
836 }
837 }
838 return t;
839}
840# endif /* NUM_SCRIPTS > 0 */
841
811# if ENABLE_BUSYBOX 842# if ENABLE_BUSYBOX
812# if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION 843# if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION
813 /* 844 /*
@@ -850,6 +881,9 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
850 "\n" 881 "\n"
851 "Usage: busybox [function [arguments]...]\n" 882 "Usage: busybox [function [arguments]...]\n"
852 " or: busybox --list"IF_FULL_LIST_OPTION("[-full]")"\n" 883 " or: busybox --list"IF_FULL_LIST_OPTION("[-full]")"\n"
884# if ENABLE_FEATURE_SHOW_SCRIPT && NUM_SCRIPTS > 0
885 " or: busybox --show SCRIPT\n"
886# endif
853 IF_FEATURE_INSTALLER( 887 IF_FEATURE_INSTALLER(
854 " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n" 888 " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n"
855 ) 889 )
@@ -877,9 +911,9 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
877 "Currently defined functions:\n" 911 "Currently defined functions:\n"
878 ); 912 );
879 col = 0; 913 col = 0;
880 a = applet_names;
881 /* prevent last comma to be in the very last pos */ 914 /* prevent last comma to be in the very last pos */
882 output_width--; 915 output_width--;
916 a = applet_names;
883 while (*a) { 917 while (*a) {
884 int len2 = strlen(a) + 2; 918 int len2 = strlen(a) + 2;
885 if (col >= (int)output_width - len2) { 919 if (col >= (int)output_width - len2) {
@@ -900,6 +934,19 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
900 return 0; 934 return 0;
901 } 935 }
902 936
937# if ENABLE_FEATURE_SHOW_SCRIPT && NUM_SCRIPTS > 0
938 if (strcmp(argv[1], "--show") == 0) {
939 int n;
940 if (!argv[2])
941 bb_error_msg_and_die(bb_msg_requires_arg, "--show");
942 n = find_script_by_name(argv[2]);
943 if (n < 0)
944 bb_error_msg_and_die("script '%s' not found", argv[2]);
945 full_write1_str(get_script_content(n));
946 return 0;
947 }
948# endif
949
903 if (is_prefixed_with(argv[1], "--list")) { 950 if (is_prefixed_with(argv[1], "--list")) {
904 unsigned i = 0; 951 unsigned i = 0;
905 const char *a = applet_names; 952 const char *a = applet_names;
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
index a53a382ce..9db79ea8b 100644
--- a/libbb/hash_md5_sha.c
+++ b/libbb/hash_md5_sha.c
@@ -794,6 +794,11 @@ static const uint32_t init512_lo[] = {
794}; 794};
795#endif /* NEED_SHA512 */ 795#endif /* NEED_SHA512 */
796 796
797// Note: SHA-384 is identical to SHA-512, except that initial hash values are
798// 0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939,
799// 0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4,
800// and the output is constructed by omitting last two 64-bit words of it.
801
797/* Initialize structure containing state of computation. 802/* Initialize structure containing state of computation.
798 (FIPS 180-2:5.3.2) */ 803 (FIPS 180-2:5.3.2) */
799void FAST_FUNC sha256_begin(sha256_ctx_t *ctx) 804void FAST_FUNC sha256_begin(sha256_ctx_t *ctx)
diff --git a/libbb/progress.c b/libbb/progress.c
index 23e974ce7..d071ce705 100644
--- a/libbb/progress.c
+++ b/libbb/progress.c
@@ -69,7 +69,7 @@ void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile)
69 * will be "totalsize" bytes. 69 * will be "totalsize" bytes.
70 * If totalsize == 0, then it is unknown. 70 * If totalsize == 0, then it is unknown.
71 */ 71 */
72void FAST_FUNC bb_progress_update(bb_progress_t *p, 72int FAST_FUNC bb_progress_update(bb_progress_t *p,
73 uoff_t beg_size, 73 uoff_t beg_size,
74 uoff_t transferred, 74 uoff_t transferred,
75 uoff_t totalsize) 75 uoff_t totalsize)
@@ -94,7 +94,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
94 * Do not update on every call 94 * Do not update on every call
95 * (we can be called on every network read!) 95 * (we can be called on every network read!)
96 */ 96 */
97 return; 97 return -1;
98 } 98 }
99 99
100 /* Before we lose real, unscaled sizes, produce human-readable size string */ 100 /* Before we lose real, unscaled sizes, produce human-readable size string */
@@ -211,4 +211,5 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
211 } 211 }
212 if (notty) 212 if (notty)
213 fputc('\n', stderr); 213 fputc('\n', stderr);
214 return notty;
214} 215}
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c
index b3038e32d..f7d598c7a 100644
--- a/libbb/u_signal_names.c
+++ b/libbb/u_signal_names.c
@@ -12,6 +12,18 @@
12//config: help 12//config: help
13//config: Support RTMIN[+n] and RTMAX[-n] signal names 13//config: Support RTMIN[+n] and RTMAX[-n] signal names
14//config: in kill, killall etc. This costs ~250 bytes. 14//config: in kill, killall etc. This costs ~250 bytes.
15//config:
16//config:config FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
17//config: bool "Use the definitions of SIGRTMIN/SIGRTMAX provided by libc"
18//config: default y
19//config: depends on FEATURE_RTMINMAX
20//config: help
21//config: Some C libraries reserve a few real-time signals for internal
22//config: use, and adjust the values of SIGRTMIN/SIGRTMAX seen by
23//config: applications accordingly. Saying yes here means that a signal
24//config: name RTMIN+n will be interpreted according to the libc definition
25//config: of SIGRTMIN, and not the raw definition provided by the kernel.
26//config: This behavior matches "kill -l RTMIN+n" from bash.
15 27
16#include "libbb.h" 28#include "libbb.h"
17 29
@@ -123,7 +135,7 @@ static const char signals[][7] ALIGN1 = {
123#ifdef SIGSYS 135#ifdef SIGSYS
124 [SIGSYS ] = "SYS", 136 [SIGSYS ] = "SYS",
125#endif 137#endif
126#if ENABLE_FEATURE_RTMINMAX 138#if ENABLE_FEATURE_RTMINMAX && !ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
127# ifdef __SIGRTMIN 139# ifdef __SIGRTMIN
128 [__SIGRTMIN] = "RTMIN", 140 [__SIGRTMIN] = "RTMIN",
129# endif 141# endif
@@ -141,8 +153,12 @@ int FAST_FUNC get_signum(const char *name)
141{ 153{
142 unsigned i; 154 unsigned i;
143 155
156 /* bb_strtou returns UINT_MAX on error. NSIG is smaller
157 * than UINT_MAX on any sane Unix. Hence no need
158 * to check errno after bb_strtou().
159 */
144 i = bb_strtou(name, NULL, 10); 160 i = bb_strtou(name, NULL, 10);
145 if (!errno && i < NSIG) /* for shells, we allow 0 too */ 161 if (i < NSIG) /* for shells, we allow 0 too */
146 return i; 162 return i;
147 if (strncasecmp(name, "SIG", 3) == 0) 163 if (strncasecmp(name, "SIG", 3) == 0)
148 name += 3; 164 name += 3;
@@ -168,36 +184,46 @@ int FAST_FUNC get_signum(const char *name)
168# endif 184# endif
169#endif 185#endif
170 186
171#if ENABLE_FEATURE_RTMINMAX 187#if ENABLE_FEATURE_RTMINMAX && defined(SIGRTMIN) && defined(SIGRTMAX)
172# if defined(SIGRTMIN) && defined(SIGRTMAX) 188 {
173/* libc may use some rt sigs for pthreads and therefore "remap" SIGRTMIN/MAX, 189# if ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
174 * but we want to use "raw" SIGRTMIN/MAX. Underscored names, if exist, provide 190 /* Use the libc provided values. */
175 * them. If they don't exist, fall back to non-underscored ones: */ 191 unsigned sigrtmin = SIGRTMIN;
192 unsigned sigrtmax = SIGRTMAX;
193# else
194 /* Use the "raw" SIGRTMIN/MAX. Underscored names, if exist, provide
195 * them. If they don't exist, fall back to non-underscored ones: */
176# if !defined(__SIGRTMIN) 196# if !defined(__SIGRTMIN)
177# define __SIGRTMIN SIGRTMIN 197# define __SIGRTMIN SIGRTMIN
178# endif 198# endif
179# if !defined(__SIGRTMAX) 199# if !defined(__SIGRTMAX)
180# define __SIGRTMAX SIGRTMAX 200# define __SIGRTMAX SIGRTMAX
181# endif 201# endif
182 if (strncasecmp(name, "RTMIN", 5) == 0) { 202
183 if (!name[5]) 203# define sigrtmin __SIGRTMIN
184 return __SIGRTMIN; 204# define sigrtmax __SIGRTMAX
185 if (name[5] == '+') { 205# endif
186 i = bb_strtou(name + 6, NULL, 10); 206 if (strncasecmp(name, "RTMIN", 5) == 0) {
187 if (!errno && i <= __SIGRTMAX - __SIGRTMIN) 207 if (!name[5])
188 return __SIGRTMIN + i; 208 return sigrtmin;
209 if (name[5] == '+') {
210 i = bb_strtou(name + 6, NULL, 10);
211 if (i <= sigrtmax - sigrtmin)
212 return sigrtmin + i;
213 }
189 } 214 }
190 } 215 else if (strncasecmp(name, "RTMAX", 5) == 0) {
191 else if (strncasecmp(name, "RTMAX", 5) == 0) { 216 if (!name[5])
192 if (!name[5]) 217 return sigrtmax;
193 return __SIGRTMAX; 218 if (name[5] == '-') {
194 if (name[5] == '-') { 219 i = bb_strtou(name + 6, NULL, 10);
195 i = bb_strtou(name + 6, NULL, 10); 220 if (i <= sigrtmax - sigrtmin)
196 if (!errno && i <= __SIGRTMAX - __SIGRTMIN) 221 return sigrtmax - i;
197 return __SIGRTMAX - i; 222 }
198 } 223 }
224# undef sigrtmin
225# undef sigrtmax
199 } 226 }
200# endif
201#endif 227#endif
202 228
203 return -1; 229 return -1;
@@ -228,8 +254,16 @@ void FAST_FUNC print_signames(void)
228 printf("%2u) %s\n", signo, name); 254 printf("%2u) %s\n", signo, name);
229 } 255 }
230#if ENABLE_FEATURE_RTMINMAX 256#if ENABLE_FEATURE_RTMINMAX
231# ifdef __SIGRTMAX 257# if ENABLE_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS
258# if defined(SIGRTMIN) && defined(SIGRTMAX)
259 printf("%2u) %s\n", SIGRTMIN, "RTMIN");
260 printf("%2u) %s\n", SIGRTMAX, "RTMAX");
261# endif
262# else
263// __SIGRTMIN is included in signals[] array.
264# ifdef __SIGRTMAX
232 printf("%2u) %s\n", __SIGRTMAX, "RTMAX"); 265 printf("%2u) %s\n", __SIGRTMAX, "RTMAX");
266# endif
233# endif 267# endif
234#endif 268#endif
235} 269}