oweals/busybox.git
6 years agolzop: buffer several 32-bit writes when we start a new compressed block
Denys Vlasenko [Sun, 8 Apr 2018 14:31:02 +0000 (16:31 +0200)]
lzop: buffer several 32-bit writes when we start a new compressed block

function                                             old     new   delta
lzo_compress                                         483     531     +48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolzop: reuse strings
Denys Vlasenko [Sun, 8 Apr 2018 12:00:03 +0000 (14:00 +0200)]
lzop: reuse strings

function                                             old     new   delta
lzo_compress                                         470     483     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes
   text    data     bss     dec     hex filename
 940011     477    7284  947772   e763c busybox_old
 939976     477    7284  947737   e7619 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolzop: checksum reads do not need to be checksummed
Denys Vlasenko [Sun, 8 Apr 2018 11:45:04 +0000 (13:45 +0200)]
lzop: checksum reads do not need to be checksummed

function                                             old     new   delta
do_lzo_decompress                                    404     427     +23
f_read32                                              22       -     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolzop: don't support ancient versions < 0.94 (15 Oct 1997)
Denys Vlasenko [Sun, 8 Apr 2018 11:35:28 +0000 (13:35 +0200)]
lzop: don't support ancient versions < 0.94 (15 Oct 1997)

0.94 came only 2 months after initial 0.90:

    0.90 (10 Aug 1997): First public release of lzop
    ...
    0.94 (15 Oct 1997): Header format change

function                                             old     new   delta
do_lzo_decompress                                    411     404      -7
f_read8                                               24       -     -24
f_read16                                              31       -     -31
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-62)             Total: -62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolzop: code shrink by using header_t matching on-disk layout
Denys Vlasenko [Sun, 8 Apr 2018 11:32:47 +0000 (13:32 +0200)]
lzop: code shrink by using header_t matching on-disk layout

function                                             old     new   delta
add_bytes_to_chksum                                   37      47     +10
lzo_decompress                                       524     532      +8
init_chksum                                           14      21      +7
chksum_getresult                                      13      17      +4
f_read                                                33      28      -5
f_write8                                              20       -     -20
f_write32                                             22       -     -22
f_write16                                             25       -     -25
f_write                                               36       -     -36
do_lzo_compress                                      328     232     -96
do_lzo_decompress                                    526     411    -115
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 4/3 up/down: 29/-319)          Total: -290 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotar: trim help text
Denys Vlasenko [Sat, 7 Apr 2018 19:04:39 +0000 (21:04 +0200)]
tar: trim help text

Usage: tar c|x|t [-ZzJjahmvokO] [-f TARFILE] [-C DIR] [-T FILE] [-X FILE] [--exclude PATTERN]... [FILE]...

Create, extract, or list files from a tar file

Operation:  <============== DELETED
    c Create
    x Extract
    t List
    -f FILE Name of TARFILE ('-' for stdin/out)
    -C DIR Change to DIR before operation
    -v Verbose
    -O Extract to stdout
    -m Don't restore mtime
    -o Don't restore user:group
    -k Don't replace existing files
    -Z (De)compress using compress
    -z (De)compress using gzip
    -J (De)compress using xz
    -j (De)compress using bzip2
    -a (De)compress using lzma
    -h Follow symlinks
    -T FILE File with names to include
    -X FILE File with glob patterns to exclude
    --exclude PATTERN Glob pattern to exclude

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix prompt in multi-line $(())
Denys Vlasenko [Sat, 7 Apr 2018 15:01:31 +0000 (17:01 +0200)]
hush: fix prompt in multi-line $(())

Now shows PS2 in this case:

/path/to/dir $ a=b; echo $((
> _

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolibbb: switch bb_ask_noecho() to "mallocing" string return API
Denys Vlasenko [Sat, 7 Apr 2018 13:50:30 +0000 (15:50 +0200)]
libbb: switch bb_ask_noecho() to "mallocing" string return API

function                                             old     new   delta
bb_ask_noecho                                        313     330     +17
get_cred_or_die                                      125     115     -10
passwd_main                                          995     958     -37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 17/-47)            Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoxargs: use bb_ask_y_confirmation_FILE() instead of homegrown copy
Denys Vlasenko [Sat, 7 Apr 2018 13:21:35 +0000 (15:21 +0200)]
xargs: use bb_ask_y_confirmation_FILE() instead of homegrown copy

function                                             old     new   delta
bb_ask_y_confirmation_FILE                             -      83     +83
inetd_main                                          2033    2043     +10
udhcp_send_kernel_packet                             295     301      +6
rmescapes                                            306     310      +4
send_tree                                            353     355      +2
i2cdetect_main                                       674     672      -2
confirm_or_abort                                      43      38      -5
get_terminal_width_height                            242     234      -8
bb_ask_y_confirmation                                 76      10     -66
xargs_main                                           823     755     -68
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/5 up/down: 105/-149)          Total: -44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolibbb: rename bb_ask -> bb_ask_noecho, bb_ask_confirmation -> bb_ask_y_confirmation
Denys Vlasenko [Sat, 7 Apr 2018 13:08:12 +0000 (15:08 +0200)]
libbb: rename bb_ask -> bb_ask_noecho, bb_ask_confirmation -> bb_ask_y_confirmation

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotelnet: move winsize detection closer to I/O loop, delete non-functioning debug code
Denys Vlasenko [Sat, 7 Apr 2018 13:02:20 +0000 (15:02 +0200)]
telnet: move winsize detection closer to I/O loop, delete non-functioning debug code

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoftpd: allow -A if !FTPD_AUTHENTICATION as well
Denys Vlasenko [Sat, 7 Apr 2018 12:18:42 +0000 (14:18 +0200)]
ftpd: allow -A if !FTPD_AUTHENTICATION as well

Users will be able to use "ftpd -A" in scripts regardless of build config

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoftpd: added -A option to disable all authentication, closes 10921
Denys Vlasenko [Sat, 7 Apr 2018 12:02:21 +0000 (14:02 +0200)]
ftpd: added -A option to disable all authentication, closes 10921

