Commit Graph

17095 Commits

Author SHA1 Message Date
Ron Yorston
b7b1119d9f vi: improvements to range selection
Rewrite find_range(), pushing quite a bit of code from do_cmd()
down into it.

- The commands 'y', 'd', 'c', '<' and '>' can be given twice to
  specify a whole-line range.  BusyBox vi actually accepted any
  second character from that group, e.g. 'dc' or '<y', with the
  latter being accepted even if yank was disabled.  Require the
  two characters to match.

- '<' and '>' commands followed by ESC incorrectly issued an alert.

- Allow search commands and a marker (specified as "y'a", for example)
  to define a range for those operators that support it.

function                                             old     new   delta
find_range                                           518     707    +189
.rodata                                           105119  105133     +14
get_motion_char                                       68       -     -68
do_cmd                                              4860    4695    -165
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 203/-233)          Total: -30 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-11 00:18:55 +02:00
Ron Yorston
7ce0e75c1f vi: code shrink search commands
Changes to search commands ('/', '?', 'n' and 'N'):

- Rewrite to be smaller and (possibly) clearer.

- Issue a warning when a repeat search is requested without a
  previous search having been made.

Vim and BusyBox vi support a repetition count for searches though
the original vi doesn't.  If the count exceeds the number of
occurrences of the search string the search may loop through the
file multiple times.

function                                             old     new   delta
.rodata                                           105135  105119     -16
do_cmd                                              4898    4860     -38
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-54)             Total: -54 bytes

Signed-off-by; Ron Yorston <rmy@pobox.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-11 00:18:55 +02:00
Ron Yorston
9f017d9db0 vi: changes to option handling
Since commit 70ee23399 (vi: code shrink) the ':set' command is
unable to process multiple options on a line.  Fix this by
temporarily null-terminating each option.

Change the default setting for all options to off to match vim.
Actually, 'flash' isn't an option in vim, only traditional vi,
where it's on by default.  In vim the corresponding option is
'visualbell' which defaults to off.  POSIX doesn't have either
of these.

Allow the abbreviation 'ts' for the 'tabstop' option.

Issue an error message if:

- an option is not implemented
- an option that takes a value has no '=' or has a 'no' prefix
- a boolean option has a '='

function                                             old     new   delta
colon                                               2944    3003     +59
.rodata                                           103171  103189     +18
vi_main                                              274     270      -4
setops                                                73       -     -73
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 77/-77)              Total: 0 bytes

v2: Try harder to detect invalid options.  Thanks to Peter D for pointing
    this out.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-08 12:50:01 +02:00
Ron Yorston
24198f652f vi: deal with invalid movements in shift commands
Since commit 25d259264 (vi: make buffer handling more vi-like)
find_range() can return early when an invalid movement is
specified.

The call to find_range() in the code that handles shift commands
('<' and '>') doesn't check for this condition.  Previously this
only resulted in the current line being shifted but it can now
result in a segfault.

Check for an invalid movement and notify the user without taking
any further action.

function                                             old     new   delta
do_cmd                                              4890    4898      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-30 14:51:27 +02:00
Ron Yorston
a25b4c2c42 vi: code shrink
- In the '+' and '-' commands the call to dot_skip_over_ws() is
  only needed for the final line processed so it can be moved out
  of the while loop.

- Marking sync_cursor() NOINLINE doesn't seem to offer the same
  advantages it did in 2009 (commit adf922ec2).

function                                             old     new   delta
refresh                                              694     974    +280
do_cmd                                              4900    4887     -13
sync_cursor                                          336       -    -336
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 280/-349)          Total: -69 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
d56da68057 vi: improve operations involving paragraph movement
Movement by paragraph doesn't always involve whole lines.  If the
cursor is positioned in the middle of a line deleting to either end
of the paragraph will result in one partial line and zero or more
full lines.

Adjust the end of ranges delimited by paragraph movement to more
closely match what vi does.

