From 432fbd7a1a71ab5a91a8cfab57fad74fda9389bb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 7 Jan 2014 14:09:47 +0100 Subject: platform.h: undef HAVE_STRCHRNUL only on correct versions of FreeBSD Signed-off-by: Denys Vlasenko --- include/platform.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/include/platform.h b/include/platform.h index cfc802907..2899a9093 100644 --- a/include/platform.h +++ b/include/platform.h @@ -385,10 +385,6 @@ typedef unsigned smalluint; # undef HAVE_STRVERSCMP #endif -#if defined(__dietlibc__) -# undef HAVE_STRCHRNUL -#endif - #if defined(__WATCOMC__) # undef HAVE_DPRINTF # undef HAVE_GETLINE @@ -434,10 +430,21 @@ typedef unsigned smalluint; # undef HAVE_UNLOCKED_LINE_OPS #endif -#if defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__dietlibc__) # undef HAVE_STRCHRNUL #endif +#if defined(__APPLE__) +# undef HAVE_STRCHRNUL +#endif + +#if defined(__FreeBSD__) +# include +# if __FreeBSD_version < 1000029 +# undef HAVE_STRCHRNUL +# endif +#endif + #if defined(__NetBSD__) # define HAVE_GETLINE 1 /* Recent NetBSD versions have getline() */ #endif -- cgit v1.2.3-55-g6feb From cd55f2d9332489432ba2b3093903949c6c2e3e33 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 7 Jan 2014 14:57:42 +0100 Subject: grep: fix two bugs with -w Unfortunately, with !EXTRA_COMPAT, "grep -w ^str" still erroneously matches "strstr". function old new delta grep_file 1499 1510 +11 Signed-off-by: Denys Vlasenko --- findutils/grep.c | 28 +++++++++++++++++++++++++--- testsuite/grep.tests | 12 ++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/findutils/grep.c b/findutils/grep.c index b8ad1bf8f..a7bc4ca9e 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -373,6 +373,9 @@ static int grep_file(FILE *file) opt_f_not_found: ; } } else { +#if ENABLE_EXTRA_COMPAT + unsigned start_pos; +#endif char *match_at; if (!(gl->flg_mem_alocated_compiled & COMPILED)) { @@ -389,15 +392,18 @@ static int grep_file(FILE *file) #if !ENABLE_EXTRA_COMPAT gl->matched_range.rm_so = 0; gl->matched_range.rm_eo = 0; +#else + start_pos = 0; #endif match_at = line; opt_w_again: +//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len); if ( #if !ENABLE_EXTRA_COMPAT regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0 #else re_search(&gl->compiled_regex, match_at, line_len, - /*start:*/ 0, /*range:*/ line_len, + start_pos, /*range:*/ line_len, &gl->matched_range) >= 0 #endif ) { @@ -416,8 +422,24 @@ static int grep_file(FILE *file) if (!c || (!isalnum(c) && c != '_')) { found = 1; } else { - match_at += gl->matched_range.rm_eo; - goto opt_w_again; + /* + * Why check gl->matched_range.rm_eo? + * Zero-length match makes -w skip the line: + * "echo foo | grep ^" prints "foo", + * "echo foo | grep -w ^" prints nothing. + * Without such check, we can loop forever. + */ +#if !ENABLE_EXTRA_COMPAT + if (gl->matched_range.rm_eo != 0) { + match_at += gl->matched_range.rm_eo; + goto opt_w_again; + } +#else + if (gl->matched_range.rm_eo > start_pos) { + start_pos = gl->matched_range.rm_eo; + goto opt_w_again; + } +#endif } } } 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" \ "foop foo\n" \ "" +testing "grep -w ^str doesn't match str not at the beginning" \ + "grep -w ^str input" \ + "" \ + "strstr\n" \ + "" + +testing "grep -w ^ doesn't hang" \ + "grep -w ^ input" \ + "" \ + "anything\n" \ + "" + # testing "test name" "commands" "expected result" "file input" "stdin" # file input will be file called "input" # test can create a file "actual" instead of writing to stdout -- cgit v1.2.3-55-g6feb From 5680e984516fa1fb3c16862fb747206da0edfbed Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 7 Jan 2014 16:12:48 +0100 Subject: ash: in bash compat mode, always export $SHLVL function old new delta ash_main 1437 1442 +5 Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index 71ef9a690..04ba447b1 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13014,7 +13014,7 @@ init(void) setvar2("PPID", utoa(getppid())); #if ENABLE_ASH_BASH_COMPAT p = lookupvar("SHLVL"); - setvar2("SHLVL", utoa(p ? atoi(p) + 1 : 1)); + setvar("SHLVL", utoa((p ? atoi(p) : 0) + 1), VEXPORT); #endif p = lookupvar("PWD"); if (p) { -- cgit v1.2.3-55-g6feb From 8e0ad2647a9725f189ad880b437619667e81343c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Jan 2014 15:10:54 +0100 Subject: Another FreeBSD fix from Matthias Andree Signed-off-by: Denys Vlasenko --- include/platform.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/platform.h b/include/platform.h index 2899a9093..bd11ad69a 100644 --- a/include/platform.h +++ b/include/platform.h @@ -415,7 +415,7 @@ typedef unsigned smalluint; /* These BSD-derived OSes share many similarities */ #if (defined __digital__ && defined __unix__) \ || defined __APPLE__ \ - || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ + || defined __OpenBSD__ || defined __NetBSD__ # undef HAVE_CLEARENV # undef HAVE_FDATASYNC # undef HAVE_GETLINE @@ -439,9 +439,18 @@ typedef unsigned smalluint; #endif #if defined(__FreeBSD__) -# include +# undef HAVE_CLEARENV +# undef HAVE_FDATASYNC +# undef HAVE_MNTENT_H +# undef HAVE_PTSNAME_R +# undef HAVE_SYS_STATFS_H +# undef HAVE_SIGHANDLER_T +# undef HAVE_STRVERSCMP +# undef HAVE_XTABS +# undef HAVE_UNLOCKED_LINE_OPS +# include # if __FreeBSD_version < 1000029 -# undef HAVE_STRCHRNUL +# undef HAVE_STRCHRNUL /* FreeBSD added strchrnul() between 1000028 and 1000029 */ # endif #endif -- cgit v1.2.3-55-g6feb From 96f92a1afac1599cc5f6128e7e9a43bdab220bc8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Jan 2014 15:25:20 +0100 Subject: libbb: FreeBSD fix for B baud rate constants not fitting into a short. Signed-off-by: Denys Vlasenko --- libbb/speed_table.c | 5 +++++ 1 file changed, 5 insertions(+) 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 @@ #include "libbb.h" struct speed_map { +#if defined __FreeBSD__ + /* On FreeBSD, B constants don't fit into a short */ + unsigned speed; +#else unsigned short speed; +#endif unsigned short value; }; -- cgit v1.2.3-55-g6feb From cb7611385c5ec7bc951d9be24a0ccbe8d89d2e4f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Jan 2014 17:17:52 +0100 Subject: ntpd: adjust last packet's recv time after a step Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 2 ++ 1 file changed, 2 insertions(+) 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) run_script("step", offset); + recv_time += offset; + #if USING_INITIAL_FREQ_ESTIMATION if (G.discipline_state == STATE_NSET) { set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); -- cgit v1.2.3-55-g6feb From f2743a5b0046069104c3afd9b14091dfa71690a4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 11:02:46 +0100 Subject: build system: stop including alloca.h, stdlib.h provides it Signed-off-by: Denys Vlasenko --- scripts/basic/docproc.c | 2 +- scripts/basic/fixdep.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 @@ #include #include #include -#include +//bbox disabled: #include /* exitstatus is used to keep track of any failing calls to kernel-doc, * but execution continues. */ diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 165a8c39d..19f82df09 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -113,7 +113,7 @@ #include #include #include -#include +//bbox disabled: #include /* bbox: not needed #define INT_CONF ntohl(0x434f4e46) -- cgit v1.2.3-55-g6feb From e4569be24488242eb190b379003a9afe789c844b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 11:03:46 +0100 Subject: build system: "make hosttools" doesn't exist, remove it from "make help" Signed-off-by: Denys Vlasenko --- Makefile.help | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile.help b/Makefile.help index 119dd6f89..6a23e2a80 100644 --- a/Makefile.help +++ b/Makefile.help @@ -21,10 +21,6 @@ help: @echo ' defconfig - set .config to largest generic configuration' @echo ' menuconfig - interactive curses-based configurator' @echo ' oldconfig - resolve any unresolved symbols in .config' - @echo ' hosttools - build sed for the host.' - @echo ' You can use these commands if the commands on the host' - @echo ' is unusable. Afterwards use it like:' - @echo ' make SED="$(objtree)/sed"' @$(if $(boards), \ $(foreach b, $(boards), \ printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ -- cgit v1.2.3-55-g6feb From f0058b1b1fe9f7e69b415616096fb9347f599426 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 11:53:26 +0100 Subject: ping: revert "try SOCK_DGRAM if no root privileges" It wasn't working, and fixes on top of it would make ping noticeably larger. Signed-off-by: Denys Vlasenko --- networking/ping.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) 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) #endif sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */ if (sock < 0) { - if (errno != EPERM) - bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); -#if defined(__linux__) || defined(__APPLE__) - /* We don't have root privileges. Try SOCK_DGRAM instead. - * Linux needs net.ipv4.ping_group_range for this to work. - * MacOSX allows ICMP_ECHO, ICMP_TSTAMP or ICMP_MASKREQ - */ -#if ENABLE_PING6 - if (lsa->u.sa.sa_family == AF_INET6) - sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6); - else -#endif - sock = socket(AF_INET, SOCK_DGRAM, 1); /* 1 == ICMP */ - if (sock < 0) -#endif - bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); + if (errno == EPERM) + bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); + bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); } xmove_fd(sock, pingsock); -- cgit v1.2.3-55-g6feb From 6eb0cbe07e5c2f3131c2d6a5bafd83d2cac20f7d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 16:07:11 +0100 Subject: find: fix a regression introduced with -HLP support function old new delta find_main 294 342 +48 Signed-off-by: Denys Vlasenko --- findutils/find.c | 21 ++++++++++++++++++++- testsuite/find.tests | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 testsuite/find.tests 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; int find_main(int argc UNUSED_PARAM, char **argv) { int i, firstopt, status = EXIT_SUCCESS; + char **past_HLP, *saved; INIT_G(); + /* "find -type f" + getopt("+HLP") => disaster. + * Need to avoid getopt running into a non-HLP option. + * Do this by temporarily storing NULL there: + */ + past_HLP = argv; + for (;;) { + saved = *++past_HLP; + if (!saved) + break; + if (saved[0] != '-') + break; + if (!saved[1]) + break; /* it is "-" */ + if ((saved+1)[strspn(saved+1, "HLP")] != '\0') + break; + } + *past_HLP = NULL; /* "+": stop on first non-option */ i = getopt32(argv, "+HLP"); if (i & (1<<0)) @@ -1301,7 +1319,8 @@ int find_main(int argc UNUSED_PARAM, char **argv) if (i & (1<<1)) G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; /* -P is default and is ignored */ - argv += optind; + argv = past_HLP; /* same result as "argv += optind;" */ + *past_HLP = saved; for (firstopt = 0; argv[firstopt]; firstopt++) { if (argv[firstopt][0] == '-') 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 @@ +#!/bin/sh + +# Copyright 2014 by Denys Vlasenko +# Licensed under GPLv2, see file LICENSE in this source tree. + +. ./testing.sh + +# testing "description" "command" "result" "infile" "stdin" + +mkdir -p find.tempdir +touch find.tempdir/testfile + +testing "find -type f" \ + "cd find.tempdir && find -type f 2>&1" \ + "./testfile\n" \ + "" "" + +# testing "description" "command" "result" "infile" "stdin" + +rm -rf find.tempdir + +exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From 16ca379b55eb5dc1cacfaabf4ca026c49fb516bd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 17:52:13 +0100 Subject: chown: fix help text Signed-off-by: Denys Vlasenko --- coreutils/chown.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ //usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n" //usage: "\n -R Recurse" //usage: "\n -h Affect symlinks instead of symlink targets" +//usage: IF_DESKTOP( //usage: "\n -L Traverse all symlinks to directories" //usage: "\n -H Traverse symlinks on command line only" //usage: "\n -P Don't traverse symlinks (default)" -//usage: IF_DESKTOP( //usage: "\n -c List changed files" //usage: "\n -v List all files" //usage: "\n -f Hide errors" -- cgit v1.2.3-55-g6feb From 89deb22f9745e145fdbb4fbe985cfa9e20e90024 Mon Sep 17 00:00:00 2001 From: Ryan Mallon Date: Thu, 9 Jan 2014 19:14:07 +0100 Subject: fakeidentd: fix use-after-free function old new delta do_rd 199 197 -2 Signed-off-by: Ryan Mallon Signed-off-by: Denys Vlasenko --- networking/isrv_identd.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index a41405c33..c6b0f6528 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c @@ -51,19 +51,18 @@ static int do_rd(int fd, void **paramp) { identd_buf_t *buf = *paramp; char *cur, *p; - int retval = 0; /* session is ok (so far) */ int sz; cur = buf->buf + buf->pos; if (buf->fd_flag & O_NONBLOCK) fcntl(fd, F_SETFL, buf->fd_flag); - sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos); + sz = safe_read(fd, cur, sizeof(buf->buf) - 1 - buf->pos); if (sz < 0) { if (errno != EAGAIN) - goto term; /* terminate this session if !EAGAIN */ - goto ok; + goto term; + return 0; /* "session is ok" */ } buf->pos += sz; @@ -71,19 +70,19 @@ static int do_rd(int fd, void **paramp) p = strpbrk(cur, "\r\n"); if (p) *p = '\0'; - if (!p && sz && buf->pos <= (int)sizeof(buf->buf)) - goto ok; + if (!p && sz && buf->pos < (int)sizeof(buf->buf)) + return 0; /* "session is ok" */ + /* Terminate session. If we are in server mode, then * fd is still in nonblocking mode - we never block here */ - if (fd == 0) fd++; /* inetd mode? then write to fd 1 */ + if (fd == 0) + fd++; /* inetd mode? then write to fd 1 */ fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser); - term: - free(buf); - retval = 1; /* terminate */ - ok: if (buf->fd_flag & O_NONBLOCK) fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK); - return retval; + term: + free(buf); + return 1; /* "terminate" */ } static int do_timeout(void **paramp UNUSED_PARAM) @@ -120,7 +119,7 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv) opt = getopt32(argv, "fiwb:", &bind_address); strcpy(bogouser, "nobody"); if (argv[optind]) - strncpy(bogouser, argv[optind], sizeof(bogouser)); + strncpy(bogouser, argv[optind], sizeof(bogouser) - 1); /* Daemonize if no -f and no -i and no -w */ if (!(opt & OPT_fiw)) -- cgit v1.2.3-55-g6feb From 3ea93e853e44fd7e227688cb96f5f847817862c0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 19:58:19 +0100 Subject: networking: explain isrv_run() API Signed-off-by: Denys Vlasenko --- networking/isrv.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/networking/isrv.h b/networking/isrv.h index 4c7e01dd1..a42fd4100 100644 --- a/networking/isrv.h +++ b/networking/isrv.h @@ -23,7 +23,32 @@ int isrv_register_fd(isrv_state_t *state, int peer, int fd); void isrv_close_fd(isrv_state_t *state, int fd); int isrv_register_peer(isrv_state_t *state, void *param); -/* driver */ +/* Driver: + * + * Select on listen_fd for (or forever if 0). + * + * If we time out and we have no peers, exit. + * If we have peers, call do_timeout(peer_param), + * if it returns !0, peer is removed. + * + * If listen_fd is active, accept new connection ("peer"), + * call new_peer() on it, and if it returns 1, + * and add it to fds to select on. + * Now, select will wait for , not + * (as long as we we have more than zero clients). + * + * If a peer's fd is active, we call do_rd() on it if read + * mask bit was set, + * and then do_wr() if write mask bit was also set. + * If either returns !0, peer is removed. + * Reaching this place also resets timeout counter for this peer. + * + * Note that peer must indicate that he wants to be selected + * for read and/or write using isrv_want_rd()/isrv_want_wr() + * [can be called in new_peer() or in do_rd()/do_wr()]. + * If it never wants to be selected for write, do_wr() + * will never be called (can be NULL). + */ void isrv_run( int listen_fd, int (*new_peer)(isrv_state_t *state, int fd), -- cgit v1.2.3-55-g6feb From abaf9109bdacf9ec2f5c60eccb175a241fb70743 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 20:05:47 +0100 Subject: fixlet for the previous commit Signed-off-by: Denys Vlasenko --- networking/isrv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/isrv.h b/networking/isrv.h index a42fd4100..d412973b7 100644 --- a/networking/isrv.h +++ b/networking/isrv.h @@ -32,7 +32,7 @@ int isrv_register_peer(isrv_state_t *state, void *param); * if it returns !0, peer is removed. * * If listen_fd is active, accept new connection ("peer"), - * call new_peer() on it, and if it returns 1, + * call new_peer() on it, and if it returns 0, * and add it to fds to select on. * Now, select will wait for , not * (as long as we we have more than zero clients). -- cgit v1.2.3-55-g6feb From 3deabea8932715dae2b7b95e08b1be96d1bc0361 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 9 Jan 2014 20:09:43 +0100 Subject: fixlet for the previous commit #2 Signed-off-by: Denys Vlasenko --- networking/isrv.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/networking/isrv.h b/networking/isrv.h index d412973b7..7b12e0edd 100644 --- a/networking/isrv.h +++ b/networking/isrv.h @@ -33,13 +33,12 @@ int isrv_register_peer(isrv_state_t *state, void *param); * * If listen_fd is active, accept new connection ("peer"), * call new_peer() on it, and if it returns 0, - * and add it to fds to select on. + * add it to fds to select on. * Now, select will wait for , not - * (as long as we we have more than zero clients). + * (as long as we have more than zero peers). * * If a peer's fd is active, we call do_rd() on it if read - * mask bit was set, - * and then do_wr() if write mask bit was also set. + * bit was set, and then do_wr() if write bit was also set. * If either returns !0, peer is removed. * Reaching this place also resets timeout counter for this peer. * -- cgit v1.2.3-55-g6feb From 9b76f895bcd50c97df66c7e0192e045245eb519f Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Fri, 10 Jan 2014 11:54:37 +0100 Subject: build system: fix non-portable sed constructs. This includes proper line breaks for labels and closing braces, and removing non-portable \n and \t in s/// functions. Signed-off-by: Matthias Andree Signed-off-by: Denys Vlasenko --- scripts/gen_build_files.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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() # copy stdin to stdout cat # print everything after INSERT line - sed -n '/^INSERT$/ { :l; n; p; bl }' "${src}" + sed -n '/^INSERT$/ { + :l + n + p + bl + }' "${src}" } >"${dst}.tmp" if ! cmp -s "${dst}" "${dst}.tmp"; then gen "${dst}" @@ -52,7 +57,12 @@ sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \ # We add line continuation backslash after each line, # and insert empty line before each line which doesn't start # with space or tab -sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\@p' \ +TAB="$(printf '\tX')" +TAB="${TAB%X}" +LF="$(printf '\nX')" +LF="${LF%X}" +sed -n -e 's@^//usage:\([ '"$TAB"'].*\)$@\1 \\@p' \ + -e 's@^//usage:\([^ '"$TAB"'].*\)$@\'"$LF"'\1 \\@p' \ "$srctree"/*/*.c "$srctree"/*/*/*.c \ | generate \ "$srctree/include/usage.src.h" \ -- cgit v1.2.3-55-g6feb From 7c47b560a8fc97956dd8132bd7f1863d83c19866 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 10 Jan 2014 14:06:57 +0100 Subject: libarchive: open_zipped() does not need to check extensions for e.g. gzip We only need to check for signature-less extensions, currently only .lzma. The rest can be happily autodetected. This fixes "zcat FILE_WITHOUT_GZ_EXT" case, among others. Signed-off-by: Denys Vlasenko --- archival/libarchive/open_transformer.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c index 4e9826441..1aeba13bc 100644 --- a/archival/libarchive/open_transformer.c +++ b/archival/libarchive/open_transformer.c @@ -182,27 +182,26 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected) int FAST_FUNC open_zipped(const char *fname) { - char *sfx; int fd; fd = open(fname, O_RDONLY); if (fd < 0) return fd; - sfx = strrchr(fname, '.'); - if (sfx) { - sfx++; - if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0) - /* .lzma has no header/signature, just trust it */ + if (ENABLE_FEATURE_SEAMLESS_LZMA) { + /* .lzma has no header/signature, can only detect it by extension */ + char *sfx = strrchr(fname, '.'); + if (sfx && strcmp(sfx+1, "lzma") == 0) { open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma"); - else - if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0) - || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0) - || (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0) - ) { - setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1); + return fd; } } + if ((ENABLE_FEATURE_SEAMLESS_GZ) + || (ENABLE_FEATURE_SEAMLESS_BZ2) + || (ENABLE_FEATURE_SEAMLESS_XZ) + ) { + setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1); + } return fd; } -- cgit v1.2.3-55-g6feb From 79df481dc4723cc018731508bc08ce42b3b2eb17 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 10 Jan 2014 14:38:26 +0100 Subject: lineedit: fix trivial build failure Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b168f1b86..85643079b 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1255,7 +1255,9 @@ line_input_t* FAST_FUNC new_line_input_t(int flags) { line_input_t *n = xzalloc(sizeof(*n)); n->flags = flags; +#if MAX_HISTORY > 0 n->max_history = MAX_HISTORY; +#endif return n; } -- cgit v1.2.3-55-g6feb From 1bdbf264540892a20d07cd81d2918dd5519f4bb3 Mon Sep 17 00:00:00 2001 From: Cristian Ionescu-Idbohrn Date: Thu, 9 Jan 2014 20:00:58 +0100 Subject: tail: adjust help/usage texts Signed-off-by: Cristian Ionescu-Idbohrn Signed-off-by: Denys Vlasenko --- coreutils/Config.src | 3 ++- coreutils/tail.c | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/coreutils/Config.src b/coreutils/Config.src index 0c44c4b51..33defa4db 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src @@ -633,12 +633,13 @@ config FEATURE_FANCY_TAIL default y depends on TAIL help - The options (-q, -s, and -v) are provided by GNU tail, but + The options (-q, -s, -v and -F) are provided by GNU tail, but are not specific in the SUSv3 standard. -q Never output headers giving file names -s SEC Wait SEC seconds between reads with -f -v Always output headers giving file names + -F Same as -f, but keep retrying config TEE bool "tee" 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 @@ //usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n" //usage: "With more than one FILE, precede each with a filename header.\n" //usage: "\n -f Print data as file grows" -//usage: IF_FEATURE_FANCY_TAIL( -//usage: "\n -s SECONDS Wait SECONDS between reads with -f" -//usage: ) +//usage: "\n -c [+]N[kbm] Print last N bytes" //usage: "\n -n N[kbm] Print last N lines" //usage: "\n -n +N[kbm] Start on Nth line and print the rest" //usage: IF_FEATURE_FANCY_TAIL( -//usage: "\n -c [+]N[kbm] Print last N bytes" //usage: "\n -q Never print headers" +//usage: "\n -s SECONDS Wait SECONDS between reads with -f" //usage: "\n -v Always print headers" +//usage: "\n -F Same as -f, but keep retrying" //usage: "\n" //usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)." //usage: ) -- cgit v1.2.3-55-g6feb From 604b7b6cc03bab020f03d35f0064ab0e87845616 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 10 Jan 2014 17:12:54 +0100 Subject: fakeidentd: simplify ndelay manipulations function old new delta new_peer 91 79 -12 do_rd 197 152 -45 Signed-off-by: Denys Vlasenko --- networking/isrv_identd.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index c6b0f6528..252c8aba9 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c @@ -25,8 +25,7 @@ enum { TIMEOUT = 20 }; typedef struct identd_buf_t { int pos; - int fd_flag; - char buf[64 - 2*sizeof(int)]; + char buf[64 - sizeof(int)]; } identd_buf_t; #define bogouser bb_common_bufsiz1 @@ -42,7 +41,7 @@ static int new_peer(isrv_state_t *state, int fd) if (isrv_register_fd(state, peer, fd) < 0) return peer; /* failure, unregister peer */ - buf->fd_flag = fcntl(fd, F_GETFL) | O_NONBLOCK; + ndelay_on(fd); isrv_want_rd(state, fd); return 0; } @@ -55,8 +54,6 @@ static int do_rd(int fd, void **paramp) cur = buf->buf + buf->pos; - if (buf->fd_flag & O_NONBLOCK) - fcntl(fd, F_SETFL, buf->fd_flag); sz = safe_read(fd, cur, sizeof(buf->buf) - 1 - buf->pos); if (sz < 0) { @@ -70,7 +67,7 @@ static int do_rd(int fd, void **paramp) p = strpbrk(cur, "\r\n"); if (p) *p = '\0'; - if (!p && sz && buf->pos < (int)sizeof(buf->buf)) + if (!p && sz) return 0; /* "session is ok" */ /* Terminate session. If we are in server mode, then @@ -78,8 +75,11 @@ static int do_rd(int fd, void **paramp) if (fd == 0) fd++; /* inetd mode? then write to fd 1 */ fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser); - if (buf->fd_flag & O_NONBLOCK) - fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK); + /* + * Why bother if we are going to close fd now anyway? + * if (server) + * ndelay_off(fd); + */ term: free(buf); return 1; /* "terminate" */ @@ -94,10 +94,9 @@ static void inetd_mode(void) { identd_buf_t *buf = xzalloc(sizeof(*buf)); /* buf->pos = 0; - xzalloc did it */ - /* We do NOT want nonblocking I/O here! */ - /* buf->fd_flag = 0; - xzalloc did it */ do alarm(TIMEOUT); + /* Note: we do NOT want nonblocking I/O here! */ while (do_rd(0, (void*)&buf) == 0); } -- cgit v1.2.3-55-g6feb From 0f592d7fb94c5887528d0ee24020c2225ab71c28 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 10 Jan 2014 18:02:38 +0100 Subject: tar: tighten up pax header validity check function old new delta get_header_tar 1785 1795 +10 Signed-off-by: Denys Vlasenko --- archival/libarchive/get_header_tar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 */ p += len; sz -= len; - if ((int)sz < 0 + if ( + /** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */ + (int)(sz|len) < 0 /* this works */ || len == 0 || errno != EINVAL || *end != ' ' -- cgit v1.2.3-55-g6feb