function                                             old     new   delta
packed_usage                                       32745   32777     +32
ftpd_main                                           2162    2156      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 32/-6)              Total: 26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agowget,ftpd: shorten and reuse strings
Denys Vlasenko [Sat, 7 Apr 2018 11:22:52 +0000 (13:22 +0200)]
wget,ftpd: shorten and reuse strings

function                                             old     new   delta
wget_main                                           2382    2386      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 4/0)                 Total: 4 bytes
   text    data     bss     dec     hex filename
 934228     477    7296  942001   e5fb1 busybox_old
 934202     477    7296  941975   e5f97 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohttpd: do not default to Content-type: application/octet-stream
Denys Vlasenko [Fri, 6 Apr 2018 23:13:30 +0000 (01:13 +0200)]
httpd: do not default to Content-type: application/octet-stream

Instead, simply don't send this header.

On Mon, Apr 2, 2018 at 8:17 PM, xisd <xisd-dev@riseup.net> wrote:
> I had some trouble using busybox httpd to serve a static website and I
> thought the issue might be of interest.
>
> My problem is related to something that seem quite common for static
> site generator :  the use of html files without the '.html' extension
> (it is called 'clean url'...)
>
> Most web server guess that these files are html and display them like
> any other .html files.
>
> From what I understood, the MIME type for files without extension in
> busybox htttp default settings is 'application/octet-stream', and
> because of that 'clean url' pages are not displayed.
>
> It is only trouble because I wanted to deploy my website on freshly
> installed linux without editing any configuration.
>
> The default MIME setting make sense to me as it is, I just thought that
> might be worth mentioning since the use of 'clean url' seem to be a
> common practice for static sites generators (the one I use is callled
> 'yellow' (https://github.com/datenstrom/yellow))
>
> Here is a link for the related issue on github :
> https://github.com/datenstrom/yellow/issues/317

function                                             old     new   delta
send_headers                                         702     718     +16
send_headers_and_exit                                 23      20      -3
handle_incoming_and_exit                            2794    2791      -3
send_file_and_exit                                   772     756     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 16/-22)             Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoscripts/kconfig/mconf.c: survive is SIGWINCH is not defined
Denys Vlasenko [Fri, 6 Apr 2018 17:05:53 +0000 (19:05 +0200)]
scripts/kconfig/mconf.c: survive is SIGWINCH is not defined

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoi386: make stack size optimization selectable, and allow i486 insns (bswap)
Denys Vlasenko [Fri, 6 Apr 2018 16:55:35 +0000 (18:55 +0200)]
i386: make stack size optimization selectable, and allow i486 insns (bswap)

It's hard to imagine someone still using non-bswap equipped CPU

function                                             old     new   delta
xmalloc_optname_optval                               888     879      -9
write_leases                                         214     205      -9
write32                                               36      27      -9
update_status                                        612     603      -9
udhcpd_main                                         1468    1459      -9
udhcpc_main                                         2708    2699      -9
udhcp_run_script                                     804     795      -9
sha256_process_block64                               423     414      -9
sha1_process_block64                                 337     328      -9
sha1_end                                              80      71      -9
send_ACK                                             161     152      -9
select_lease_time                                     64      55      -9
rpm_getint                                           118     109      -9
readprofile_main                                    1719    1710      -9
read32                                                33      24      -9
rdate_main                                           236     227      -9
machtime                                              39      30      -9
inet_addr_match                                      103      94      -9
get_prefix                                           344     335      -9
f_write32                                             31      22      -9
f_read32                                              31      22      -9
dumpleases_main                                      620     611      -9
KeyExpansion                                         197     188      -9
udhcp_str2optset                                     536     518     -18
read_config                                          222     204     -18
lfp_to_d                                              55      37     -18
ipaddr_modify                                       1226    1208     -18
dnsd_main                                           1278    1260     -18
des_crypt                                           1344    1326     -18
d_to_lfp                                             106      88     -18
bb_bswap_64                                           29      11     -18
INET_setroute                                        827     809     -18
read_leases                                          330     309     -21
zcip_main                                           1256    1229     -27
send_offer                                           476     449     -27
ipcalc_main                                          534     507     -27
handle_incoming_and_exit                            2821    2794     -27
fmt_time_bernstein_25                                131     104     -27
common_traceroute_main                              3804    3768     -36
rpm_gettags                                          451     397     -54
parse_args                                          1412    1358     -54
volume_id_probe_hfs_hfsplus                          627     564     -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/42 up/down: 0/-732)          Total: -732 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoplacate gcc-8.0.1 warnings
Denys Vlasenko [Fri, 6 Apr 2018 16:26:33 +0000 (18:26 +0200)]
placate gcc-8.0.1 warnings

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix "unset PS1/PS2", and put them into initial variable set
Denys Vlasenko [Fri, 6 Apr 2018 15:58:21 +0000 (17:58 +0200)]
hush: fix "unset PS1/PS2", and put them into initial variable set

"unset PS1/PS2" causes prompts to be empty strings

function                                             old     new   delta
hush_main                                           1031    1089     +58
goto_new_line                                         27      33      +6
fgetc_interactive                                    244     245      +1
unset_local_var                                      155     149      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 65/-6)              Total: 59 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agosort: smaller and more agressive FEATURE_SORT_OPTIMIZE_MEMORY
Denys Vlasenko [Fri, 6 Apr 2018 14:44:50 +0000 (16:44 +0200)]
sort: smaller and more agressive FEATURE_SORT_OPTIMIZE_MEMORY

function                                             old     new   delta
sort_main                                           1098    1037     -61

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: if we did match "LINENO" or "OPTIND", stop further comparisons
Denys Vlasenko [Fri, 6 Apr 2018 12:57:53 +0000 (14:57 +0200)]
hush: if we did match "LINENO" or "OPTIND", stop further comparisons