function                                             old     new   delta
find_range                                           467     518     +51
at_eof                                                 -      49     +49
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 100/0)             Total: 100 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
8b571bd7b5 vi: improve motion by paragraph
When moving by paragraph ('{' and '}'):

- Treat multiple empty lines as a single paragraph separator.

- When no paragraph separator is found move to the start or end of
  the file depending on the direction of motion.

function                                             old     new   delta
do_cmd                                              4821    4900     +79
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 79/0)               Total: 79 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
d3b74826c5 vi: allow repetition count for paragraph motion
The paragraph motion commands '{' and '}' should accept a count.

function                                             old     new   delta
do_cmd                                              5054    5071     +17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 17/0)               Total: 17 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
1e84daf054 vi: allow motion count for change/delete/yank/shift
The motion that determines the range of a change, delete, yank
or shift operation can have its own count.  Thus the commands
'5dd' and 'd5d' are equivalent:  both delete 5 lines.

When the command itself also has a count the two values are
multiplied.  Thus the command '2d3w' deletes 6 words and '2D3G'
deletes from the current line to line 6.

(When dealing with structured data it might make sense to think in
units of 3 words so '2d3w' is deleting 2 such units.  It doesn't
seem quite as sensible to express 'delete from current line to line 6'
as '2D3G' but vi permits it.)

function                                             old     new   delta
get_motion_char                                        -      68     +68
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/0 up/down: 68/0)               Total: 68 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
d4c46037a6 vi: support more commands for range selection
Add 'F', 'T' and '|' as commands that can be used to specify a
range for change/delete/yank operations.

function                                             old     new   delta
.rodata                                           105129  105135      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 6/0)                 Total: 6 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
15f4ac3ca9 vi: improvements to character search within line
- Use a common routine to handle all commands to search for a
  character in a line.

- When searching for the nth occurrence of a character don't move
  the cursor if fewer than n occurrences are present.

- Add support for the 'T' command, search backwards for character
  after next occurrence of given character.

function                                             old     new   delta
do_cmd                                              4861    4805     -56
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-56)             Total: -56 bytes

v2: Add parentheses to avoid searches continuing past end of line.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
50a2db7dff vi: remember cursor column during vertical motion
When the 'j'/'k' commands or up/down arrow keys are used to move
the cursor vertically 'vi' remembers the original cursor column
and positions the cursor there if possible.  Also, if the '$'
command has been used to position the cursor at the end of a line
vertical movements keep the cursor at the end of the line.

Make BusyBox 'vi' do the same.

function                                             old     new   delta
refresh                                              674     694     +20
do_cmd                                              4853    4861      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 28/0)               Total: 28 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
18871c3f2b vi: 'G'/'M' commands move to first visible character
The 'G' command with no target (meaning 'go to last line') should
position the cursor on the first visible character of the line, as
it already does in other cases.

The 'M' command  should position the cursor on the first visible
character (as 'H' and 'L' already do).

function                                             old     new   delta
do_cmd                                              4842    4853     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
5ae25f40bd vi: don't overwrite existing file
If the name of the file being written doesn't match the current
filename and the output file already exists vi should issue a
warning and not overwrite the file.

Because the test only compares the file names it's somewhat over-
protective.  If the current file name is 'my_text' and the user tries
to save to './my_text' they'll be prevented from doing so.

function                                             old     new   delta
colon                                               3092    3151     +59
.rodata                                           105118  105146     +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 87/0)               Total: 87 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:16:21 +02:00
Ron Yorston
25d2592640 vi: make buffer handling more vi-like
Vi places text affected by change/delete/yank operations into a
buffer.  The contents of such buffers can be restored with the put
commands, 'p' or 'P'.  These behave differently depending on whether
the buffer contains whole lines or partial lines.  For whole lines
the text is copied into the file on the line before (P) or after
(p) the current line.  For partial lines the text is copied before
or after the current cursor position.

