aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-01-13 09:11:24 +0000
committerRon Yorston <rmy@pobox.com>2014-01-13 09:11:24 +0000
commite6edcba4f2fc20a3e9db75ebe82d7a71094fe17c (patch)
treeaf786c447cae6ca59e195b31fbae442c0b42d198
parent215f730e98215bff8dfacafdaa70e4a11395ad53 (diff)
parent0f592d7fb94c5887528d0ee24020c2225ab71c28 (diff)
downloadbusybox-w32-e6edcba4f2fc20a3e9db75ebe82d7a71094fe17c.tar.gz
busybox-w32-e6edcba4f2fc20a3e9db75ebe82d7a71094fe17c.tar.bz2
busybox-w32-e6edcba4f2fc20a3e9db75ebe82d7a71094fe17c.zip
Merge branch 'busybox' into merge
Conflicts: include/platform.h scripts/basic/fixdep.c
-rw-r--r--Makefile.help4
-rw-r--r--archival/libarchive/get_header_tar.c4
-rw-r--r--archival/libarchive/open_transformer.c23
-rw-r--r--coreutils/Config.src3
-rw-r--r--coreutils/chown.c2
-rw-r--r--coreutils/tail.c7
-rw-r--r--findutils/find.c21
-rw-r--r--findutils/grep.c28
-rw-r--r--include/platform.h28
-rw-r--r--libbb/lineedit.c2
-rw-r--r--libbb/speed_table.c5
-rw-r--r--networking/isrv.h26
-rw-r--r--networking/isrv_identd.c38
-rw-r--r--networking/ntpd.c2
-rw-r--r--networking/ping.c19
-rw-r--r--scripts/basic/docproc.c2
-rw-r--r--scripts/basic/fixdep.c2
-rwxr-xr-xscripts/gen_build_files.sh14
-rw-r--r--shell/ash.c2
-rwxr-xr-xtestsuite/find.tests22
-rwxr-xr-xtestsuite/grep.tests12
21 files changed, 191 insertions, 75 deletions
diff --git a/Makefile.help b/Makefile.help
index 119dd6f89..6a23e2a80 100644
--- a/Makefile.help
+++ b/Makefile.help
@@ -21,10 +21,6 @@ help:
21 @echo ' defconfig - set .config to largest generic configuration' 21 @echo ' defconfig - set .config to largest generic configuration'
22 @echo ' menuconfig - interactive curses-based configurator' 22 @echo ' menuconfig - interactive curses-based configurator'
23 @echo ' oldconfig - resolve any unresolved symbols in .config' 23 @echo ' oldconfig - resolve any unresolved symbols in .config'
24 @echo ' hosttools - build sed for the host.'
25 @echo ' You can use these commands if the commands on the host'
26 @echo ' is unusable. Afterwards use it like:'
27 @echo ' make SED="$(objtree)/sed"'
28 @$(if $(boards), \ 24 @$(if $(boards), \
29 $(foreach b, $(boards), \ 25 $(foreach b, $(boards), \
30 printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ 26 printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index 32f842095..54d910431 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -115,7 +115,9 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
115 */ 115 */
116 p += len; 116 p += len;
117 sz -= len; 117 sz -= len;
118 if ((int)sz < 0 118 if (
119 /** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
120 (int)(sz|len) < 0 /* this works */
119 || len == 0 121 || len == 0
120 || errno != EINVAL 122 || errno != EINVAL
121 || *end != ' ' 123 || *end != ' '
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index c4e02f0f7..b11bf46af 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -184,27 +184,26 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
184 184
185int FAST_FUNC open_zipped(const char *fname) 185int FAST_FUNC open_zipped(const char *fname)
186{ 186{
187 char *sfx;
188 int fd; 187 int fd;
189 188
190 fd = open(fname, O_RDONLY); 189 fd = open(fname, O_RDONLY);
191 if (fd < 0) 190 if (fd < 0)
192 return fd; 191 return fd;
193 192
194 sfx = strrchr(fname, '.'); 193 if (ENABLE_FEATURE_SEAMLESS_LZMA) {
195 if (sfx) { 194 /* .lzma has no header/signature, can only detect it by extension */
196 sfx++; 195 char *sfx = strrchr(fname, '.');
197 if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0) 196 if (sfx && strcmp(sfx+1, "lzma") == 0) {
198 /* .lzma has no header/signature, just trust it */
199 open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma"); 197 open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
200 else 198 return fd;
201 if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
202 || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
203 || (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
204 ) {
205 setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
206 } 199 }
207 } 200 }
201 if ((ENABLE_FEATURE_SEAMLESS_GZ)
202 || (ENABLE_FEATURE_SEAMLESS_BZ2)
203 || (ENABLE_FEATURE_SEAMLESS_XZ)
204 ) {
205 setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
206 }
208 207
209 return fd; 208 return fd;
210} 209}
diff --git a/coreutils/Config.src b/coreutils/Config.src
index b5701217e..ef14be471 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -635,12 +635,13 @@ config FEATURE_FANCY_TAIL
635 default y 635 default y
636 depends on TAIL 636 depends on TAIL
637 help 637 help
638 The options (-q, -s, and -v) are provided by GNU tail, but 638 The options (-q, -s, -v and -F) are provided by GNU tail, but
639 are not specific in the SUSv3 standard. 639 are not specific in the SUSv3 standard.
640 640
641 -q Never output headers giving file names 641 -q Never output headers giving file names
642 -s SEC Wait SEC seconds between reads with -f 642 -s SEC Wait SEC seconds between reads with -f
643 -v Always output headers giving file names 643 -v Always output headers giving file names
644 -F Same as -f, but keep retrying
644 645
645config TEE 646config TEE
646 bool "tee" 647 bool "tee"
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 1a9127622..cb07bbcbb 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -16,10 +16,10 @@
16//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n" 16//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
17//usage: "\n -R Recurse" 17//usage: "\n -R Recurse"
18//usage: "\n -h Affect symlinks instead of symlink targets" 18//usage: "\n -h Affect symlinks instead of symlink targets"
19//usage: IF_DESKTOP(
19//usage: "\n -L Traverse all symlinks to directories" 20//usage: "\n -L Traverse all symlinks to directories"
20//usage: "\n -H Traverse symlinks on command line only" 21//usage: "\n -H Traverse symlinks on command line only"
21//usage: "\n -P Don't traverse symlinks (default)" 22//usage: "\n -P Don't traverse symlinks (default)"
22//usage: IF_DESKTOP(
23//usage: "\n -c List changed files" 23//usage: "\n -c List changed files"
24//usage: "\n -v List all files" 24//usage: "\n -v List all files"
25//usage: "\n -f Hide errors" 25//usage: "\n -f Hide errors"
diff --git a/coreutils/tail.c b/coreutils/tail.c
index eab502beb..e352ab627 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -32,15 +32,14 @@
32//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n" 32//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n"
33//usage: "With more than one FILE, precede each with a filename header.\n" 33//usage: "With more than one FILE, precede each with a filename header.\n"
34//usage: "\n -f Print data as file grows" 34//usage: "\n -f Print data as file grows"
35//usage: IF_FEATURE_FANCY_TAIL( 35//usage: "\n -c [+]N[kbm] Print last N bytes"
36//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
37//usage: )
38//usage: "\n -n N[kbm] Print last N lines" 36//usage: "\n -n N[kbm] Print last N lines"
39//usage: "\n -n +N[kbm] Start on Nth line and print the rest" 37//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
40//usage: IF_FEATURE_FANCY_TAIL( 38//usage: IF_FEATURE_FANCY_TAIL(
41//usage: "\n -c [+]N[kbm] Print last N bytes"
42//usage: "\n -q Never print headers" 39//usage: "\n -q Never print headers"
40//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
43//usage: "\n -v Always print headers" 41//usage: "\n -v Always print headers"
42//usage: "\n -F Same as -f, but keep retrying"
44//usage: "\n" 43//usage: "\n"
45//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)." 44//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
46//usage: ) 45//usage: )
diff --git a/findutils/find.c b/findutils/find.c
index 53d8239c7..5d5e24bfb 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -1291,9 +1291,27 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1291int find_main(int argc UNUSED_PARAM, char **argv) 1291int find_main(int argc UNUSED_PARAM, char **argv)
1292{ 1292{
1293 int i, firstopt, status = EXIT_SUCCESS; 1293 int i, firstopt, status = EXIT_SUCCESS;
1294 char **past_HLP, *saved;
1294 1295
1295 INIT_G(); 1296 INIT_G();
1296 1297
1298 /* "find -type f" + getopt("+HLP") => disaster.
1299 * Need to avoid getopt running into a non-HLP option.
1300 * Do this by temporarily storing NULL there:
1301 */
1302 past_HLP = argv;
1303 for (;;) {
1304 saved = *++past_HLP;
1305 if (!saved)
1306 break;
1307 if (saved[0] != '-')
1308 break;
1309 if (!saved[1])
1310 break; /* it is "-" */
1311 if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
1312 break;
1313 }
1314 *past_HLP = NULL;
1297 /* "+": stop on first non-option */ 1315 /* "+": stop on first non-option */
1298 i = getopt32(argv, "+HLP"); 1316 i = getopt32(argv, "+HLP");
1299 if (i & (1<<0)) 1317 if (i & (1<<0))
@@ -1301,7 +1319,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
1301 if (i & (1<<1)) 1319 if (i & (1<<1))
1302 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; 1320 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
1303 /* -P is default and is ignored */ 1321 /* -P is default and is ignored */
1304 argv += optind; 1322 argv = past_HLP; /* same result as "argv += optind;" */
1323 *past_HLP = saved;
1305 1324
1306 for (firstopt = 0; argv[firstopt]; firstopt++) { 1325 for (firstopt = 0; argv[firstopt]; firstopt++) {
1307 if (argv[firstopt][0] == '-') 1326 if (argv[firstopt][0] == '-')
diff --git a/findutils/grep.c b/findutils/grep.c
index 5bbe61100..f5f95cb95 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -381,6 +381,9 @@ static int grep_file(FILE *file)
381 opt_f_not_found: ; 381 opt_f_not_found: ;
382 } 382 }
383 } else { 383 } else {
384#if ENABLE_EXTRA_COMPAT
385 unsigned start_pos;
386#endif
384 char *match_at; 387 char *match_at;
385 388
386 if (!(gl->flg_mem_alocated_compiled & COMPILED)) { 389 if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
@@ -397,15 +400,18 @@ static int grep_file(FILE *file)
397#if !ENABLE_EXTRA_COMPAT 400#if !ENABLE_EXTRA_COMPAT
398 gl->matched_range.rm_so = 0; 401 gl->matched_range.rm_so = 0;
399 gl->matched_range.rm_eo = 0; 402 gl->matched_range.rm_eo = 0;
403#else
404 start_pos = 0;
400#endif 405#endif
401 match_at = line; 406 match_at = line;
402 opt_w_again: 407 opt_w_again:
408//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
403 if ( 409 if (
404#if !ENABLE_EXTRA_COMPAT 410#if !ENABLE_EXTRA_COMPAT
405 regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0 411 regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
406#else 412#else
407 re_search(&gl->compiled_regex, match_at, line_len, 413 re_search(&gl->compiled_regex, match_at, line_len,
408 /*start:*/ 0, /*range:*/ line_len, 414 start_pos, /*range:*/ line_len,
409 &gl->matched_range) >= 0 415 &gl->matched_range) >= 0
410#endif 416#endif
411 ) { 417 ) {
@@ -424,8 +430,24 @@ static int grep_file(FILE *file)
424 if (!c || (!isalnum(c) && c != '_')) { 430 if (!c || (!isalnum(c) && c != '_')) {
425 found = 1; 431 found = 1;
426 } else { 432 } else {
427 match_at += gl->matched_range.rm_eo; 433 /*
428 goto opt_w_again; 434 * Why check gl->matched_range.rm_eo?
435 * Zero-length match makes -w skip the line:
436 * "echo foo | grep ^" prints "foo",
437 * "echo foo | grep -w ^" prints nothing.
438 * Without such check, we can loop forever.
439 */
440#if !ENABLE_EXTRA_COMPAT
441 if (gl->matched_range.rm_eo != 0) {
442 match_at += gl->matched_range.rm_eo;
443 goto opt_w_again;
444 }
445#else
446 if (gl->matched_range.rm_eo > start_pos) {
447 start_pos = gl->matched_range.rm_eo;
448 goto opt_w_again;
449 }
450#endif
429 } 451 }
430 } 452 }
431 } 453 }
diff --git a/include/platform.h b/include/platform.h
index e52dd7ba5..515ef031f 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -402,10 +402,6 @@ typedef unsigned smalluint;
402# undef HAVE_STRVERSCMP 402# undef HAVE_STRVERSCMP
403#endif 403#endif
404 404
405#if defined(__dietlibc__)
406# undef HAVE_STRCHRNUL
407#endif
408
409#if ENABLE_PLATFORM_MINGW32 405#if ENABLE_PLATFORM_MINGW32
410# undef HAVE_DPRINTF 406# undef HAVE_DPRINTF
411# undef HAVE_GETLINE 407# undef HAVE_GETLINE
@@ -453,7 +449,7 @@ typedef unsigned smalluint;
453/* These BSD-derived OSes share many similarities */ 449/* These BSD-derived OSes share many similarities */
454#if (defined __digital__ && defined __unix__) \ 450#if (defined __digital__ && defined __unix__) \
455 || defined __APPLE__ \ 451 || defined __APPLE__ \
456 || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ 452 || defined __OpenBSD__ || defined __NetBSD__
457# undef HAVE_CLEARENV 453# undef HAVE_CLEARENV
458# undef HAVE_FDATASYNC 454# undef HAVE_FDATASYNC
459# undef HAVE_GETLINE 455# undef HAVE_GETLINE
@@ -468,10 +464,30 @@ typedef unsigned smalluint;
468# undef HAVE_UNLOCKED_LINE_OPS 464# undef HAVE_UNLOCKED_LINE_OPS
469#endif 465#endif
470 466
471#if defined(__FreeBSD__) || defined(__APPLE__) 467#if defined(__dietlibc__)
468# undef HAVE_STRCHRNUL
469#endif
470
471#if defined(__APPLE__)
472# undef HAVE_STRCHRNUL 472# undef HAVE_STRCHRNUL
473#endif 473#endif
474 474
475#if defined(__FreeBSD__)
476# undef HAVE_CLEARENV
477# undef HAVE_FDATASYNC
478# undef HAVE_MNTENT_H
479# undef HAVE_PTSNAME_R
480# undef HAVE_SYS_STATFS_H
481# undef HAVE_SIGHANDLER_T
482# undef HAVE_STRVERSCMP
483# undef HAVE_XTABS
484# undef HAVE_UNLOCKED_LINE_OPS
485# include <osreldate.h>
486# if __FreeBSD_version < 1000029
487# undef HAVE_STRCHRNUL /* FreeBSD added strchrnul() between 1000028 and 1000029 */
488# endif
489#endif
490
475#if defined(__NetBSD__) 491#if defined(__NetBSD__)
476# define HAVE_GETLINE 1 /* Recent NetBSD versions have getline() */ 492# define HAVE_GETLINE 1 /* Recent NetBSD versions have getline() */
477#endif 493#endif
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 38d4c598d..4bb1ab783 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1267,7 +1267,9 @@ line_input_t* FAST_FUNC new_line_input_t(int flags)
1267{ 1267{
1268 line_input_t *n = xzalloc(sizeof(*n)); 1268 line_input_t *n = xzalloc(sizeof(*n));
1269 n->flags = flags; 1269 n->flags = flags;
1270#if MAX_HISTORY > 0
1270 n->max_history = MAX_HISTORY; 1271 n->max_history = MAX_HISTORY;
1272#endif
1271 return n; 1273 return n;
1272} 1274}
1273 1275
diff --git a/libbb/speed_table.c b/libbb/speed_table.c
index 45159f1f3..174d531b2 100644
--- a/libbb/speed_table.c
+++ b/libbb/speed_table.c
@@ -10,7 +10,12 @@
10#include "libbb.h" 10#include "libbb.h"
11 11
12struct speed_map { 12struct speed_map {
13#if defined __FreeBSD__
14 /* On FreeBSD, B<num> constants don't fit into a short */
15 unsigned speed;
16#else
13 unsigned short speed; 17 unsigned short speed;
18#endif
14 unsigned short value; 19 unsigned short value;
15}; 20};
16 21
diff --git a/networking/isrv.h b/networking/isrv.h
index 4c7e01dd1..7b12e0edd 100644
--- a/networking/isrv.h
+++ b/networking/isrv.h
@@ -23,7 +23,31 @@ int isrv_register_fd(isrv_state_t *state, int peer, int fd);
23void isrv_close_fd(isrv_state_t *state, int fd); 23void isrv_close_fd(isrv_state_t *state, int fd);
24int isrv_register_peer(isrv_state_t *state, void *param); 24int isrv_register_peer(isrv_state_t *state, void *param);
25 25
26/* driver */ 26/* Driver:
27 *
28 * Select on listen_fd for <linger_timeout> (or forever if 0).
29 *
30 * If we time out and we have no peers, exit.
31 * If we have peers, call do_timeout(peer_param),
32 * if it returns !0, peer is removed.
33 *
34 * If listen_fd is active, accept new connection ("peer"),
35 * call new_peer() on it, and if it returns 0,
36 * add it to fds to select on.
37 * Now, select will wait for <timeout>, not <linger_timeout>
38 * (as long as we have more than zero peers).
39 *
40 * If a peer's fd is active, we call do_rd() on it if read
41 * bit was set, and then do_wr() if write bit was also set.
42 * If either returns !0, peer is removed.
43 * Reaching this place also resets timeout counter for this peer.
44 *
45 * Note that peer must indicate that he wants to be selected
46 * for read and/or write using isrv_want_rd()/isrv_want_wr()
47 * [can be called in new_peer() or in do_rd()/do_wr()].
48 * If it never wants to be selected for write, do_wr()
49 * will never be called (can be NULL).
50 */
27void isrv_run( 51void isrv_run(
28 int listen_fd, 52 int listen_fd,
29 int (*new_peer)(isrv_state_t *state, int fd), 53 int (*new_peer)(isrv_state_t *state, int fd),
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index a41405c33..252c8aba9 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -25,8 +25,7 @@ enum { TIMEOUT = 20 };
25 25
26typedef struct identd_buf_t { 26typedef struct identd_buf_t {
27 int pos; 27 int pos;
28 int fd_flag; 28 char buf[64 - sizeof(int)];
29 char buf[64 - 2*sizeof(int)];
30} identd_buf_t; 29} identd_buf_t;
31 30
32#define bogouser bb_common_bufsiz1 31#define bogouser bb_common_bufsiz1
@@ -42,7 +41,7 @@ static int new_peer(isrv_state_t *state, int fd)
42 if (isrv_register_fd(state, peer, fd) < 0) 41 if (isrv_register_fd(state, peer, fd) < 0)
43 return peer; /* failure, unregister peer */ 42 return peer; /* failure, unregister peer */
44 43
45 buf->fd_flag = fcntl(fd, F_GETFL) | O_NONBLOCK; 44 ndelay_on(fd);
46 isrv_want_rd(state, fd); 45 isrv_want_rd(state, fd);
47 return 0; 46 return 0;
48} 47}
@@ -51,19 +50,16 @@ static int do_rd(int fd, void **paramp)
51{ 50{
52 identd_buf_t *buf = *paramp; 51 identd_buf_t *buf = *paramp;
53 char *cur, *p; 52 char *cur, *p;
54 int retval = 0; /* session is ok (so far) */
55 int sz; 53 int sz;
56 54
57 cur = buf->buf + buf->pos; 55 cur = buf->buf + buf->pos;
58 56
59 if (buf->fd_flag & O_NONBLOCK) 57 sz = safe_read(fd, cur, sizeof(buf->buf) - 1 - buf->pos);
60 fcntl(fd, F_SETFL, buf->fd_flag);
61 sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos);
62 58
63 if (sz < 0) { 59 if (sz < 0) {
64 if (errno != EAGAIN) 60 if (errno != EAGAIN)
65 goto term; /* terminate this session if !EAGAIN */ 61 goto term;
66 goto ok; 62 return 0; /* "session is ok" */
67 } 63 }
68 64
69 buf->pos += sz; 65 buf->pos += sz;
@@ -71,19 +67,22 @@ static int do_rd(int fd, void **paramp)
71 p = strpbrk(cur, "\r\n"); 67 p = strpbrk(cur, "\r\n");
72 if (p) 68 if (p)
73 *p = '\0'; 69 *p = '\0';
74 if (!p && sz && buf->pos <= (int)sizeof(buf->buf)) 70 if (!p && sz)
75 goto ok; 71 return 0; /* "session is ok" */
72
76 /* Terminate session. If we are in server mode, then 73 /* Terminate session. If we are in server mode, then
77 * fd is still in nonblocking mode - we never block here */ 74 * fd is still in nonblocking mode - we never block here */
78 if (fd == 0) fd++; /* inetd mode? then write to fd 1 */ 75 if (fd == 0)
76 fd++; /* inetd mode? then write to fd 1 */
79 fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser); 77 fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser);
78 /*
79 * Why bother if we are going to close fd now anyway?
80 * if (server)
81 * ndelay_off(fd);
82 */
80 term: 83 term:
81 free(buf); 84 free(buf);
82 retval = 1; /* terminate */ 85 return 1; /* "terminate" */
83 ok:
84 if (buf->fd_flag & O_NONBLOCK)
85 fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK);
86 return retval;
87} 86}
88 87
89static int do_timeout(void **paramp UNUSED_PARAM) 88static int do_timeout(void **paramp UNUSED_PARAM)
@@ -95,10 +94,9 @@ static void inetd_mode(void)
95{ 94{
96 identd_buf_t *buf = xzalloc(sizeof(*buf)); 95 identd_buf_t *buf = xzalloc(sizeof(*buf));
97 /* buf->pos = 0; - xzalloc did it */ 96 /* buf->pos = 0; - xzalloc did it */
98 /* We do NOT want nonblocking I/O here! */
99 /* buf->fd_flag = 0; - xzalloc did it */
100 do 97 do
101 alarm(TIMEOUT); 98 alarm(TIMEOUT);
99 /* Note: we do NOT want nonblocking I/O here! */
102 while (do_rd(0, (void*)&buf) == 0); 100 while (do_rd(0, (void*)&buf) == 0);
103} 101}
104 102
@@ -120,7 +118,7 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv)
120 opt = getopt32(argv, "fiwb:", &bind_address); 118 opt = getopt32(argv, "fiwb:", &bind_address);
121 strcpy(bogouser, "nobody"); 119 strcpy(bogouser, "nobody");
122 if (argv[optind]) 120 if (argv[optind])
123 strncpy(bogouser, argv[optind], sizeof(bogouser)); 121 strncpy(bogouser, argv[optind], sizeof(bogouser) - 1);
124 122
125 /* Daemonize if no -f and no -i and no -w */ 123 /* Daemonize if no -f and no -i and no -w */
126 if (!(opt & OPT_fiw)) 124 if (!(opt & OPT_fiw))
diff --git a/networking/ntpd.c b/networking/ntpd.c
index ed83415b4..c4b018778 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -1445,6 +1445,8 @@ update_local_clock(peer_t *p)
1445 1445
1446 run_script("step", offset); 1446 run_script("step", offset);
1447 1447
1448 recv_time += offset;
1449
1448#if USING_INITIAL_FREQ_ESTIMATION 1450#if USING_INITIAL_FREQ_ESTIMATION
1449 if (G.discipline_state == STATE_NSET) { 1451 if (G.discipline_state == STATE_NSET) {
1450 set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); 1452 set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time);
diff --git a/networking/ping.c b/networking/ping.c
index 5d71fe8cc..5e4771f5a 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -168,22 +168,9 @@ create_icmp_socket(void)
168#endif 168#endif
169 sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */ 169 sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */
170 if (sock < 0) { 170 if (sock < 0) {
171 if (errno != EPERM) 171 if (errno == EPERM)
172 bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); 172 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
173#if defined(__linux__) || defined(__APPLE__) 173 bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);
174 /* We don't have root privileges. Try SOCK_DGRAM instead.
175 * Linux needs net.ipv4.ping_group_range for this to work.
176 * MacOSX allows ICMP_ECHO, ICMP_TSTAMP or ICMP_MASKREQ
177 */
178#if ENABLE_PING6
179 if (lsa->u.sa.sa_family == AF_INET6)
180 sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6);
181 else
182#endif
183 sock = socket(AF_INET, SOCK_DGRAM, 1); /* 1 == ICMP */
184 if (sock < 0)
185#endif
186 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
187 } 174 }
188 175
189 xmove_fd(sock, pingsock); 176 xmove_fd(sock, pingsock);
diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c
index b12569832..7f21443c1 100644
--- a/scripts/basic/docproc.c
+++ b/scripts/basic/docproc.c
@@ -39,7 +39,7 @@
39#include <limits.h> 39#include <limits.h>
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/wait.h> 41#include <sys/wait.h>
42#include <alloca.h> 42//bbox disabled: #include <alloca.h>
43 43
44/* exitstatus is used to keep track of any failing calls to kernel-doc, 44/* exitstatus is used to keep track of any failing calls to kernel-doc,
45 * but execution continues. */ 45 * but execution continues. */
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index b7f9e0c2f..f012551af 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -117,7 +117,7 @@
117#ifndef __MINGW32__ 117#ifndef __MINGW32__
118#include <arpa/inet.h> 118#include <arpa/inet.h>
119#endif 119#endif
120#include <alloca.h> 120//bbox disabled: #include <alloca.h>
121 121
122/* bbox: not needed 122/* bbox: not needed
123#define INT_CONF ntohl(0x434f4e46) 123#define INT_CONF ntohl(0x434f4e46)
diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh
index 0989b2fe5..e8fa831be 100755
--- a/scripts/gen_build_files.sh
+++ b/scripts/gen_build_files.sh
@@ -31,7 +31,12 @@ generate()
31 # copy stdin to stdout 31 # copy stdin to stdout
32 cat 32 cat
33 # print everything after INSERT line 33 # print everything after INSERT line
34 sed -n '/^INSERT$/ { :l; n; p; bl }' "${src}" 34 sed -n '/^INSERT$/ {
35 :l
36 n
37 p
38 bl
39 }' "${src}"
35 } >"${dst}.tmp" 40 } >"${dst}.tmp"
36 if ! cmp -s "${dst}" "${dst}.tmp"; then 41 if ! cmp -s "${dst}" "${dst}.tmp"; then
37 gen "${dst}" 42 gen "${dst}"
@@ -52,7 +57,12 @@ sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
52# We add line continuation backslash after each line, 57# We add line continuation backslash after each line,
53# and insert empty line before each line which doesn't start 58# and insert empty line before each line which doesn't start
54# with space or tab 59# with space or tab
55sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\@p' \ 60TAB="$(printf '\tX')"
61TAB="${TAB%X}"
62LF="$(printf '\nX')"
63LF="${LF%X}"
64sed -n -e 's@^//usage:\([ '"$TAB"'].*\)$@\1 \\@p' \
65 -e 's@^//usage:\([^ '"$TAB"'].*\)$@\'"$LF"'\1 \\@p' \
56 "$srctree"/*/*.c "$srctree"/*/*/*.c \ 66 "$srctree"/*/*.c "$srctree"/*/*/*.c \
57| generate \ 67| generate \
58 "$srctree/include/usage.src.h" \ 68 "$srctree/include/usage.src.h" \
diff --git a/shell/ash.c b/shell/ash.c
index d104aea1d..a916f2772 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13616,7 +13616,7 @@ init(void)
13616 setvar2("PPID", utoa(getppid())); 13616 setvar2("PPID", utoa(getppid()));
13617#if ENABLE_ASH_BASH_COMPAT 13617#if ENABLE_ASH_BASH_COMPAT
13618 p = lookupvar("SHLVL"); 13618 p = lookupvar("SHLVL");
13619 setvar2("SHLVL", utoa(p ? atoi(p) + 1 : 1)); 13619 setvar("SHLVL", utoa((p ? atoi(p) : 0) + 1), VEXPORT);
13620#endif 13620#endif
13621 p = lookupvar("PWD"); 13621 p = lookupvar("PWD");
13622 if (p) { 13622 if (p) {
diff --git a/testsuite/find.tests b/testsuite/find.tests
new file mode 100755
index 000000000..345d1e82e
--- /dev/null
+++ b/testsuite/find.tests
@@ -0,0 +1,22 @@
1#!/bin/sh
2
3# Copyright 2014 by Denys Vlasenko <vda.linux@googlemail.com>
4# Licensed under GPLv2, see file LICENSE in this source tree.
5
6. ./testing.sh
7
8# testing "description" "command" "result" "infile" "stdin"
9
10mkdir -p find.tempdir
11touch find.tempdir/testfile
12
13testing "find -type f" \
14 "cd find.tempdir && find -type f 2>&1" \
15 "./testfile\n" \
16 "" ""
17
18# testing "description" "command" "result" "infile" "stdin"
19
20rm -rf find.tempdir
21
22exit $FAILCOUNT
diff --git a/testsuite/grep.tests b/testsuite/grep.tests
index 64d99a905..412efffbb 100755
--- a/testsuite/grep.tests
+++ b/testsuite/grep.tests
@@ -147,6 +147,18 @@ testing "grep -w doesn't stop on 1st mismatch" \
147 "foop foo\n" \ 147 "foop foo\n" \
148 "" 148 ""
149 149
150testing "grep -w ^str doesn't match str not at the beginning" \
151 "grep -w ^str input" \
152 "" \
153 "strstr\n" \
154 ""
155
156testing "grep -w ^ doesn't hang" \
157 "grep -w ^ input" \
158 "" \
159 "anything\n" \
160 ""
161
150# testing "test name" "commands" "expected result" "file input" "stdin" 162# testing "test name" "commands" "expected result" "file input" "stdin"
151# file input will be file called "input" 163# file input will be file called "input"
152# test can create a file "actual" instead of writing to stdout 164# test can create a file "actual" instead of writing to stdout