function                                             old     new   delta
handle_changed_special_names                          99     101      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: consolidate handling of setting/unsetting of PSn, LINENO, OPTIND
Denys Vlasenko [Fri, 6 Apr 2018 12:50:12 +0000 (14:50 +0200)]
hush: consolidate handling of setting/unsetting of PSn, LINENO, OPTIND

function                                             old     new   delta
handle_changed_special_names                           -      99     +99
unset_local_var                                      256     155    -101
set_local_var                                        557     437    -120
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 99/-221)          Total: -122 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: update to correctly handle changed var_bash[346].tests
Denys Vlasenko [Thu, 5 Apr 2018 15:04:53 +0000 (17:04 +0200)]
hush: update to correctly handle changed var_bash[346].tests

function                                             old     new   delta
expand_one_var                                      1612    1604      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: implement "hush -s"
Denys Vlasenko [Thu, 5 Apr 2018 14:46:49 +0000 (16:46 +0200)]
hush: implement "hush -s"

function                                             old     new   delta
hush_main                                           1015    1031     +16
packed_usage                                       32757   32745     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-12)              Total: 4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoplacate gcc 8.0.1 sprintf overflow warnings in config tools
Denys Vlasenko [Thu, 5 Apr 2018 13:21:34 +0000 (15:21 +0200)]
placate gcc 8.0.1 sprintf overflow warnings in config tools

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix a few more corner cases with empty-expanding `cmds`
Denys Vlasenko [Thu, 5 Apr 2018 13:15:53 +0000 (15:15 +0200)]
hush: fix a few more corner cases with empty-expanding `cmds`

See added testcases

function                                             old     new   delta
run_pipe                                            1723    1784     +61

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix corner cases with exec in empty expansions
Denys Vlasenko [Thu, 5 Apr 2018 12:41:21 +0000 (14:41 +0200)]
hush: fix corner cases with exec in empty expansions

Cases like these:

var=val exec >redir

var=val `` >redir

function                                             old     new   delta
run_pipe                                            1701    1723     +22
redirect_and_varexp_helper                            56      55      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 22/-1)              Total: 21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: less mind-bending set_vars_and_save_old()
Denys Vlasenko [Thu, 5 Apr 2018 12:09:14 +0000 (14:09 +0200)]
hush: less mind-bending set_vars_and_save_old()

function                                             old     new   delta
run_pipe                                            1651    1701     +50
set_local_var                                        510     557     +47
pseudo_exec_argv                                     544     581     +37
redirect_and_varexp_helper                            64      56      -8
set_vars_and_save_old                                164     149     -15
unset_local_var                                      274     256     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/3 up/down: 134/-41)            Total: 93 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: "no logic changes" in last commit was not true, fix it up
Denys Vlasenko [Thu, 5 Apr 2018 11:10:34 +0000 (13:10 +0200)]
hush: "no logic changes" in last commit was not true, fix it up

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: make run_pipe code simpler to understand, no logic changes
Denys Vlasenko [Thu, 5 Apr 2018 09:30:17 +0000 (11:30 +0200)]
hush: make run_pipe code simpler to understand, no logic changes

function                                             old     new   delta
run_pipe                                            1641    1651     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix a bug where we don't properly handle f() { a=A; b=B; }; a= f
Denys Vlasenko [Wed, 4 Apr 2018 22:51:55 +0000 (00:51 +0200)]
hush: fix a bug where we don't properly handle f() { a=A; b=B; }; a= f

function                                             old     new   delta
unset_local_var                                       20     274    +254
leave_var_nest_level                                   -      98     +98
set_vars_and_save_old                                128     164     +36
enter_var_nest_level                                   -      32     +32
builtin_local                                         46      50      +4
pseudo_exec_argv                                     554     544     -10
redirect_and_varexp_helper                            77      64     -13
run_pipe                                            1890    1641    -249
unset_local_var_len                                  267       -    -267
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/3 up/down: 424/-539)         Total: -115 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: make var nesting code independent of "local" support
Denys Vlasenko [Wed, 4 Apr 2018 20:32:59 +0000 (22:32 +0200)]
hush: make var nesting code independent of "local" support

Also, add code to abort at ~65000 function recursion depth.
SEGVing is not as nice as exiting with a message (and restoring termios!):

$ f() { echo -n .; f; }; f
....<many dots later>....hush: fatal recursion (depth 65281)

function                                             old     new   delta
run_pipe                                            1826    1890     +64
pseudo_exec_argv                                     544     554     +10
parse_and_run_file                                    71      80      +9
i_getch                                              104     107      +3
done_command                                          99     102      +3
set_local_var                                        508     510      +2
helper_export_local                                  214     215      +1
builtin_local                                         49      46      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/1 up/down: 92/-3)              Total: 89 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix for readonly vars in "ro=A ro=B cmd" case
Denys Vlasenko [Wed, 4 Apr 2018 19:14:28 +0000 (21:14 +0200)]
hush: fix for readonly vars in "ro=A ro=B cmd" case

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agosort: move misplaced comment
Denys Vlasenko [Wed, 4 Apr 2018 15:07:21 +0000 (17:07 +0200)]
sort: move misplaced comment

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agosort: FEATURE_SORT_OPTIMIZE_MEMORY
Denys Vlasenko [Wed, 4 Apr 2018 15:02:32 +0000 (17:02 +0200)]
sort: FEATURE_SORT_OPTIMIZE_MEMORY

On sorting all kernel/linux/arch/ *.[ch] files,
this reduces memory usage by 6%.

yes | head -99999999 | sort

goes down from 1900Mb to 380 Mb.

function                                             old     new   delta
sort_main                                            862    1098    +236

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: unbreak PS1 parsing after "ash: parser: Add syntax stack..." commit
Denys Vlasenko [Wed, 4 Apr 2018 11:59:53 +0000 (13:59 +0200)]
ash: unbreak PS1 parsing after "ash: parser: Add syntax stack..." commit

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: support "f() (cmd)" functions
Denys Vlasenko [Tue, 3 Apr 2018 12:56:52 +0000 (14:56 +0200)]
hush: support "f() (cmd)" functions