Whether an operation results in whole or partial lines depends on
the command used.

BusyBox vi treats any buffer with a newline as though it contained
whole lines.  This is incorrect.  Deleting multiple words across
a line boundary results in a buffer with a newline but not having
whole lines.

Rework how buffers are handled to behave more like vi.

function                                             old     new   delta
static.text_yank                                      79      99     +20
colon                                               3092    3097      +5
edit_file                                            885     887      +2
yank_delete                                          127     112     -15
.rodata                                           105139  105101     -38
find_range                                           514     467     -47
do_cmd                                              5088    4842    -246
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/4 up/down: 27/-346)          Total: -319 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:05:53 +02:00
Ron Yorston
776b56d774 vi: code shrink
I was puzzled by code in find_range() which handles forward word
movement.  It included a test to see if we're at the start of a
word.  Since these are forward word movements surely we'd expect to
be at the start of a word?  In fact, the test was intended to fix a
problem with changes to the last word in a file, as discussed in the
thread starting here:

   http://lists.busybox.net/pipermail/busybox/2004-January/044552.html

The code can be simplified by testing directly for end of file instead
of indirectly for not being at the start of a word.  Since trailing
whitespace is now handled in do_cmd() the code to back up off a newline
is no longer required.

function                                             old     new   delta
find_range                                           619     514    -105
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-105)           Total: -105 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:05:53 +02:00
Ron Yorston
7b4c2276a8 vi: fix word operations across line boundaries
Commit 4b49422a0 (vi: fix changes to word at end of line. Closes
11796) fixed a problem where an operation on a word at the end of
a line followed by a line starting with whitespace incorrectly
joined the lines.  However it also broke the case where operating
on multiple words across a line boundary *should* join the lines.

Fix this by detecting when trailing whitepace in a word operation
includes a newline.  Whitespace beyond the newline is excluded
from consideration.

function                                             old     new   delta
do_cmd                                              5083    5088      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 5/0)                 Total: 5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-29 12:05:53 +02:00
Denys Vlasenko
1195782d79 ntpd: code shrink (force not-inlining, stop returning structs)
function                                             old     new   delta
d_to_sfp                                               -     133    +133
lfp_to_d                                               -      84     +84
sfp_to_d                                               -      78     +78
d_to_lfp                                             141     137      -4
.rodata                                           103182  103174      -8
recv_and_process_peer_pkt                           2380    2173    -207
recv_and_process_client_pkt                          706     493    -213
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/4 up/down: 295/-432)         Total: -137 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-26 12:02:08 +01:00
Denys Vlasenko
c2bd0b6806 timeout,top,watch,ping: parse NN.N fractional duration in locales with other separators
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-23 13:50:02 +01:00
Denys Vlasenko
14ed4ec8a4 resume: write offset in /sys/power/resume_offset
Doing this the kernel will hibernate and resume successfully from a swap file.
Stop writing offset to /sys/power/resume, as this is not a parameter
the kernel takes from this input. (Change added by Sven Mueller)

function                                             old     new   delta
resume_main                                          522     561     +39
.rodata                                           103175  103182      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 46/0)               Total: 46 bytes

Signed-off-by: Jordi Pujol Palomer <jordipujolp@gmail.com>
Signed-off-by: Sven Mueller <sven.mueller72+busybox@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-20 14:01:04 +01:00
Denys Vlasenko
2a2ca93530 login: implement LOGIN_TIMEOUT
function                                             old     new   delta
packed_usage                                       33559   33598     +39
login_main                                           953     986     +33
.rodata                                           103161  103175     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 86/0)               Total: 86 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-19 00:27:44 +01:00
Denys Vlasenko
fe78d70ec6 udhcpc: ignore zero-length DHCP options, take 2
advance the optionptr by two bytes, not one

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-16 11:42:56 +01:00
Russell Senior
1c461df70a udhcpc: ignore zero-length DHCP options
Discovered that the DHCP server on a TrendNet router (unknown model)
provides a zero-length option 12 (Host Name) in the DHCP ACK message. This
has the effect of causing udhcpc to drop the rest of the options, including
option 51 (IP Address Lease Time), 3 (Router), and 6 (Domain Name Server),
most importantly leaving the OpenWrt device with no default gateway.

