source: clfs-embedded/patches/busybox-1.15.0-branch_update-1.patch@ 8235a08

Last change on this file since 8235a08 was 2e856a4, checked in by Maarten Lankhorst <mlankhorst@…>, 15 years ago

bump busybox to 1.15

  • Property mode set to 100644
File size: 15.5 KB
RevLine 
[2e856a4]1diff -ru busybox-1.15.0-ori/archival/Config.in busybox-1.15.0/archival/Config.in
2--- busybox-1.15.0-ori/archival/Config.in 2009-08-21 00:26:13.000000000 +0200
3+++ busybox-1.15.0/archival/Config.in 2009-09-07 13:50:46.926666752 +0200
4@@ -298,8 +298,8 @@
5 default n
6 depends on UNLZMA
7 help
8- This option reduces decompression time by about 25% at the cost of
9- a 1K bigger binary.
10+ This option reduces decompression time by about 33% at the cost of
11+ a 2K bigger binary.
12
13 config UNZIP
14 bool "unzip"
15diff -ru busybox-1.15.0-ori/archival/libunarchive/data_extract_all.c busybox-1.15.0/archival/libunarchive/data_extract_all.c
16--- busybox-1.15.0-ori/archival/libunarchive/data_extract_all.c 2009-08-21 00:26:13.000000000 +0200
17+++ busybox-1.15.0/archival/libunarchive/data_extract_all.c 2009-09-07 13:50:46.926666752 +0200
18@@ -132,7 +132,7 @@
19 #endif
20 lchown(file_header->name, file_header->uid, file_header->gid);
21 }
22- if (S_ISLNK(file_header->mode)) {
23+ if (!S_ISLNK(file_header->mode)) {
24 /* uclibc has no lchmod, glibc is even stranger -
25 * it has lchmod which seems to do nothing!
26 * so we use chmod... */
27diff -ru busybox-1.15.0-ori/archival/libunarchive/decompress_unlzma.c busybox-1.15.0/archival/libunarchive/decompress_unlzma.c
28--- busybox-1.15.0-ori/archival/libunarchive/decompress_unlzma.c 2009-08-21 00:26:13.000000000 +0200
29+++ busybox-1.15.0/archival/libunarchive/decompress_unlzma.c 2009-09-07 13:50:46.926666752 +0200
30@@ -8,15 +8,14 @@
31 *
32 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
33 */
34+
35 #include "libbb.h"
36 #include "unarchive.h"
37
38 #if ENABLE_FEATURE_LZMA_FAST
39 # define speed_inline ALWAYS_INLINE
40-# define size_inline
41 #else
42 # define speed_inline
43-# define size_inline ALWAYS_INLINE
44 #endif
45
46
47@@ -45,8 +44,8 @@
48 #define RC_MODEL_TOTAL_BITS 11
49
50
51-/* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
52-static size_inline void rc_read(rc_t *rc)
53+/* Called twice: once at startup and once in rc_normalize() */
54+static void rc_read(rc_t *rc)
55 {
56 int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
57 if (buffer_size <= 0)
58@@ -55,17 +54,8 @@
59 rc->buffer_end = RC_BUFFER + buffer_size;
60 }
61
62-/* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */
63-static void rc_do_normalize(rc_t *rc)
64-{
65- if (rc->ptr >= rc->buffer_end)
66- rc_read(rc);
67- rc->range <<= 8;
68- rc->code = (rc->code << 8) | *rc->ptr++;
69-}
70-
71 /* Called once */
72-static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
73+static rc_t* rc_init(int fd) /*, int buffer_size) */
74 {
75 int i;
76 rc_t *rc;
77@@ -73,18 +63,17 @@
78 rc = xmalloc(sizeof(*rc) + RC_BUFFER_SIZE);
79
80 rc->fd = fd;
81+ /* rc->buffer_size = buffer_size; */
82+ rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;
83 rc->ptr = rc->buffer_end;
84
85+ rc->code = 0;
86+ rc->range = 0xFFFFFFFF;
87 for (i = 0; i < 5; i++) {
88-#if ENABLE_FEATURE_LZMA_FAST
89 if (rc->ptr >= rc->buffer_end)
90 rc_read(rc);
91 rc->code = (rc->code << 8) | *rc->ptr++;
92-#else
93- rc_do_normalize(rc);
94-#endif
95 }
96- rc->range = 0xFFFFFFFF;
97 return rc;
98 }
99
100@@ -94,6 +83,14 @@
101 free(rc);
102 }
103
104+/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
105+static void rc_do_normalize(rc_t *rc)
106+{
107+ if (rc->ptr >= rc->buffer_end)
108+ rc_read(rc);
109+ rc->range <<= 8;
110+ rc->code = (rc->code << 8) | *rc->ptr++;
111+}
112 static ALWAYS_INLINE void rc_normalize(rc_t *rc)
113 {
114 if (rc->range < (1 << RC_TOP_BITS)) {
115@@ -101,28 +98,49 @@
116 }
117 }
118
119-/* rc_is_bit_1 is called 9 times */
120-static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
121+/* rc_is_bit_0 is called 9 times */
122+/* Why rc_is_bit_0_helper exists?
123+ * Because we want to always expose (rc->code < rc->bound) to optimizer.
124+ * Thus rc_is_bit_0 is always inlined, and rc_is_bit_0_helper is inlined
125+ * only if we compile for speed.
126+ */
127+static speed_inline uint32_t rc_is_bit_0_helper(rc_t *rc, uint16_t *p)
128 {
129 rc_normalize(rc);
130 rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
131- if (rc->code < rc->bound) {
132- rc->range = rc->bound;
133- *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
134- return 0;
135- }
136+ return rc->bound;
137+}
138+static ALWAYS_INLINE int rc_is_bit_0(rc_t *rc, uint16_t *p)
139+{
140+ uint32_t t = rc_is_bit_0_helper(rc, p);
141+ return rc->code < t;
142+}
143+
144+/* Called ~10 times, but very small, thus inlined */
145+static speed_inline void rc_update_bit_0(rc_t *rc, uint16_t *p)
146+{
147+ rc->range = rc->bound;
148+ *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
149+}
150+static speed_inline void rc_update_bit_1(rc_t *rc, uint16_t *p)
151+{
152 rc->range -= rc->bound;
153 rc->code -= rc->bound;
154 *p -= *p >> RC_MOVE_BITS;
155- return 1;
156 }
157
158 /* Called 4 times in unlzma loop */
159-static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
160+static int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
161 {
162- int ret = rc_is_bit_1(rc, p);
163- *symbol = *symbol * 2 + ret;
164- return ret;
165+ if (rc_is_bit_0(rc, p)) {
166+ rc_update_bit_0(rc, p);
167+ *symbol *= 2;
168+ return 0;
169+ } else {
170+ rc_update_bit_1(rc, p);
171+ *symbol = *symbol * 2 + 1;
172+ return 1;
173+ }
174 }
175
176 /* Called once */
177@@ -248,13 +266,13 @@
178 header.dst_size = SWAP_LE64(header.dst_size);
179
180 if (header.dict_size == 0)
181- header.dict_size++;
182+ header.dict_size = 1;
183
184 buffer = xmalloc(MIN(header.dst_size, header.dict_size));
185
186 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
187 p = xmalloc(num_probs * sizeof(*p));
188- num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
189+ num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
190 for (i = 0; i < num_probs; i++)
191 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
192
193@@ -264,8 +282,9 @@
194 int pos_state = (buffer_pos + global_pos) & pos_state_mask;
195
196 prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
197- if (!rc_is_bit_1(rc, prob)) {
198+ if (rc_is_bit_0(rc, prob)) {
199 mi = 1;
200+ rc_update_bit_0(rc, prob);
201 prob = (p + LZMA_LITERAL
202 + (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
203 + (previous_byte >> (8 - lc))
204@@ -321,21 +340,27 @@
205 int offset;
206 uint16_t *prob_len;
207
208+ rc_update_bit_1(rc, prob);
209 prob = p + LZMA_IS_REP + state;
210- if (!rc_is_bit_1(rc, prob)) {
211+ if (rc_is_bit_0(rc, prob)) {
212+ rc_update_bit_0(rc, prob);
213 rep3 = rep2;
214 rep2 = rep1;
215 rep1 = rep0;
216 state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
217 prob = p + LZMA_LEN_CODER;
218 } else {
219- prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
220- if (!rc_is_bit_1(rc, prob)) {
221+ rc_update_bit_1(rc, prob);
222+ prob = p + LZMA_IS_REP_G0 + state;
223+ if (rc_is_bit_0(rc, prob)) {
224+ rc_update_bit_0(rc, prob);
225 prob = (p + LZMA_IS_REP_0_LONG
226 + (state << LZMA_NUM_POS_BITS_MAX)
227 + pos_state
228 );
229- if (!rc_is_bit_1(rc, prob)) {
230+ if (rc_is_bit_0(rc, prob)) {
231+ rc_update_bit_0(rc, prob);
232+
233 state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
234 #if ENABLE_FEATURE_LZMA_FAST
235 pos = buffer_pos - rep0;
236@@ -347,16 +372,25 @@
237 len = 1;
238 goto string;
239 #endif
240+ } else {
241+ rc_update_bit_1(rc, prob);
242 }
243 } else {
244 uint32_t distance;
245
246- prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
247- distance = rep1;
248- if (rc_is_bit_1(rc, prob)) {
249- prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
250- distance = rep2;
251- if (rc_is_bit_1(rc, prob)) {
252+ rc_update_bit_1(rc, prob);
253+ prob = p + LZMA_IS_REP_G1 + state;
254+ if (rc_is_bit_0(rc, prob)) {
255+ rc_update_bit_0(rc, prob);
256+ distance = rep1;
257+ } else {
258+ rc_update_bit_1(rc, prob);
259+ prob = p + LZMA_IS_REP_G2 + state;
260+ if (rc_is_bit_0(rc, prob)) {
261+ rc_update_bit_0(rc, prob);
262+ distance = rep2;
263+ } else {
264+ rc_update_bit_1(rc, prob);
265 distance = rep3;
266 rep3 = rep2;
267 }
268@@ -370,20 +404,24 @@
269 }
270
271 prob_len = prob + LZMA_LEN_CHOICE;
272- if (!rc_is_bit_1(rc, prob_len)) {
273- prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
274- + (pos_state << LZMA_LEN_NUM_LOW_BITS);
275+ if (rc_is_bit_0(rc, prob_len)) {
276+ rc_update_bit_0(rc, prob_len);
277+ prob_len = (prob + LZMA_LEN_LOW
278+ + (pos_state << LZMA_LEN_NUM_LOW_BITS));
279 offset = 0;
280 num_bits = LZMA_LEN_NUM_LOW_BITS;
281 } else {
282- prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
283- if (!rc_is_bit_1(rc, prob_len)) {
284- prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
285- + (pos_state << LZMA_LEN_NUM_MID_BITS);
286+ rc_update_bit_1(rc, prob_len);
287+ prob_len = prob + LZMA_LEN_CHOICE_2;
288+ if (rc_is_bit_0(rc, prob_len)) {
289+ rc_update_bit_0(rc, prob_len);
290+ prob_len = (prob + LZMA_LEN_MID
291+ + (pos_state << LZMA_LEN_NUM_MID_BITS));
292 offset = 1 << LZMA_LEN_NUM_LOW_BITS;
293 num_bits = LZMA_LEN_NUM_MID_BITS;
294 } else {
295- prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
296+ rc_update_bit_1(rc, prob_len);
297+ prob_len = prob + LZMA_LEN_HIGH;
298 offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
299 + (1 << LZMA_LEN_NUM_MID_BITS));
300 num_bits = LZMA_LEN_NUM_HIGH_BITS;
301@@ -400,20 +438,19 @@
302 ((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
303 LZMA_NUM_LEN_TO_POS_STATES - 1)
304 << LZMA_NUM_POS_SLOT_BITS);
305- rc_bit_tree_decode(rc, prob,
306- LZMA_NUM_POS_SLOT_BITS, &pos_slot);
307- rep0 = pos_slot;
308+ rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
309+ &pos_slot);
310 if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
311 num_bits = (pos_slot >> 1) - 1;
312 rep0 = 2 | (pos_slot & 1);
313- prob = p + LZMA_ALIGN;
314 if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
315 rep0 <<= num_bits;
316- prob += LZMA_SPEC_POS - LZMA_ALIGN - 1 + rep0 - pos_slot;
317+ prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
318 } else {
319 num_bits -= LZMA_NUM_ALIGN_BITS;
320 while (num_bits--)
321 rep0 = (rep0 << 1) | rc_direct_bit(rc);
322+ prob = p + LZMA_ALIGN;
323 rep0 <<= LZMA_NUM_ALIGN_BITS;
324 num_bits = LZMA_NUM_ALIGN_BITS;
325 }
326@@ -424,7 +461,8 @@
327 rep0 |= i;
328 i <<= 1;
329 }
330- }
331+ } else
332+ rep0 = pos_slot;
333 if (++rep0 == 0)
334 break;
335 }
336diff -ru busybox-1.15.0-ori/modutils/modprobe-small.c busybox-1.15.0/modutils/modprobe-small.c
337--- busybox-1.15.0-ori/modutils/modprobe-small.c 2009-08-21 00:26:14.000000000 +0200
338+++ busybox-1.15.0/modutils/modprobe-small.c 2009-09-07 13:50:46.922667475 +0200
339@@ -218,6 +218,7 @@
340 bksp(); /* remove last ' ' */
341 appendc('\0');
342 info->aliases = copy_stringbuf();
343+ replace(info->aliases, '-', '_');
344
345 /* "dependency1 depandency2" */
346 reset_stringbuf();
347diff -ru busybox-1.15.0-ori/networking/inetd.c busybox-1.15.0/networking/inetd.c
348--- busybox-1.15.0-ori/networking/inetd.c 2009-08-21 00:26:14.000000000 +0200
349+++ busybox-1.15.0/networking/inetd.c 2009-09-07 13:50:46.922667475 +0200
350@@ -1031,10 +1031,10 @@
351 continue;
352 /* One of our "wait" services */
353 if (WIFEXITED(status) && WEXITSTATUS(status))
354- bb_error_msg("%s: exit status 0x%x",
355+ bb_error_msg("%s: exit status %u",
356 sep->se_program, WEXITSTATUS(status));
357 else if (WIFSIGNALED(status))
358- bb_error_msg("%s: exit signal 0x%x",
359+ bb_error_msg("%s: exit signal %u",
360 sep->se_program, WTERMSIG(status));
361 sep->se_wait = 1;
362 add_fd_to_set(sep->se_fd);
363@@ -1119,7 +1119,12 @@
364 else
365 bb_sanitize_stdio();
366 if (!(opt & 4)) {
367- openlog(applet_name, LOG_PID, LOG_DAEMON);
368+ /* LOG_NDELAY: connect to syslog daemon NOW.
369+ * Otherwise, we may open syslog socket
370+ * in vforked child, making opened fds and syslog()
371+ * internal state inconsistent.
372+ * This was observed to leak file descriptors. */
373+ openlog(applet_name, LOG_PID | LOG_NDELAY, LOG_DAEMON);
374 logmode = LOGMODE_SYSLOG;
375 }
376
377@@ -1355,17 +1360,23 @@
378 if (rlim_ofile.rlim_cur != rlim_ofile_cur)
379 if (setrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0)
380 bb_perror_msg("setrlimit");
381- closelog();
382+
383+ /* closelog(); - WRONG. we are after vfork,
384+ * this may confuse syslog() internal state.
385+ * Let's hope libc sets syslog fd to CLOEXEC...
386+ */
387 xmove_fd(ctrl, STDIN_FILENO);
388 xdup2(STDIN_FILENO, STDOUT_FILENO);
389 /* manpages of inetd I managed to find either say
390 * that stderr is also redirected to the network,
391 * or do not talk about redirection at all (!) */
392- xdup2(STDIN_FILENO, STDERR_FILENO);
393- /* NB: among others, this loop closes listening socket
394+ if (!sep->se_wait) /* only for usual "tcp nowait" */
395+ xdup2(STDIN_FILENO, STDERR_FILENO);
396+ /* NB: among others, this loop closes listening sockets
397 * for nowait stream children */
398 for (sep2 = serv_list; sep2; sep2 = sep2->se_next)
399- maybe_close(sep2->se_fd);
400+ if (sep2->se_fd != ctrl)
401+ maybe_close(sep2->se_fd);
402 sigaction_set(SIGPIPE, &saved_pipe_handler);
403 restore_sigmask(&omask);
404 BB_EXECVP(sep->se_program, sep->se_argv);
405diff -ru busybox-1.15.0-ori/shell/hush.c busybox-1.15.0/shell/hush.c
406--- busybox-1.15.0-ori/shell/hush.c 2009-08-21 00:26:14.000000000 +0200
407+++ busybox-1.15.0/shell/hush.c 2009-09-07 13:50:46.922667475 +0200
408@@ -58,7 +58,7 @@
409 * TODOs:
410 * grep for "TODO" and fix (some of them are easy)
411 * builtins: ulimit
412- * special variables (PWD etc)
413+ * special variables (done: PWD)
414 * follow IFS rules more precisely, including update semantics
415 * export builtin should be special, its arguments are assignments
416 * and therefore expansion of them should be "one-word" expansion:
417@@ -1432,6 +1432,13 @@
418 return 0;
419 }
420
421+/* Used at startup and after each cd */
422+static void set_pwd_var(int exp)
423+{
424+ set_local_var(xasprintf("PWD=%s", get_cwd(/*force:*/ 1)),
425+ /*exp:*/ exp, /*lvl:*/ 0, /*ro:*/ 0);
426+}
427+
428 static int unset_local_var_len(const char *name, int name_len)
429 {
430 struct variable *cur;
431@@ -1604,6 +1611,9 @@
432 /* Set up the prompt */
433 if (promptmode == 0) { /* PS1 */
434 free((char*)G.PS1);
435+ /* bash uses $PWD value, even if it is set by user.
436+ * It uses current dir only if PWD is unset.
437+ * We always use current dir. */
438 G.PS1 = xasprintf("%s %c ", get_cwd(0), (geteuid() != 0) ? '$' : '#');
439 prompt_str = G.PS1;
440 } else
441@@ -6432,8 +6442,49 @@
442 }
443 e++;
444 }
445+ /* reinstate HUSH_VERSION */
446 debug_printf_env("putenv '%s'\n", hush_version_str);
447- putenv((char *)hush_version_str); /* reinstate HUSH_VERSION */
448+ putenv((char *)hush_version_str);
449+
450+ /* Export PWD */
451+ set_pwd_var(/*exp:*/ 1);
452+ /* bash also exports SHLVL and _,
453+ * and sets (but doesn't export) the following variables:
454+ * BASH=/bin/bash
455+ * BASH_VERSINFO=([0]="3" [1]="2" [2]="0" [3]="1" [4]="release" [5]="i386-pc-linux-gnu")
456+ * BASH_VERSION='3.2.0(1)-release'
457+ * HOSTTYPE=i386
458+ * MACHTYPE=i386-pc-linux-gnu
459+ * OSTYPE=linux-gnu
460+ * HOSTNAME=<xxxxxxxxxx>
461+ * PPID=<NNNNN>
462+ * EUID=<NNNNN>
463+ * UID=<NNNNN>
464+ * GROUPS=()
465+ * LINES=<NNN>
466+ * COLUMNS=<NNN>
467+ * BASH_ARGC=()
468+ * BASH_ARGV=()
469+ * BASH_LINENO=()
470+ * BASH_SOURCE=()
471+ * DIRSTACK=()
472+ * PIPESTATUS=([0]="0")
473+ * HISTFILE=/<xxx>/.bash_history
474+ * HISTFILESIZE=500
475+ * HISTSIZE=500
476+ * MAILCHECK=60
477+ * PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.
478+ * SHELL=/bin/bash
479+ * SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
480+ * TERM=dumb
481+ * OPTERR=1
482+ * OPTIND=1
483+ * IFS=$' \t\n'
484+ * PS1='\s-\v\$ '
485+ * PS2='> '
486+ * PS4='+ '
487+ */
488+
489 #if ENABLE_FEATURE_EDITING
490 G.line_input_state = new_line_input_t(FOR_SHELL);
491 #endif
492@@ -6816,7 +6867,11 @@
493 bb_perror_msg("cd: %s", newdir);
494 return EXIT_FAILURE;
495 }
496- get_cwd(1);
497+ /* Read current dir (get_cwd(1) is inside) and set PWD.
498+ * Note: do not enforce exporting. If PWD was unset or unexported,
499+ * set it again, but do not export. bash does the same.
500+ */
501+ set_pwd_var(/*exp:*/ 0);
502 return EXIT_SUCCESS;
503 }
504
Note: See TracBrowser for help on using the repository browser.