Many other shells support this construct

function                                             old     new   delta
parse_stream                                        2950    3018     +68

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix mishandling of "true | f() { echo QWE; }"
Denys Vlasenko [Tue, 3 Apr 2018 11:02:43 +0000 (13:02 +0200)]
hush: fix mishandling of "true | f() { echo QWE; }"

function                                             old     new   delta
run_pipe                                            1820    1826      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix "set -e; false || x=1; echo OK"
Denys Vlasenko [Tue, 3 Apr 2018 09:21:13 +0000 (11:21 +0200)]
hush: fix "set -e; false || x=1; echo OK"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: one-word, no-globbing handling of local/export/readonly args
Denys Vlasenko [Tue, 3 Apr 2018 06:20:58 +0000 (08:20 +0200)]
hush: one-word, no-globbing handling of local/export/readonly args

function                                             old     new   delta
done_word                                            738     790     +52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: parser: Fix parameter expansion inside inner double quotes
Denys Vlasenko [Mon, 2 Apr 2018 19:00:59 +0000 (21:00 +0200)]
ash: parser: Fix parameter expansion inside inner double quotes

Upstream email:

    parser: Fix parameter expansion inside inner double quotes

    The parsing of parameter expansion inside inner double quotes
    breaks because we never look for ENDVAR while innerdq is true.

            echo "${x#"${x+''}"''}

    This patch fixes it by pushing the syntax stack if innerdq is
    true and we enter a new parameter expansion.

    This patch also fixes a corner case where a bad substitution error
    occurs within arithmetic expansion.

Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
    Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
function                                             old     new   delta
readtoken1                                          2880    2898     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix a backslash-removal bug in case
Denys Vlasenko [Mon, 2 Apr 2018 15:25:18 +0000 (17:25 +0200)]
hush: fix a backslash-removal bug in case

function                                             old     new   delta
run_list                                            1270    1053    -217

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: expand: Fix bugs with words connected to the right of $@
Denys Vlasenko [Mon, 2 Apr 2018 12:27:50 +0000 (14:27 +0200)]
ash: expand: Fix bugs with words connected to the right of $@

Upstream email:

    This is actually composed of two bugs.  First of all our tracking
    of quotemark is wrong so anything after "$@" becomes quoted.  Once
    we fix that then the problem is that the first space character
    after "$@" is not recognised as an IFS.

    This patch fixes both.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: redir: Fix typo in noclobber code
Denys Vlasenko [Mon, 2 Apr 2018 11:34:57 +0000 (13:34 +0200)]
ash: redir: Fix typo in noclobber code

Upstream commit "redir: Fix typo in noclobber code"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: parser: Fix single-quoted patterns in here-documents
Denys Vlasenko [Mon, 2 Apr 2018 11:29:20 +0000 (13:29 +0200)]
ash: parser: Fix single-quoted patterns in here-documents

Upstream commit:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 23:07:53 +0800
    parser: Fix single-quoted patterns in here-documents

    The script

            x=*
            cat <<- EOF
                    ${x#'*'}
            EOF

    prints * instead of nothing as it should.  The problem is that
    when we're in sqsyntax context in a here-document, we won't add
    CTLESC as we should.  This patch fixes it:

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: remove stray debugging printout
Denys Vlasenko [Mon, 2 Apr 2018 11:26:16 +0000 (13:26 +0200)]
hush: remove stray debugging printout

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: parser: Add syntax stack for recursive parsing
Denys Vlasenko [Mon, 2 Apr 2018 10:35:04 +0000 (12:35 +0200)]
ash: parser: Add syntax stack for recursive parsing

This closes 10821.

Upstream patch:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 00:14:02 +0800
    parser: Add syntax stack for recursive parsing

    Without a stack of syntaxes we cannot correctly these two cases
    together:

            "${a#'$$'}"
            "${a#"${b-'$$'}"}"

    A recursive parser also helps in some other corner cases such
    as nested arithmetic expansion with paratheses.

    This patch adds a syntax stack allocated from the stack using
    alloca.  As a side-effect this allows us to remove the naked
    backslashes for patterns within double-quotes, which means that
    EXP_QPAT also has to go.

    This patch also fixes removes any backslashes that precede right
    braces when they are present within a parameter expansion context,
    and backslashes that precede double quotes within inner double
    quotes inside a parameter expansion in a here-document context.

    The idea of a recursive parser is based on a patch by Harald van
    Dijk.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
var_bash3, var_bash4 and var_bash6 tests are updated
with the output given by bash-4.3.43

With this patch, the following tests now pass for ash:

    dollar_repl_slash_bash2.tests
    squote_in_varexp2.tests
    squote_in_varexp.tests
    var_bash4.tests

function                                             old     new   delta
readtoken1                                          2615    2874    +259
synstack_push                                          -      54     +54
evalvar                                              574     571      -3
rmescapes                                            330     310     -20
subevalvar                                          1279    1258     -21
argstr                                              1146    1107     -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/4 up/down: 313/-83)           Total: 230 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: update information comment about heredoc discrepancy
Denys Vlasenko [Sun, 1 Apr 2018 18:11:23 +0000 (20:11 +0200)]
hush: update information comment about heredoc discrepancy

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolibbb: new function bb_die_memory_exhausted
Denys Vlasenko [Sun, 1 Apr 2018 17:59:37 +0000 (19:59 +0200)]
libbb: new function bb_die_memory_exhausted