The TrendNet behavior violates RFC 2132, which in Section 3.14 declares that
option 12 has a minimum length of 1 octet. It is perhaps not a cosmic coincidence
that I found this behavior on Pi Day.

This patch allows zero length options without bailing out, by simply skipping them.

function                                             old     new   delta
udhcp_scan_options                                   183     172     -11

Signed-off-by: Russell Senior <russell@personaltelco.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-16 11:40:19 +01:00
Denys Vlasenko
f26e5634b1 echo: special case "echo --help": it should not show help text
While at it, fix "busybox --help echo" and other special applets to still print
the help text.

function                                             old     new   delta
run_applet_and_exit                                  732     761     +29
show_usage_if_dash_dash_help                          70      78      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0)               Total: 37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-15 17:44:53 +01:00
Samuel Sapalski
f25d254dfd decompress_gunzip: Fix DoS if gzip is corrupt
On certain corrupt gzip files, huft_build will set the error bit on
the result pointer. If afterwards abort_unzip is called huft_free
might run into a segmentation fault or an invalid pointer to
free(p).

In order to mitigate this, we check in huft_free if the error bit
is set and clear it before the linked list is freed.

Signed-off-by: Samuel Sapalski <samuel.sapalski@nokia.com>
Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-12 10:45:10 +01:00
Denys Vlasenko
cbfdeba660 hush: make LINENO selectable without BASH-COMPAT
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-10 16:31:05 +01:00
Sergey Ponomarev
b6e6c83ab3 wget: new option FEATURE_WGET_FTP to enable/disable FTP
Introduce a separate option FTPS_SUPPORTED instead of not obvious ENABLE_FEATURE_WGET_HTTPS.

function                                             old     new   delta
P_FTP                                                  4       -      -4
P_FTPS                                                 5       -      -5
reset_beg_range_to_zero                               41       -     -41
parse_url                                            431     366     -65
parse_pasv_epsv                                      154       -    -154
.rodata                                           115566  115408    -158
ftpcmd                                               204       -    -204
spawn_ssl_client                                     291       -    -291
wget_main                                           2998    2664    -334
------------------------------------------------------------------------------
(add/remove: 0/7 grow/shrink: 0/3 up/down: 0/-1256)         Total: -1256 bytes

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-09 17:45:10 +01:00
Ron Yorston
0b25e810ed bloat-o-meter: avoid double counting
Disable 'echo' in the default config, run 'make baseline', then
re-enable 'echo' and run 'make bloatcheck':

function                                             old     new   delta
.rodata                                           182521  182622    +101
packed_usage                                       33714   33792     +78
applet_main                                         3168    3176      +8
applet_names                                        2730    2735      +5
applet_suid                                           99     100      +1
applet_install_loc                                   198     199      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 194/0)             Total: 194 bytes
   text	   data	    bss	    dec	    hex	filename
 955052	   4195	   1808	 961055	  eaa1f	busybox_old
 955153	   4195	   1808	 961156	  eaa84	busybox_unstripped

The Total bytes value doesn't equal the change in the size of the
binary.  The packed_usage and applet_* items are in .rodata and
are counted twice.  With this modified bloat-o-meter the size of
named items is deducted from .rodata:

function                                             old     new   delta
packed_usage                                       33714   33792     +78
applet_main                                         3168    3176      +8
.rodata                                           105105  105113      +8
applet_names                                        2730    2735      +5
applet_suid                                           99     100      +1
applet_install_loc                                   198     199      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 101/0)             Total: 101 bytes
   text	   data	    bss	    dec	    hex	filename
 955052	   4195	   1808	 961055	  eaa1f	busybox_old
 955153	   4195	   1808	 961156	  eaa84	busybox_unstripped

