dash has accepted a patch to remove the first argument of findvar().
It's commit e85e972 (var: move hashvar() calls into findvar()).
Apply the same change to BusyBox ash.
function old new delta
findvar 35 40 +5
mklocal 268 261 -7
exportcmd 164 157 -7
setvareq 319 310 -9
lookupvar 150 141 -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 5/-32) Total: -27 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The 'timeout' applet uses parse_duration_str() to obtain its
timeout values. The default configuration enables float durations.
However, the applet silently ignores fractional seconds. This
results in unexpected behaviour:
$ timeout 5.99 sleep 5.1; echo $?
Terminated
143
When float durations are enabled ensure that any fractional seconds
are taken into account.
function old new delta
timeout_wait 44 92 +48
timeout_main 383 365 -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-18) Total: 30 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
"echo text >&0000000000002" works as you would expect,
"echo text >&9999999999" properly fails instead of creating a file
named "9999999999".
function old new delta
expredir 219 232 +13
readtoken1 3045 3053 +8
parsefname 204 201 -3
isdigit_str9 45 - -45
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 21/-48) Total: -27 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
With very large fd#, the error code path is different
from one for closed but small fd#.
Make it not abort if we are interactive:
$ echo text >&99 # this wasn't buggy
ash: dup2(9,1): Bad file descriptor
$ echo text >&9999 # this was
ash: fcntl(1,F_DUPFD,10000): Invalid argument
function old new delta
.rodata 105637 105661 +24
dup2_or_raise 35 38 +3
redirect 1084 1044 -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 27/-40) Total: -13 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The check for result hash size was buggy for CONFIG_SHA1_HWACCEL=y.
While at it, document CPUID use a bit better.
function old new delta
get_shaNI - 28 +28
sha1_end 66 79 +13
sha256_begin 83 60 -23
sha1_begin 111 88 -23
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 41/-46) Total: -5 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
gcc is being rather silly. Usues suboptimal registers,
and does not realize that i and j are never negative,
thus usese even _more_ registers for temporaries
to sign-extend i/j to 64-bit offsets.
function old new delta
sp_256_mont_mul_8 155 132 -23
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
gcc does not necessarily clear upper bits in
64-bit regs if you ask it to load a 32-bit constant.
Cast it to unsigned long. Better yet, hand-write loading
of the constant with a smaller instruction.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The coreutils versions of md5sum and the like accept uppercase hex
strings from checksum files specified with the '-c' option.
Use a case-insensitive comparison so BusyBox does the same.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Currently vi assumes that the edit buffer ends in a newline. This may
not be the case. For example:
$ printf test > test
$ vi test
<press 'o'>
We fix this by inserting a newline to the end during initialization.
Signed-off-by: Petja Patjas <pp01415943@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Commit 549deab5a (ash: move parse-time quote flag detection to
run-time) did away with the need to distinguish between backquotes
inside and outside quotes. This left a gap among the control
characters used in argument strings. Removing this gap saves a
few bytes.
function old new delta
.rodata 167346 167338 -8
cmdputs 399 388 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19) Total: -19 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Extend the changes introduced by commit b4ef2e3467 (Makefile.flags:
suppress some clang-9 warnings) so they also cover the case where
clang is used as a cross-compiler.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
An alias expansion immediately followed by '<' and a newline is
parsed incorrectly:
~ $ alias x='echo yo'
~ $ x<
yo
~ $
sh: syntax error: unexpected newline
The echo is executed and an error is printed on the next command
submission. In dash the echo isn't executed and the error is
reported immediately:
$ alias x='echo yo'
$ x<
dash: 3: Syntax error: newline unexpected
$
The difference between BusyBox and dash is that BusyBox supports
bash-style process substitution and output redirection. These
require checking for '<(', '>(' and '&>' in readtoken1().
In the case above, when the end of the alias is found, the '<' and
the following newline are both read to check for '<('. Since
there's no match both characters are pushed back.
The next input is obtained by reading the expansion of the alias.
Once this string is exhausted the next call to __pgetc() calls
preadbuffer() which pops the string, reverts to the previous input
and recursively calls __pgetc(). This request is satisified from
the pungetc buffer. But the first __pgetc() doesn't know this:
it sees the character has come from preadbuffer() so it (incorrectly)
updates the pungetc buffer.
Resolve the issue by moving the code to pop the string and fetch
the next character up from preadbuffer() into __pgetc().
function old new delta
pgetc 28 589 +561
__pgetc 607 - -607
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 561/-607) Total: -46 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Something is fishy with constrcts like "3==v=3" in gawk,
they should not work, but do. Ignore those for now.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
function old new delta
evaluate 3377 3385 +8
Fixes https://bugs.busybox.net/show_bug.cgi?id=15865
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
HTTP headers are case insensitive and therefore the check if a default
header has been overwritten needs to be case insensitive.
Without this patch `--header 'user-agent: test'` results in
`User-Agent: Wget` and `user-agent: test` being send.
function old new delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0) Total: 0 bytes
text data bss dec hex filename
1040876 16443 1840 1059159 102957 busybox_old
1040876 16443 1840 1059159 102957 busybox_unstripped
Signed-off-by: Sertonix <sertonix@posteo.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Although "naive" counting function is not too slow and is smaller,
using it on e.g. each of 1024 words of CPU mask feels wrong.
function old new delta
bb_popcnt_32 - 52 +52
get_prefix 323 321 -2
nproc_main 206 199 -7
d4_run_script 739 731 -8
ipcalc_main 533 507 -26
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/4 up/down: 52/-43) Total: 9 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
In the function find_export_symbols, since the fopen file does not
exit when it fails, there is a dereference problem in fclose(fp),
which will cause a segmentation fault.
Signed-off-by: Yan Zhu <zhuyan2015@foxmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
A 32-bit build of BusyBox using clang segfaulted in the test
"awk assign while assign". Specifically, on line 7 of the test
input where the adjustment of the L.v pointer when the Fields
array was reallocated
L.v += Fields - old_Fields_ptr;
was out by 4 bytes.
Rearrange to code so both gcc and clang generate code that works.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
log5() with crondlog(5, msg, va) seems making logging more consistent.
function old new delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0) Total: 0 bytes
Signed-off-by: Jones Syue <jonessyue@qnap.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
I developed this application to test the Linux kernel series [1]. As
described in it I could not use the iproute2 package since the
microcontroller is without MMU.
function old new delta
do_set_can - 920 +920
packed_usage 34645 34908 +263
get_float_1000 - 164 +164
.rodata 105427 105539 +112
do_iplink 1313 1381 +68
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 1527/0) Total: 1527 bytes
cc: Marc Kleine-Budde <mkl@pengutronix.de>
[1] https://marc.info/?l=linux-netdev&m=167999323611710&w=2
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
sed would currently not error if write failed when modifying a file.
This can be reproduced with the following 'script':
$ sudo mount -t tmpfs tmpfs -o size=1M /tmp/m
$ sudo chmod 777 /tmp/m
$ echo foo > /tmp/m/foo
$ dd if=/dev/zero of=/tmp/m/fill bs=4k
dd: error writing '/tmp/m/fill': No space left on device
256+0 records in
255+0 records out
1044480 bytes (1.0 MB, 1020 KiB) copied, 0.00234567 s, 445 MB/s
$ busybox sed -i -e 's/.*/bar/' /tmp/m/foo
$ echo $?
0
$ cat /tmp/m/foo
<empty>
new behaviour:
$ echo foo > /tmp/m/foo
$ ./busybox sed -i -e 's/.*/bar/' /tmp/m/foo
sed: write error
$ echo $?
4
$ cat /tmp/m/foo
foo
function old new delta
sed_main 754 801 +47
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 47/0) Total: 47 bytes
text data bss dec hex filename
75727 2510 1552 79789 137ad busybox_old
75774 2510 1552 79836 137dc busybox_unstripped
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The ru_maxrss is already in Kbytes and not pages.
function old new delta
ptok 21 - -21
time_main 1261 1217 -44
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-65) Total: -65 bytes
fixes: https://bugs.busybox.net/show_bug.cgi?id=15751
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Patch by M Rubon <rubonmtz@gmail.com>:
Busybox awk handles references to empty (not provided in the input)
fields differently during the first line of input, as compared to
subsequent lines.
$ (echo a ; echo b) | awk '$2 != 0' #wrong
b
No field $2 value is provided in the input. When awk references field
$2 for the "a" line, it is seen to have a different behaviour than
when it is referenced for the "b" line.
Problem in BusyBox v1.36.1 embedded in OpenWrt 23.05.0
Same problem also in 21.02 versions of OpenWrt
Same problem in BusyBox v1.37.0.git
I get the correct expected output from Ubuntu gawk and Debian mawk,
and from my fix.
will@dev:~$ (echo a ; echo b) | awk '$2 != 0' #correct
a
b
will@dev:~/busybox$ (echo a ; echo b ) | ./busybox awk '$2 != 0' #fixed
a
b
I built and poked into the source code at editors/awk.c The function
fsrealloc(int size) is core to allocating, initializing, reallocating,
and reinitializing fields, both real input line fields and imaginary
fields that the script references but do not exist in the input.
When fsrealloc() needs more field space than it has previously
allocated, it initializes those new fields differently than how they
are later reinitialized for the next input line. This works fine for
fields defined in the input, like $1, but does not work the first time
when there is no input for that field (e.g. field $99)
My one-line fix simply makes the initialization and clrvar()
reinitialization use the same value for .type. I am not sure if there
are regression tests to run, but I have not done those.
I'm not sure if I understand why clrvar() is not setting .type to a
default constant value, but in any case I have left that untouched.
function old new delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0) Total: 0 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Just listing the vendor/product IDs is not always very helpful, so add logic
to print the manufacturer and product strings similar to the "big" usbutils
versions.
Not all devices provide sensible strings though. The usbutils version works
around this by falling back to looking up the vendor/product IDs in the hwdb
and using those strings instead, which is not an option here - Instead
simply trim() the strings for readability.
lsusb | sort
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0bda:5539 Realtek Semiconductor Corp. Integrated_Webcam_HD
Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp. 58200
Bus 001 Device 030: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson Peak (JfP)
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 002: ID 0bda:5487 Realtek Semiconductor Corp. Dell dock
Bus 006 Device 003: ID 0bda:5413 Realtek Semiconductor Corp. Dell dock
Bus 006 Device 004: ID 413c:b06e Dell Computer Corp. Dell dock
Bus 006 Device 005: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
Bus 006 Device 006: ID 0bda:402e Realtek Semiconductor Corp. USB Audio
Bus 006 Device 007: ID 413c:1010 Dell Computer Corp. USB 2.0 Hub [MTT]
Bus 006 Device 008: ID 413c:b06f Dell Computer Corp. Dell dock
Bus 006 Device 009: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
Bus 006 Device 010: ID 413c:2110 Dell Computer Corp. Dell Wired Multimedia Keyboard
Bus 006 Device 011: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
Bus 006 Device 012: ID 0451:3410 Texas Instruments, Inc. TUSB3410 Microcontroller
Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 002: ID 0bda:0487 Realtek Semiconductor Corp. Dell dock
Bus 007 Device 003: ID 0bda:0413 Realtek Semiconductor Corp. Dell dock
Bus 007 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
./busybox lsusb | sort
Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 001 Device 002: ID 0bda:5539 CNFHH53Q0324300ACA10 Integrated_Webcam_HD
Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp 58200
Bus 001 Device 030: ID 8087:0aaa
Bus 002 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 003 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 004 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 005 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 dummy_hcd Dummy host controller
Bus 006 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 006 Device 002: ID 0bda:5487 Dell Inc. Dell dock
Bus 006 Device 003: ID 0bda:5413 Dell Inc. Dell dock
Bus 006 Device 004: ID 413c:b06e Dell dock
Bus 006 Device 005: ID 0451:8142
Bus 006 Device 006: ID 0bda:402e Generic USB Audio
Bus 006 Device 007: ID 413c:1010 USB 2.0 Hub [MTT]
Bus 006 Device 008: ID 413c:b06f Dell dock
Bus 006 Device 009: ID 046d:c016 Logitech Optical USB Mouse
Bus 006 Device 010: ID 413c:2110 Dell Dell Wired Multimedia Keyboard
Bus 006 Device 011: ID 0451:8142
Bus 006 Device 012: ID 0451:3410 Texas Instruments TUSB3410 Boot Device
Bus 007 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller
Bus 007 Device 002: ID 0bda:0487 Dell Inc. Dell dock
Bus 007 Device 003: ID 0bda:0413 Dell Inc. Dell dock
Bus 007 Device 004: ID 0bda:8153 Realtek USB 10/100/1000 LAN
./scripts/bloat-o-meter busybox_unstripped{_orig,}
function old new delta
trim - 101 +101
fileAction 338 431 +93
add_sysfs_prop - 70 +70
open_read_close - 54 +54
read_close - 35 +35
.rodata 3268 3294 +26
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 2/0 up/down: 379/0) Total: 379 bytes
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
4c20d9f2b removed FEATURE_FLOAT_SLEEP option, thus since then there are
only two variants.
Fixes: 4c20d9f2b ("extend fractional duration support to "top -d N.N" and "timeout"")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>