function                                             old     new   delta
bb_die_memory_exhausted                                -      10     +10
xstrdup                                               28      23      -5
xsetenv                                               27      22      -5
xrealloc                                              32      27      -5
xputenv                                               22      17      -5
xmalloc                                               30      25      -5
xfdopen_helper                                        40      35      -5
xasprintf                                             44      39      -5
wget_main                                           2387    2382      -5
open_socket                                           54      49      -5
glob_brace                                           419     414      -5
bb_get_chunk_from_file                               146     141      -5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/11 up/down: 10/-55)           Total: -45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agosed: prevent overflow of length from bb_get_chunk_from_file
Quentin Rameau [Sun, 1 Apr 2018 17:49:58 +0000 (19:49 +0200)]
sed: prevent overflow of length from bb_get_chunk_from_file

This fragment did not work right:

                temp = bb_get_chunk_from_file(fp, &len);
                if (temp) {
                        /* len > 0 here, it's ok to do temp[len-1] */
                        char c = temp[len-1];

With "int len" _sign-extending_, temp[len-1] can refer to a wrong location
if len > 0x7fffffff.

Signed-off-by: Quentin Rameau <quinq@fifth.space>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolibbb: remove unnecessary variable in xmalloc_fgets
Quentin Rameau [Sun, 1 Apr 2018 15:05:35 +0000 (17:05 +0200)]
libbb: remove unnecessary variable in xmalloc_fgets

Signed-off-by: Quentin Rameau <quinq@fifth.space>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: add a comment where we differ from bash wrt heredoc EOF mark handling
Denys Vlasenko [Sun, 1 Apr 2018 16:55:00 +0000 (18:55 +0200)]
hush: add a comment where we differ from bash wrt heredoc EOF mark handling

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoparser: Fix backquote support in here-document EOF mark
Denys Vlasenko [Sun, 1 Apr 2018 14:38:32 +0000 (16:38 +0200)]
parser: Fix backquote support in here-document EOF mark

Upstream commit:

    Author: Herbert Xu <herbert@gondor.apana.org.au>
    Date:   Thu Mar 15 18:27:30 2018 +0800
    parser: Fix backquote support in here-document EOF mark

    Currently using backquotes in a here-document EOF mark is broken
    because dash tries to do command substitution on it.  This patch
    fixes it by checking whether we're looking for an EOF mark during
    tokenisation.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
With added fix for quoted-ness of the EOF mark.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash,hush: handle a few more bkslash-newline cases
Denys Vlasenko [Sun, 1 Apr 2018 01:04:55 +0000 (03:04 +0200)]
ash,hush: handle a few more bkslash-newline cases

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoshells: fix var_LINENO1.tests false positive, add it to ash tests too
Denys Vlasenko [Sat, 31 Mar 2018 18:31:13 +0000 (20:31 +0200)]
shells: fix var_LINENO1.tests false positive, add it to ash tests too

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix heredoc_bkslash_newline1.tests failure
Denys Vlasenko [Sat, 31 Mar 2018 18:16:31 +0000 (20:16 +0200)]
hush: fix heredoc_bkslash_newline1.tests failure

function                                             old     new   delta
parse_stream                                        2787    2827     +40
builtin_type                                         117     115      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: use pgetc_eatbnl() in more places
Denys Vlasenko [Sat, 31 Mar 2018 17:21:31 +0000 (19:21 +0200)]
ash: use pgetc_eatbnl() in more places

Part of upstream commit:

    Date:   Thu Mar 8 08:37:11 2018 +0100
    Author: Harald van Dijk <harald@gigawatt.nl>
    parser: use pgetc_eatbnl() in more places

    dash has a pgetc_eatbnl function in parser.c which skips any
    backslash-newline combinations. It's not used everywhere it could be.
    There is also some duplicated backslash-newline handling elsewhere in
    parser.c. Replace most of the calls to pgetc() with calls to
    pgetc_eatbnl() and remove the duplicated backslash-newline handling.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Not adding "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes, since
readtoken1() handles the "starts with backslash + newline" case itself.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: 'nolog' and 'debug' options cause "$-" to wreak havoc
Martijn Dekker [Sat, 31 Mar 2018 16:15:59 +0000 (18:15 +0200)]
ash: 'nolog' and 'debug' options cause "$-" to wreak havoc

Upstream commit:

    Date:   Tue Mar 6 17:40:37 2018 +0000
    expand: 'nolog' and 'debug' options cause "$-" to wreak havoc

    Op 29-03-17 om 20:02 schreef Martijn Dekker:
    > Bug: if either the 'nolog' or the 'debug' option is set, trying to
    > expand "$-" silently aborts parsing of an entire argument.
    >
    > $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; set +o nolog; echo "|$- are the options|"'
    > |
    > |uCf are the options|
    > $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; set +o debug; echo "|$- are the options|"'
    > |
    > |uCf are the options|

    This turned out to be easy to fix. The routine producing the "$-"
    expansion failed to skip options for which there is no option letter,
    but only a long-form name. In dash, 'nolog' and 'debug' are currently
    the only two such options. Patch below.

    - Martijn

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
In bbox ash, pipefail is the option which exhibited this.

Signed-off-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agostat: fix a typo: s/romfs/ramfs/, closes 10876
Denys Vlasenko [Sat, 31 Mar 2018 00:45:22 +0000 (02:45 +0200)]
stat: fix a typo: s/romfs/ramfs/, closes 10876

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: fix a signedness bug
Denys Vlasenko [Fri, 30 Mar 2018 22:46:07 +0000 (00:46 +0200)]
hush: fix a signedness bug

Testcase:

set -- a ""; space=" "; printf "<%s>\n" "$@"$space

Before:
<a >
After:
<a>
<>

It usually does not bite since bbox forces -funsigned-char build.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash,hush: new test dollar_repl_slash_bash2.tests
Denys Vlasenko [Fri, 30 Mar 2018 21:25:24 +0000 (23:25 +0200)]
ash,hush: new test dollar_repl_slash_bash2.tests

This fails for ash. hush works.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: fix "char == CTLfoo" comparison signedness bug
Denys Vlasenko [Fri, 30 Mar 2018 21:03:29 +0000 (23:03 +0200)]
ash: fix "char == CTLfoo" comparison signedness bug

It usually does not bite since bbox forces -funsigned-char build.
But for some reason void linux people disabled that.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash: use F_DUPFD_CLOEXEC and O_CLOEXEC
Denys Vlasenko [Fri, 30 Mar 2018 20:15:14 +0000 (22:15 +0200)]
ash: use F_DUPFD_CLOEXEC and O_CLOEXEC

function                                             old     new   delta
setjobctl                                            371     367      -4
setinputfile                                         226     220      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10)             Total: -10 bytes