v2: Sections numbered less than 10 were always being omitted from
    consideration because splitting "[ 1] .interp" leaves "1]" in
    x[1] where the section name is expected.  This wasn't a problem
    for .rodata (numbered 15 in my testing) but let's fix it anyway.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-09 17:25:07 +01:00
Denys Vlasenko
307cd26e98 start-stop-daemon: explain -x + -a test
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-09 01:12:18 +01:00
Denys Vlasenko
2d48d9b1cc ntpd: tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-02 19:54:09 +01:00
Denys Vlasenko
2d6c175d9b ntpd: decrease INITIAL_SAMPLES from 4 to 3
This reduces initial traffic to NTP servers when a lot of devices boot at once.

Log inspection tells me we agressively burst-poll servers about 5 times
at startup, even though we usually already update clock after second replies.
INITIAL_SAMPLES can probably be even lower, e.g. 2, but let's be conservative
when changing this stuff.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-02 12:21:12 +01:00
Denys Vlasenko
70ee23399c vi: code shrink
function                                             old     new   delta
setops                                                85      73     -12
colon                                               2965    2915     -50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-62)             Total: -62 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-01 14:41:39 +01:00
Alison Winters
63d9da322f vi: restore 0 offset after :set noXXX command
Fixes bug where commands after the first noXXX command are ignored.
    e.g. :set noic tabstop=4

While at it, stop recognizing "notabstop=NNN".

function                                             old     new   delta
colon                                               2990    2965     -25

Signed-off-by: Alison Winters <alisonatwork@outlook.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-01 14:26:36 +01:00
Denys Vlasenko
9b6bcfda0e bc: typo fix in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-26 21:20:18 +01:00
Denys Vlasenko
9037757c5f dc: more docs in --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-26 17:11:55 +01:00
Denys Vlasenko
1a37aa7a88 dc: document what non-GNU commands do
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-26 14:48:04 +01:00
Denys Vlasenko
ace81cd46c bc/dc: fix length(0) and length(0.000nnn) result
function                                             old     new   delta
zxc_vm_process                                      6464    6498     +34

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-26 14:23:13 +01:00
Denys Vlasenko
3d88cc1d37 dc: correct --help text
before:

    Tiny RPN calculator. Operations:
    +, -, *, /, %, ~, ^, |,
    p - print top of the stack without popping
    f - print entire stack
    k - pop the value and set the precision
    i - pop the value and set input radix
    o - pop the value and set output radix

After:

    Tiny RPN calculator. Operations:
    Arithmetic: + - * / % ^
    ~ - divide with remainder
    | - modular exponentiation
    v - square root
    p - print top of the stack without popping
    f - print entire stack
    k - pop the value and set precision
    i - pop the value and set input radix
    o - pop the value and set output radix

function                                             old     new   delta
packed_usage                                       33519   33565     +46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-26 13:32:29 +01:00
Denys Vlasenko
1f9ed02caf trylink: do not drop libs from CONFIG_EXTRA_LDLIBS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-23 23:09:49 +01:00
Natanael Copa
e880c9c100 echo: do not assume that free() leaves errno unmodified
musl libc's mallocng free() may modify errno if kernel does not support
MADV_FREE which causes echo to echo with error when it shouldn't.

Future versions of POSIX[1] will require that free() leaves errno
unmodified but til then, do not rely free() implementation.

Should fix downstream issues:
https://github.com/alpinelinux/docker-alpine/issues/134
https://gitlab.alpinelinux.org/alpine/aports/-/issues/12311

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-23 12:59:29 +01:00
Ron Yorston
760b627e2a lineedit: support empty PATH entries in tab completion
Zero-length path prefixes can be specified in PATH as a leading or
trailing colon or two adjacent colons.  POSIX says that the use of
zero-length prefixes to refer to the current directory is a legacy
feature.  Nonetheless the shells in BusyBox respect this feature,
as does 'which'.