Based on patch by Mark Marshall <mark.marshall@omicronenergy.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoexamples/var_service: new example: dnsmasq service
Denys Vlasenko [Fri, 30 Mar 2018 18:49:16 +0000 (20:49 +0200)]
examples/var_service: new example: dnsmasq service

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agocpio: extract "unsafe" symlinks the same way tar/unzip does
Natanael Copa [Fri, 30 Mar 2018 18:18:12 +0000 (20:18 +0200)]
cpio: extract "unsafe" symlinks the same way tar/unzip does

function                                             old     new   delta
cpio_main                                            588     596      +8

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agosvok: new applet (daemontools compat)
Denys Vlasenko [Fri, 30 Mar 2018 18:02:33 +0000 (20:02 +0200)]
svok: new applet (daemontools compat)

function                                             old     new   delta
svok_main                                              -     127    +127
packed_usage                                       32705   32757     +52
applet_names                                        2756    2761      +5
applet_main                                         1588    1592      +4
bb_banner                                             46      47      +1
sv                                                  1286    1284      -2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 189/-2)            Total: 187 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoifplugd service example: always run up/down script on startup
Denys Vlasenko [Fri, 30 Mar 2018 09:14:46 +0000 (11:14 +0200)]
ifplugd service example: always run up/down script on startup

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoifplugd: if SIOCSIFFLAGS fails with EADDRNOTAVAIL, don't die
Stefan Agner [Thu, 29 Mar 2018 12:12:31 +0000 (14:12 +0200)]
ifplugd: if SIOCSIFFLAGS fails with EADDRNOTAVAIL, don't die

When using ifplugd on a RNDIS interface with monitor mode, using
SIOCSIFFLAGS seems to fail with EADDRNOTAVAIL. Treat it the same
as if iface disappeared again.

This has been observed on a Tegra TK1 using Linux 4.14. There seem
to be a race when the kernel is creating the device:
  ifplugd(usb0): started: BusyBox v1.24.1 (2018-03-27 09:47:48 CEST)
  ifplugd(usb0): interface doesn't exist, waiting
  ifplugd(usb0): interface appeared
  ifplugd(usb0): upping interface
  ifplugd(usb0): setting interface flags failed: Cannot assign requested address
  <exit>

With this patch ifplugd is successful in upping the device the second
time around:

  ifplugd(usb0): upping interface
  ifplugd(usb0): using SIOCETHTOOL detection mode
  ifplugd(usb0): interface appeared
  ifplugd(usb0): upping interface
  ifplugd(usb0): setting interface flags failed: Cannot assign requested address
  ifplugd(usb0): interface appeared
  ifplugd(usb0): upping interface
  ifplugd(usb0): using SIOCETHTOOL detection mode
  ifplugd(usb0): link is up
  ifplugd(usb0): executing '/etc/ifplugd/ifplugd.usb.action usb0 up'
  ifplugd up
  ifplugd(usb0): exit code: 0

function                                             old     new   delta
up_iface                                             120     127      +7

Signed-off-by: Stefan Agner <stefan@agner.ch>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agofbsplash: support configurable image position
Peter Korsgaard [Thu, 29 Mar 2018 11:35:01 +0000 (13:35 +0200)]
fbsplash: support configurable image position

For some setups (E.G. for supporting different screen resolutions),
positioning the image somewhere else than the top left corner may be
interesting.

Add support for IMG_LEFT/IMG_TOP settings to specify the image location,
similar to how it is done for the progress bar.

function                                             old     new   delta
fbsplash_main                                        994    1038     +44
static.param_names                                    57      74     +17
packed_usage                                       32631   32647     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 77/0)               Total: 77 bytes

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agogrep: fix echo "aa" | busybox grep -F -w "a" (should not match)
Denys Vlasenko [Thu, 29 Mar 2018 16:03:50 +0000 (18:03 +0200)]
grep: fix echo "aa" | busybox grep -F -w "a" (should not match)

function                                             old     new   delta
grep_file                                           1461    1470      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agofstrim: do not check that specified file is on a block device
Denys Vlasenko [Thu, 29 Mar 2018 14:00:30 +0000 (16:00 +0200)]
fstrim: do not check that specified file is on a block device

Kernel will surely inform us in FITRIM does not make sense on a given file.

function                                             old     new   delta
fstrim_main                                          241     221     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: add a FIXME comment
Denys Vlasenko [Wed, 28 Mar 2018 16:42:54 +0000 (18:42 +0200)]
hush: add a FIXME comment

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoash,hush: fix "saved" redirected fds still visible in children
Denys Vlasenko [Wed, 28 Mar 2018 16:35:07 +0000 (18:35 +0200)]
ash,hush: fix "saved" redirected fds still visible in children

Based on a patch by Mark Marshall <mark.marshall@omicronenergy.com>

function                                             old     new   delta
dup_CLOEXEC                                            -      49     +49
fcntl_F_DUPFD                                         46       -     -46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agolibbb: use BUILD_BUG_ON in utoa_to_buf()
Denys Vlasenko [Wed, 28 Mar 2018 15:12:56 +0000 (17:12 +0200)]
libbb: use BUILD_BUG_ON in utoa_to_buf()

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoifupdown: do not fail if interface disappears during ifdown
Kaarle Ritvanen [Tue, 27 Mar 2018 22:00:03 +0000 (00:00 +0200)]
ifupdown: do not fail if interface disappears during ifdown

Interface may not exist because it got deleted by an ifdown hook script
earlier. This may happen when a virtual interface, such as VLAN, has multiple
iface blocks defined.