Tab-completion of executables using PATH should support this too.

function                                             old     new   delta
complete_cmd_dir_file                                934     931      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-23 12:20:51 +01:00
Ron Yorston
858f8aafac diff: code shrink
function                                             old     new   delta
diff_main                                           1515    1495     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20)             Total: -20 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-22 19:00:07 +01:00
Denys Vlasenko
9fa7d7d97d dnsd: check that we don't read past packet
function                                             old     new   delta
dnsd_main                                           1296    1304      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-22 15:36:07 +01:00
Denys Vlasenko
a4959eef71 udhcp: reuse strings
text	   data	    bss	    dec	    hex	filename
1019916	    559	   5020	1025495	  fa5d7	busybox_old
1019906	    559	   5020	1025485	  fa5cd	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21 16:32:07 +01:00
Denys Vlasenko
855aeacfba ntpd: log responses to clients at log level 3
function                                             old     new   delta
recv_and_process_client_pkt                          670     706     +36

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21 09:47:34 +01:00
Denys Vlasenko
2620d38714 ntpd: without INITIAL_FREQ_ESTIMATION code, state variable is not needed too
function                                             old     new   delta
update_local_clock                                   917     872     -45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21 09:13:05 +01:00
Denys Vlasenko
423c4c25d8 ntpd: remove unused USING_INITIAL_FREQ_ESTIMATION code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21 09:05:48 +01:00
Denys Vlasenko
5024d86255 ntpd: increase loglevel to 3 for "poll:32s sockets:0 interval:64s" message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-21 08:54:08 +01:00
Denys Vlasenko
64483324c5 udhcpc: clarify bcast/unicast sends in logs, include server ID
Before:
    sending discover
    sending select for 192.168.1.173
    lease of 192.168.1.173 obtained, lease time 43200
    sending renew to 192.168.1.1
    lease of 192.168.1.173 obtained, lease time 43200
After:
    broadcasting discover
    broadcasting select for 192.168.1.173, server 192.168.1.1
    lease of 192.168.1.173 obtained from 192.168.1.1, lease time 43200
    sending renew to server 192.168.1.1
    lease of 192.168.1.173 obtained from 192.168.1.1, lease time 43200

function                                             old     new   delta
udhcpc_main                                         2580    2610     +30
send_select                                          104     130     +26
send_renew                                            82      99     +17
send_discover                                         94      89      -5
send_decline                                          93      88      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 73/-10)             Total: 63 bytes
   text	   data	    bss	    dec	    hex	filename
1019732	    559	   5020	1025311	  fa51f	busybox_old
1019898	    559	   5020	1025477	  fa5c5	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-20 18:13:42 +01:00
Denys Vlasenko
6bdfbc4cb5 libbb: fix '--help' handling in FEATURE_SH_NOFORK=y
Most BusyBox applets respond to the '--help' option by printing
a usage message.  This is normally handled by busybox_main() so
applet main routines don't have support for '--help'.

In standalone shell mode with FEATURE_SH_NOFORK enabled nofork
applets are invoked directly, bypassing busybox_main().  This
results in inconsistent handling of '--help':

- applets which call getopt() report "unrecognized option '--help'"
  and print help anyway;

- realpath says "--help: No such file or directory" and doesn't
  print help;

- usleep says "invalid number '--help'" and doesn't print help.

Avoid inconsistency by checking for '--help' in run_nofork_applet().

Bug found by Ron Yorston.

function                                             old     new   delta
show_usage_if_dash_dash_help                           -      70     +70
run_nofork_applet                                    347     362     +15
run_applet_no_and_exit                               432     365     -67
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 85/-67)             Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-18 23:30:24 +01:00