function                                             old     new   delta
static_down6                                          14      40     +26
static_down                                           54      70     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 42/0)               Total: 42 bytes

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoioctl(SIOCGIFINDEX) does not require clearing of entire ifr
Denys Vlasenko [Tue, 27 Mar 2018 21:54:54 +0000 (23:54 +0200)]
ioctl(SIOCGIFINDEX) does not require clearing of entire ifr

function                                             old     new   delta
INET6_setroute                                       492     472     -20
do_iplink                                           1357    1330     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-47)             Total: -47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agonetstat: produce numeric-ip output for non-resolved names
Mark Marshall [Mon, 19 Mar 2018 09:45:40 +0000 (10:45 +0100)]
netstat: produce numeric-ip output for non-resolved names

If we don't ask for numerical output, and the symbolic look-up failed
we used to get "(null)", but the numeric output would be better.

function                                             old     new   delta
ip_port_str                                          109     121     +12

Signed-off-by: Mark Marshall <mark.marshall@omicronenergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agossl_client: fix option parsing
Ron Yorston [Tue, 20 Mar 2018 10:41:28 +0000 (11:41 +0100)]
ssl_client: fix option parsing

The wrong character was used to indicate options taking an integer
parameter.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotop: fix "warning: unused variable new_mask"
Denys Vlasenko [Mon, 19 Mar 2018 19:00:10 +0000 (20:00 +0100)]
top: fix "warning: unused variable new_mask"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotar: add -o and -k to short --help too
Denys Vlasenko [Fri, 16 Mar 2018 03:02:23 +0000 (04:02 +0100)]
tar: add -o and -k to short --help too

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotar: add -k and -o to --help
Denys Vlasenko [Fri, 16 Mar 2018 02:55:14 +0000 (03:55 +0100)]
tar: add -k and -o to --help

    -o Don't restore user:group
    -k Don't replace existing files

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotcpsvd: fix fallout from opt_complementary removal
Denys Vlasenko [Sun, 11 Mar 2018 22:02:50 +0000 (23:02 +0100)]
tcpsvd: fix fallout from opt_complementary removal

   text    data     bss     dec     hex filename
 933035     473    6836  940344   e5938 busybox_old
 933051     473    6836  940360   e5948 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoreadprofile: code shrink
Denys Vlasenko [Sun, 11 Mar 2018 18:35:58 +0000 (19:35 +0100)]
readprofile: code shrink

function                                             old     new   delta
defaultpro                                            14       -     -14
defaultmap                                            17       -     -17
readprofile_main                                    1762    1719     -43
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-74)             Total: -74 bytes
   text    data     bss     dec     hex filename
 933081     473    6836  940390   e5966 busybox_old
 933035     473    6836  940344   e5938 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agontpd: choose initial FREQHOLD_cnt dynamically
Denys Vlasenko [Sun, 11 Mar 2018 16:08:02 +0000 (17:08 +0100)]
ntpd: choose initial FREQHOLD_cnt dynamically

function                                             old     new   delta
update_local_clock                                   834     858     +24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoudhcpd: clamp down huge auto_times to ~2M seconds, better EINTR poll handling
Denys Vlasenko [Sun, 11 Mar 2018 10:34:44 +0000 (11:34 +0100)]
udhcpd: clamp down huge auto_times to ~2M seconds, better EINTR poll handling

EINTR _should_ only happen on two signals we trap, and safe_poll
_should_ work here just fine, but there were kernel bugs where spurious EINTRs
happen (e.g. on ptrace attach). Be safe.

function                                             old     new   delta
udhcpd_main                                         1437    1468     +31

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agontpd: suppress in-kernel frequency correction in first 8 adjtimex calls
Denys Vlasenko [Sat, 10 Mar 2018 20:25:53 +0000 (21:25 +0100)]
ntpd: suppress in-kernel frequency correction in first 8 adjtimex calls

In other words: try to correct initially existing clock offset first,
before assuming that our clock drifts.

function                                             old     new   delta
update_local_clock                                   826     834      +8
ntp_init                                             550     557      +7
filter_datapoints                                    179     173      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 15/-6)               Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoudhcpd: fix "not dying on SIGTERM"
Denys Vlasenko [Sat, 10 Mar 2018 18:01:48 +0000 (19:01 +0100)]
udhcpd: fix "not dying on SIGTERM"

Fixes:
commit 52a515d18724bbb34e3ccbbb0218efcc4eccc0a8
"udhcp: use poll() instead of select()"
Feb 16 2017

udhcp_sp_read() is meant to check whether signal pipe indeed has some data to read.
In the above commit, it was changed as follows:

- if (!FD_ISSET(signal_pipe.rd, rfds))
+ if (!pfds[0].revents)
return 0;

The problem is, the check was working for select() purely by accident.
Caught signal interrupts select()/poll() syscalls, they return with EINTR
(regardless of SA_RESTART flag in sigaction). _Then_ signal handler is invoked.
IOW: they can't see any changes to fd state caused by signal haldler
(in our case, signal handler makes signal pipe ready to be read).

For select(), it means that rfds[] bit array is unmodified, bit of signal
pipe's read fd is still set, and the above check "works": it thinks select()
says there is data to read.

This accident does not work for poll(): .revents stays clear, and we do not
try reading signal pipe as we should. In udhcpd, we fall through and block
in socket read. Further SIGTERM signals simply cause socket read to be
interrupted and then restarted (since SIGTERM handler has SA_RESTART=1).

Fixing this as follows: remove the check altogether. Set signal pipe read fd
to nonblocking mode. Always read it in udhcp_sp_read().
If read fails, assume it's EAGAIN and return 0 ("no signal seen").

udhcpd avoids reading signal pipe on every recvd packet by looping if EINTR
(using safe_poll()) - thus ensuring we have correct .revents for all fds -
and calling udhcp_sp_read() only if pfds[0].revents!=0.

udhcpc performs much fewer reads (typically it sleeps >99.999% of the time),
there is no need to optimize it: can call udhcp_sp_read() after each poll
unconditionally.

To robustify socket reads, unconditionally set pfds[1].revents=0
in udhcp_sp_fd_set() (which is before poll), and check it before reading
network socket in udhcpd.

TODO:
This might still fail: if pfds[1].revents=POLLIN, socket read may still block.
There are rare cases when select/poll indicates that data can be read,
but then actual read still blocks (one such case is UDP packets with
wrong checksum). General advise is, if you use a poll/select loop,
keep all your fds nonblocking.
Maybe we should also do that to our network sockets?

function                                             old     new   delta
udhcp_sp_setup                                        55      65     +10
udhcp_sp_fd_set                                       54      60      +6
udhcp_sp_read                                         46      36     -10
udhcpd_main                                         1451    1437     -14
udhcpc_main                                         2723    2708     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 16/-39)            Total: -23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoremove stray newline in "iplink --help"
Denys Vlasenko [Thu, 8 Mar 2018 15:06:18 +0000 (16:06 +0100)]
remove stray newline in "iplink --help"

function                                             old     new   delta
packed_usage                                       32547   32550      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoip: fix "ip -oneline a"
Denys Vlasenko [Thu, 8 Mar 2018 14:55:07 +0000 (15:55 +0100)]
ip: fix "ip -oneline a"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoipcs: further code shrink
Denys Vlasenko [Thu, 8 Mar 2018 12:23:06 +0000 (13:23 +0100)]
ipcs: further code shrink

function                                             old     new   delta
packed_usage                                       32543   32547      +4
ipcs_main                                           1014     980     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-34)             Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agoipcs: code shrink
Denys Vlasenko [Thu, 8 Mar 2018 12:10:23 +0000 (13:10 +0100)]
ipcs: code shrink

function                                             old     new   delta
packed_usage                                       32539   32543      +4
format                                                 1       -      -1
do_shm                                               883     880      -3
do_sem                                               636     633      -3
do_msg                                               782     779      -3
ipcs_main                                           1049    1014     -35
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/4 up/down: 4/-45)             Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agomd5sum: use config help text similar to other "sum" tools
Denys Vlasenko [Thu, 8 Mar 2018 11:47:13 +0000 (12:47 +0100)]
md5sum: use config help text similar to other "sum" tools

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotop: much faster cursor key navigation by avoiding process rescan
Denys Vlasenko [Wed, 7 Mar 2018 03:47:52 +0000 (04:47 +0100)]
top: much faster cursor key navigation by avoiding process rescan

function                                             old     new   delta
handle_input                                         549     560     +11
top_main                                             889     891      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotop: do unsigned rather than signed division in do_stats()
Denys Vlasenko [Wed, 7 Mar 2018 03:20:22 +0000 (04:20 +0100)]
top: do unsigned rather than signed division in do_stats()

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agotop: handle much larger VSZ values
Denys Vlasenko [Wed, 7 Mar 2018 02:59:52 +0000 (03:59 +0100)]
top: handle much larger VSZ values

function                                             old     new   delta
display_process_list                                1018     999     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agouse gmtime_r() instead of gmtime()
Denys Vlasenko [Tue, 6 Mar 2018 17:11:47 +0000 (18:11 +0100)]
use gmtime_r() instead of gmtime()

This avoids pulling in gmtime's static buffer:

function                                             old     new   delta
svlogd_main                                         1401    1412     +11
send_headers                                         668     678     +10
gmtime                                                21       -     -21
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/0 up/down: 21/-21)              Total: 0 bytes
   text    data     bss     dec     hex filename
 920221     555    5804  926580   e2374 busybox_old
 920221     555    5740  926516   e2334 busybox_unstripped
                   ^^^^

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agohush: code shrink
Denys Vlasenko [Tue, 6 Mar 2018 16:21:57 +0000 (17:21 +0100)]
hush: code shrink

function                                             old     new   delta
run_pipe                                            1589    1591      +2
pseudo_exec_argv                                     374     375      +1
builtin_type                                         114     115      +1
find_function                                          8       -      -8
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/0 up/down: 4/-8)               Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agonetworking/interface.c: get rid of global data
Denys Vlasenko [Mon, 5 Mar 2018 17:28:04 +0000 (18:28 +0100)]
networking/interface.c: get rid of global data

These were data/bss:

static.proc_read                                       1       -      -1
int_list                                               4       -      -4
int_last                                               4       -      -4

We never call display_interfaces() twice, thus code to not scan /proc twice
never triggers.

function                                             old     new   delta
do_if_print                                            -    1998   +1998
display_interfaces                                   145     249    +104
static.proc_read                                       1       -      -1
add_interface                                        104     103      -1
int_list                                               4       -      -4
int_last                                               4       -      -4
if_readlist_proc                                     560     542     -18
if_readconf                                          141       -    -141
do_if_fetch                                          643       -    -643
ife_print                                           1296       -   -1296
------------------------------------------------------------------------------
(add/remove: 1/6 grow/shrink: 1/2 up/down: 2102/-2108)         Total: -6 bytes
   text    data     bss     dec     hex filename
 933084     473    6844  940401   e5971 busybox_old
 933087     473    6836  940396   e596c busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agonetworking/interface.c: get rid of global "smallint interface_opt_a"
Denys Vlasenko [Mon, 5 Mar 2018 16:46:17 +0000 (17:46 +0100)]
networking/interface.c: get rid of global "smallint interface_opt_a"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
6 years agonetworking/interface.c: code shrink
Denys Vlasenko [Mon, 5 Mar 2018 15:56:16 +0000 (16:56 +0100)]
networking/interface.c: code shrink

function                                             old     new   delta
ife_print                                           1293    1296      +3
display_interfaces                                   145     146      +1
if_readconf                                          162     141     -21
if_readlist_proc                                     631     560     -71
do_if_fetch                                          753     643    -110
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 4/-202)           Total: -198 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>