Compare commits

...

607 Commits

Author SHA1 Message Date
Ron Yorston 371fe9f71d ash: move hashvar() calls into findvar()
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>
2024-07-14 01:12:54 +02:00
Ron Yorston e4b5ccd13b timeout: allow fractional seconds in timeout values
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>
2024-07-13 21:34:18 +02:00
Denys Vlasenko b20b3790b4 powertop: code shrink
function                                             old     new   delta
print_intel_cstates                                  477     475      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 11:46:15 +02:00
Denys Vlasenko 23da5c4b71 hush: do not exit interactive shell on some redirection errors
$ echo >&99
hush: dup2(99,1): Bad file descriptor
$ echo >&9999
hush: fcntl(1,F_DUPFD,10000): Invalid argument
$ echo 2>/dev/tty 10>&9999
hush: fcntl(10,F_DUPFD,10000): Invalid argument
$ still alive!_

function                                             old     new   delta
static.setup_redirects                               334     394     +60
.rodata                                           105661  105712     +51
dup_CLOEXEC                                           49      79     +30
save_fd_on_redirect                                  263     277     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 155/0)             Total: 155 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 02:13:28 +02:00
Denys Vlasenko 14e28c18ca hush: fix "exec 3>FILE" aborting if 3 is exactly the next free fd
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 00:59:02 +02:00
Denys Vlasenko 6c38d0e9da hush: avoid duplicate fcntl(F_SETFD, FD_CLOEXEC) during init
function                                             old     new   delta
hush_main                                           1149    1150      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13 00:14:41 +02:00
Denys Vlasenko 08fb86726b ash: remove limitation on fd# length
"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>
2024-07-12 22:28:25 +02:00
Denys Vlasenko 0829fce079 ash: do not abort interactive mode on >&9999 redirect
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>
2024-07-12 22:10:50 +02:00
Denys Vlasenko 1ad2f5cd9f tls: fix CONFIG_FEATURE_TLS_SHA1=y + CONFIG_SHA1_HWACCEL=y
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>
2024-07-12 19:30:14 +02:00
Denys Vlasenko 999e290ef6 tls: P256: improve x86_64 multiplication asm code
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>
2024-07-12 11:10:24 +02:00
Denys Vlasenko d745852f13 tls: P256: fix obscure x86_64 asm misbehavior, closes 15679
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>
2024-07-11 23:53:47 +02:00
Ron Yorston a3c5068306 md5/shaXsum: accept uppercase hex strings
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>
2024-07-11 18:17:31 +02:00
Petja Patjas 05e5d6a381 vi: Ensure that the edit buffer ends in a newline
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>
2024-07-11 17:52:18 +02:00
Ron Yorston 0af28b84e5 ash: remove defunct control character to save a few bytes
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>
2024-07-10 07:35:26 +02:00
Ron Yorston 87c31609f4 Makefile.flags: suppress clang warnings when cross-compiling
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>
2024-07-10 07:21:20 +02:00
Ron Yorston ba0f94458b ash: fix parsing of alias expansion + bash features
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>
2024-07-10 07:11:23 +02:00
Denys Vlasenko 0a88a7ae3b awk: mktime() with no arguments is not allowed
It was SEGVing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 07:04:28 +02:00
Denys Vlasenko 2eea3494f1 awk: improve comments and constants, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 06:58:51 +02:00
Denys Vlasenko 45d471d435 qwk: code shrink
function                                             old     new   delta
mk_splitter                                          100      96      -4
as_regex                                             103      99      -4
parse_expr                                           991     986      -5
awk_split                                            544     538      -6
awk_getline                                          559     552      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-26)             Total: -26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-09 17:50:58 +02:00
Denys Vlasenko 38335df9e9 awk: restore assignment precedence to be lower than ternary ?:
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>
2024-07-09 15:30:46 +02:00
Denys Vlasenko 49340d93ed awk: do not infinitely recurse getvar_s() if CONVFMT is set to a numeric value
function                                             old     new   delta
fmt_num                                              247     257     +10
evaluate                                            3385    3379      -6
getvar_s                                             111     102      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-15)             Total: -5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-09 03:04:26 +02:00
Natanael Copa fb08d43d44 awk: fix use after free (CVE-2023-42363)
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>
2024-07-09 02:34:00 +02:00
Denys Vlasenko eba9b33b45 chown: stop accepting deprecated USER.GROUP syntax, only : separator is allowed
function                                             old     new   delta
parse_chown_usergroup_or_die                         115      94     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-08 17:53:32 +02:00
Sertonix 9f262698cc wget: ignore header casing
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>
2024-07-08 15:02:58 +02:00
Denys Vlasenko a6ce017a8a typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-06-01 10:51:58 +02:00
Denys Vlasenko 41b47398f5 libbb: fix 64-bit bb_popcnt_long
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-05-31 23:37:28 +02:00
Denys Vlasenko 2075553a1b libbb: add bit counting function, use where appropriate
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>
2024-05-31 16:03:23 +02:00
Denys Vlasenko 5a68a246e7 nproc: prepare for arbitrarily large CPU masks
function                                             old     new   delta
get_malloc_cpu_affinity                                -      76     +76
nproc_main                                           216     206     -10
process_pid_str                                      250     206     -44
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 76/-54)             Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-05-31 11:58:48 +02:00
Denys Vlasenko fd47f05676 lineedit: print prompt and editing operations to stderr
For shells, this is mandated by standards

function                                             old     new   delta
input_backward                                       215     231     +16
read_line_input                                     3015    3028     +13
draw_custom                                           66      78     +12
put_cur_glyph_and_inc_cursor                         149     159     +10
put_prompt_custom                                     47      56      +9
show_history                                          40      46      +6
input_tab                                            927     933      +6
input_delete                                         136     142      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/0 up/down: 78/0)               Total: 78 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-04-13 18:40:20 +02:00
Yan Zhu 681e4f5d92 docproc: avoid segfault during file closing
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>
2024-04-13 17:57:46 +02:00
Ron Yorston e1a6874106 awk: fix segfault when compiled by clang
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>
2024-03-02 17:03:37 +01:00
Jones Syue 01f2b5976d crond: log5 fix typo, replace log level '4' with '5'
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>
2024-03-02 17:03:37 +01:00
Denys Vlasenko c5a1be25ba ash: fix handling of single-quoted strings in pattern substitution
function                                             old     new   delta
subevalvar                                          1576    1588     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-26 16:27:53 +01:00
Dario Binacchi f873c63085 ip link: support for the CAN netlink
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>
2024-02-26 14:10:10 +01:00
Denys Vlasenko 758b21402a hush: detect when terminating "done"/"fi" is missing
function                                             old     new   delta
parse_stream                                        2271    2292     +21
.rodata                                           105408  105427     +19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0)               Total: 40 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25 17:53:25 +01:00
Denys Vlasenko 2639f3bc72 hush: set G.ifs sooner (prevents segfault)
function                                             old     new   delta
set_G_ifs                                              -     151    +151
run_list                                            1024    1031      +7
run_pipe                                            1567    1445    -122
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 158/-122)           Total: 36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25 15:42:16 +01:00
Denys Vlasenko a97a2f1280 ls: do not truncate username/groupname to 8 chars
function                                             old     new   delta
.rodata                                           105412  105408      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25 01:06:30 +01:00
Dominique Martinet 5dc9ece3b9 sed: check errors writing file with sed -i
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>
2024-01-02 00:58:56 +01:00
Denys Vlasenko 1cac258521 time: implement %% and \escapes in -f FMT
function                                             old     new   delta
time_main                                           1217    1316     +99

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-01-01 22:24:42 +01:00
Natanael Copa 01e80ff9eb time: fix max resident set size unit
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>
2023-12-31 16:28:53 +01:00
Denys Vlasenko 789ccac7d9 awk: fix handling of empty fields
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>
2023-12-31 15:49:54 +01:00
Peter Korsgaard 5e0e54827f util-linux/lsusb.c: print manufacturer/product strings if available
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>
2023-12-13 15:59:47 +01:00
Denys Vlasenko 28f4126093 top: improve large PID display in memory ('s') mode
Display VSZ[RW] fields in more compact form if PID is wider.

function                                             old     new   delta
display_topmem_process_list                          564     614     +50
ulltoa5_and_space                                      -      14     +14
ulltoa6_and_space                                     14       -     -14
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/0 up/down: 64/-14)             Total: 50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-23 01:18:02 +01:00
Christian Franke a63b60bdd6 Cygwin: regenerate defconfig
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-13 11:32:35 +01:00
Denys Vlasenko 59cf2c23ae start-stop-daemon: make --output not depend on FANCY
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-08 14:42:00 +01:00
Denys Vlasenko 58ca629fd2 start-stop-daemon: do not lose error messages with -b
function                                             old     new   delta
start_stop_daemon_main                              1186    1206     +20
bb_daemonize_or_rexec                                196     212     +16
bb_banner                                             47      46      -1
packed_usage                                       34656   34645     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 36/-12)             Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-08 14:07:20 +01:00
Denys Vlasenko 2de67a62e8 start-stop-daemon: typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-08 12:36:11 +01:00
Louai Al-Khanji 389c0458da start-stop-daemon: implement option -O|--output
If specified redirect command stdout and stderr to given pathname.

function                                             old     new   delta
start_stop_daemon_main                              1130    1186     +56
start_stop_daemon_longopts                           164     173      +9
packed_usage                                       34653   34656      +3
.rodata                                           105384  105386      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 70/0)               Total: 70 bytes

Signed-off-by: Louai Al-Khanji <louai@astranis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 21:44:07 +01:00
Petr Vorel d17c0a348f sleep: Update doc
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>
2023-11-07 16:59:09 +01:00
Denys Vlasenko da8d1d84fd start-stop-daemon: update comment, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 15:59:11 +01:00
ejaaskel 73f28134fc start-stop-daemon: add -d DIR chdir option
Add option to change the running directory before starting the process.
This can be done using -d or --chdir options. Add also test cases to
start-stop-daemon to test out the directory change option.

function                                             old     new   delta
packed_usage                                       34602   34648     +46
start_stop_daemon_main                              1107    1130     +23
start_stop_daemon_longopts                           156     164      +8
.rodata                                           105382  105384      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 79/0)               Total: 79 bytes

Signed-off-by: ejaaskel <esa.jaaskela@suomi24.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 07:12:40 +01:00
Denys Vlasenko 0c71497e65 start-stop-daemon: fix --help: -K or -S is required
function                                             old     new   delta
.rodata                                           105381  105382      +1
packed_usage                                       34638   34602     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-36)             Total: -35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-11-07 06:55:35 +01:00
Russ Dill e265c8d4c0 udhcp: Avoid leaking uninitialized/stale data
I noticed a commit in connman:

"gdhcp: Avoid leaking stack data via unitiialized variable" [1]

Since gdhcp is just BusyBox udhcp with the serial numbers filed off, I
checked if BusyBox udhcp has a related issue.

The issue is that the get_option logic assumes any data within the
memory area of the buffer is "valid". This reduces the complexity of the
function at the cost of reading past the end of the actually received
data in the case of specially crafted packets. This is not a problem
for the udhcp_recv_kernel_packet data path as the entire memory
area is zeroed. However, d4/d6_recv_raw_packet does not zero the
memory.

Note that a related commit [2] is not required as we are zeroing
any data that can be read by the get_option function.

[1] https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=a74524b3e3fad81b0fd1084ffdf9f2ea469cd9b1
[2] https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=58d397ba74873384aee449690a9070bacd5676fa

function                                             old     new   delta
d4_recv_raw_packet                                   484     497     +13
d6_recv_raw_packet                                   216     228     +12
.rodata                                           105390  105381      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 25/-9)              Total: 16 bytes

Signed-off-by: Russ Dill <russ.dill@gmail.com>
Cc: Colin Wee <cwee@tesla.com>
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-04 16:46:35 +02:00
Denys Vlasenko 5fa39d48d5 syslogd: fix breakage caused by "daemonize _after_ init" change
function                                             old     new   delta
syslogd_init                                        1007    1140    +133
create_socket                                        143       -    -143
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 133/-143)          Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-03 19:16:10 +02:00
Denys Vlasenko 92ab29fcf0 awk: implement -E; do not reorder -f and -e
function                                             old     new   delta
awk_main                                             843     891     +48
next_input_file                                      243     261     +18
packed_usage                                       34631   34638      +7
.rodata                                           105391  105390      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 73/-1)              Total: 72 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 15:24:06 +02:00
Nero 6d22c9abc2 install: Fix chown resetting suid/sgid bits from chmod
Since Linux 2.2.13, chown(2) resets the suid/gid bits for all users.
This patch changes the ordering so that chmod gets called after chown.

This behavior follows GNU coreutils.

Signed-off-by: Nero <nero@w1r3.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 14:26:27 +02:00
Denys Vlasenko 791b222dd5 sleep: fix "sleep -- ARGS"
function                                             old     new   delta
sleep_main                                           116     119      +3
printf_main                                          860     837     -23
single_argv                                           50      25     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48)             Total: -45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-10-02 13:56:32 +02:00
Ron Yorston 2cc9d436e8 tsort: avoid use-after-free
When the input data contained a cycle it was possible for tsort to
attempt to access freed nodes.  This sometimes resulted in the
test case 'echo a b b a | tsort' crashing.

Don't free nodes when they're removed from the graph.

function                                             old     new   delta
tsort_main                                           621     596     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-08-31 09:41:53 +02:00
zhuyan ed4a24dfd1 ash: initialize basepf.buf in ash
When I planned to print the command in read_line_input, I found that after
the system started, the command printed for the first time was always
garbled.

After analysis, it is found that in the init() function of ash, the
variable basepf.buf is not initialized after applying for memory, resulting
in garbled initial data. Then assign it to the global variable
g_parsefile->buf in ash.c, and then pass g_parsefile->buf to the parameter
command of the function read_line_input in the function preadfd(), and
finally cause it to be garbled when the command is printed by
read_line_input.

The call stack is as follows:
 #0  read_line_input (st=0xb6fff220, prompt=0xb6ffc910 "\\[\\033[32m\\]\\h \\w\\[\\033[m\\] \\$ ", command=command@entry=0xb6ffc230 "P\325\377\266P\325\377\266", maxsize=maxsize@entry=1024) at libbb/lineedit.c:2461
 #1  0x0043ef8c in preadfd () at shell/ash.c:10812
 #2  preadbuffer () at shell/ash.c:10914
 #3  pgetc () at shell/ash.c:10997
 #4  0x00440c20 in pgetc_eatbnl () at shell/ash.c:11039
 #5  0x00440cbc in xxreadtoken () at shell/ash.c:13157
 #6  0x00440f40 in readtoken () at shell/ash.c:13268
 #7  0x00441234 in list (nlflag=nlflag@entry=1) at shell/ash.c:11782
 #8  0x004420e8 in parsecmd (interact=<optimized out>) at shell/ash.c:13344
 #9  0x00442c34 in cmdloop (top=top@entry=1) at shell/ash.c:13549
 #10 0x00444e4c in ash_main (argc=<optimized out>, argv=0x444e4c <ash_main+1328>) at shell/ash.c:14747
 #11 0x00407954 in run_applet_no_and_exit (applet_no=9, name=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1024
 #12 0x00407b68 in run_applet_and_exit (name=0xbefffe56 "ash", argv=0x9) at libbb/appletlib.c:1047
 #13 0x00407f88 in main (argc=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1181

Fixes: 82dd14a510 ("ash: use CONFIG_FEATURE_EDITING_MAX_LEN")

Signed-off-by: zhuyan <zhuyan34@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-08-31 02:20:19 +02:00
Denys Vlasenko 8f0845cad7 libbb: rename source files, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-18 16:41:12 +02:00
Denys Vlasenko c484846c44 introduce and use exitcode_t
function                                             old     new   delta
strings_main                                         422     420      -2
setfattr_main                                        175     173      -2
brctl_main                                          1548    1546      -2
makedevs_main                                        979     975      -4
rev_main                                             337     332      -5
getfattr_main                                        307     302      -5
cut_main                                            1201    1196      -5
cksum_main                                           398     393      -5
umount_main                                          573     565      -8
ln_main                                              516     508      -8
expand_main                                          660     652      -8
df_main                                             1068    1060      -8
renice_main                                          346     332     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/13 up/down: 0/-76)            Total: -76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-17 17:29:36 +02:00
Denys Vlasenko a6a102ec4c getfattr: fix "getfattr NOTEXIST" - now prints error msg
function                                             old     new   delta
getfattr_main                                        309     307      -2
.rodata                                           105395  105391      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6)               Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-17 09:36:17 +02:00
YU Jincheng cf809e2f2d getfattr: new applet
function                                             old     new   delta
getfattr_main                                          -     309    +309
print_attr                                             -     115    +115
packed_usage                                       34576   34631     +55
.rodata                                           105349  105395     +46
lgetxattr                                              -      41     +41
getxattr                                               -      41     +41
llistxattr                                             -      35     +35
listxattr                                              -      35     +35
applet_names                                        2806    2815      +9
applet_main                                         1620    1624      +4
------------------------------------------------------------------------------
(add/remove: 7/0 grow/shrink: 4/0 up/down: 690/0)             Total: 690 bytes

Signed-off-by: YU Jincheng <shana@zju.edu.cn>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-16 14:40:44 +02:00
Denys Vlasenko ab755f4925 hwclock: force LONG_OPTS, stop accepting non-compatible -t
function                                             old     new   delta
hwclock_main                                         576     579      +3
.rodata                                           105404  105349     -55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 3/-55)             Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-14 16:37:24 +02:00
Andrej Picej d70256a5c7 hwclock: add get/set parameters option
In kernel 5.16 special ioctls were introduced to get/set RTC parameters.
Add option to get/set parameters into busybox version of hwclock.
Implementation is similar to the one already used in linux-utils hwclock
tool.

Example of parameter get use:
$ hwclock -g 2
The RTC parameter 0x2 is set to 0x2.
$ hwclock --param-get bsm
The RTC parameter 0x2 is set to 0x2.

Example of parameter set use:
$ hwclock -p 2=1
The RTC parameter 0x2 will be set to 0x1.
$ hwclock -p bsm=2
The RTC parameter 0x2 will be set to 0x2.

function                                             old     new   delta
hwclock_main                                         298     576    +278
.rodata                                           105231  105400    +169
packed_usage                                       34541   34576     +35
static.hwclock_longopts                               60      84     +24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 506/0)             Total: 506 bytes

Signed-off-by: Andrej Picej <andrej.picej@norik.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-12 16:27:49 +02:00
Denys Vlasenko 9fc5933b10 ntpd: fix a warning on 32-bit arch build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:29:38 +02:00
Denys Vlasenko 69d33db445 i2ctransfer: fix build warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:27:26 +02:00
Denys Vlasenko 5353df91cb Update applet size estimates
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:25:21 +02:00
Denys Vlasenko a9047e0980 ash: tweak comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 12:02:34 +02:00
Denys Vlasenko ae351311da ash: remove "volatile" specifier from suppress_int
function                                             old     new   delta
aliascmd                                             274     278      +4
signal_handler                                        81      80      -1
static.redirectsafe                                  144     141      -3
unwindlocalvars                                      219     215      -4
trapcmd                                              333     329      -4
setvar                                               164     160      -4
setpwd                                               167     163      -4
setinputfile                                         216     212      -4
setcmd                                                76      72      -4
readcmd                                              221     217      -4
raise_exception                                       26      22      -4
out2str                                               37      33      -4
out1str                                               32      28      -4
freejob                                               89      85      -4
forkchild                                            616     612      -4
fg_bgcmd                                             298     294      -4
expandarg                                            949     945      -4
evaltree                                             753     749      -4
evalsubshell                                         173     169      -4
evalpipe                                             346     342      -4
evalfun                                              408     404      -4
cdcmd                                                699     695      -4
ash_main                                            1240    1236      -4
__pgetc                                              589     585      -4
unaliascmd                                           152     147      -5
unalias                                               51      46      -5
umaskcmd                                             253     248      -5
stalloc                                               97      92      -5
shiftcmd                                             144     139      -5
setinputstring                                        73      68      -5
redirect                                            1068    1063      -5
recordregion                                          81      76      -5
pushstring                                           160     155      -5
popstring                                            120     115      -5
popstackmark                                          69      64      -5
popredir                                             123     118      -5
popfile                                              110     105      -5
out1fmt                                               45      40      -5
newline_and_flush                                     39      34      -5
ifsfree                                               66      61      -5
growstackblock                                       146     141      -5
freestrings                                           95      90      -5
fmtstr                                                59      54      -5
flush_stdout_stderr                                   23      18      -5
dowait                                               577     572      -5
delete_cmd_entry                                      52      47      -5
clearcmdentry                                         98      93      -5
ash_arith                                             79      74      -5
argstr                                              1404    1399      -5
evalcommand                                         1523    1515      -8
removerecordregions                                  219     209     -10
mklocal                                              284     274     -10
find_command                                         893     883     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/52 up/down: 4/-251)          Total: -247 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 11:13:51 +02:00
Denys Vlasenko 5e0411a7fb ash: disable sleep as builtin, closes 15619
Has a few annoying problems:
* sleepcmd() -> sleep_main(), the parsing of bad arguments exits the shell.
* sleep_for_duration() in sleep_main() has to be interruptible for
  ^C traps to work, which may be a problem for other users
  of sleep_for_duration().
* BUT, if sleep_for_duration() is interruptible, then SIGCHLD interrupts it
  as well (try "/bin/sleep 1 & sleep 10").
* sleep_main() must not allocate anything as ^C in ash longjmp's.
  (currently, allocations are only on error paths, in message printing).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 10:53:23 +02:00
Yousong Zhou 6ce1dc2e91 libiproute: fix filtering ip6 route by table id
Otherwise

 - "ip -6 route show" shows routes from all tables
 - "ip -6 route show table 200" shows nothing

function                                             old     new   delta
print_route                                         1962    1941     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-21)             Total: -21 bytes

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-09 20:26:23 +02:00
Denys Vlasenko e41e481fd5 hush: fix a compile failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-08 17:57:42 +02:00
Denys Vlasenko 07a95cfcab ash: disable check for "good" function name, bash does not check this
function                                             old     new   delta
.rodata                                           105304  105261     -43
parse_command                                       1696    1633     -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106)           Total: -106 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-04 14:38:25 +02:00
Denys Vlasenko e5692e2342 hush: quote values in "readonly" output
function                                             old     new   delta
builtin_readonly                                      61     107     +46
builtin_export                                       140     145      +5
.rodata                                           105321  105304     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-17)             Total: 34 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-03 14:30:59 +02:00
Denys Vlasenko cc9543fed1 shell/math: avoid $((3**999999999999999999)) to take years
function                                             old     new   delta
arith_apply                                          991    1030     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02 19:32:12 +02:00
Denys Vlasenko 045924ed7d shell/math: do not accept $((36#@))
function                                             old     new   delta
parse_with_base                                      170     174      +4
arith_apply                                          996     991      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-5)               Total: -1 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02 17:58:20 +02:00
Denys Vlasenko 38f769ab4e shell/math: code shrink
function                                             old     new   delta
arith_apply                                          999     996      -3
evaluate_string                                     1295    1291      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7)               Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-30 19:16:41 +02:00
Denys Vlasenko 6a0ba67382 shell/math: code shrink
function                                             old     new   delta
arith_apply                                         1023     996     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-29 11:01:50 +02:00
Denys Vlasenko 800207b90a shell/math: code shrink
function                                             old     new   delta
arith_apply                                         1015    1023      +8
evaluate_string                                     1309    1295     -14
.rodata                                           105344  105321     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 8/-37)             Total: -29 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-28 14:18:35 +02:00
Denys Vlasenko e619a25a55 shell/math: improve comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26 11:08:40 +02:00
Denys Vlasenko 5d8f8570c0 shell/math: rename TOK_NUM to TOK_VALUE, improve comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26 10:02:54 +02:00
Denys Vlasenko c1c267fd36 shell/math: bash-compatible handling of too large numbers
function                                             old     new   delta
parse_with_base                                        -     170    +170
evaluate_string                                     1477    1309    -168
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 170/-168)            Total: 2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-25 17:42:05 +02:00
Denys Vlasenko 019dd31150 shell/math: disable debug again
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19 10:23:58 +02:00
Denys Vlasenko db0e886735 shell/math: $((1?)) has one-too-small opstack, fix this
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19 10:22:15 +02:00
Denys Vlasenko a165098922 shell/math: fix comments about jammed-together num+num corner cases
function                                             old     new   delta
evaluate_string                                     1478    1470      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19 09:44:04 +02:00
Denys Vlasenko 79b90cbece shell/math: add note on ERANGE
function                                             old     new   delta
evaluate_string                                     1488    1478     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 20:15:35 +02:00
Denys Vlasenko 10cce8ae35 shell/math: explain why we use separate &end
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 19:30:22 +02:00
Denys Vlasenko 7701b526a7 shell/math: code shrink
function                                             old     new   delta
evaluate_string                                     1498    1491      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 19:20:10 +02:00
Denys Vlasenko 8309c9159f shell/math: eliminate redundant endofname()
function                                             old     new   delta
evaluate_string                                     1486    1498     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 19:03:05 +02:00
Denys Vlasenko b61fd8ec5a shell: typo fix in tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:49:00 +02:00
Denys Vlasenko 2d06c83b87 shell/math: code shrink
function                                             old     new   delta
evaluate_string                                     1489    1486      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:31:55 +02:00
Denys Vlasenko c72c5552ed shell/math: decrease stack usage by not allocating copies of variable names
We risk exhaust stack with alloca() with old code.

function                                             old     new   delta
arith_apply                                          990    1023     +33
evaluate_string                                     1467    1494     +27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 60/0)               Total: 60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:12:14 +02:00
Denys Vlasenko 182e5a4d00 shell/math: decrease stack usage
function                                             old     new   delta
evaluate_string                                     1412    1467     +55

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18 18:12:04 +02:00
Denys Vlasenko 96769486e2 shell: move varcmp() to shell_common.h and use it in hush
function                                             old     new   delta
unset_local_var                                        -     112    +112
findvar                                               31      35      +4
set_vars_and_save_old                                144     141      -3
helper_export_local                                  235     230      -5
set_local_var                                        425     416      -9
handle_changed_special_names                          38      27     -11
builtin_unset                                        154     141     -13
builtin_getopts                                      404     391     -13
get_local_var_value                                  281     260     -21
get_ptr_to_local_var                                  71      45     -26
unset_local_var_len                                  139       -    -139
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/8 up/down: 116/-240)         Total: -124 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 21:13:13 +02:00
Denys Vlasenko d0441222db ash: code shrink
function                                             old     new   delta
setvar                                               166     164      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 20:45:02 +02:00
Denys Vlasenko 2ca9c45953 shell/read: do not allow empty variable name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 19:52:20 +02:00
Denys Vlasenko 822590f5e2 shell/math: eliminate some redundant stores on return code path
function                                             old     new   delta
evaluate_string                                     1432    1412     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 19:21:28 +02:00
Denys Vlasenko 19a74a54de shell/math: change ?: nesting code to not have 63 level nesting limitation
function                                             old     new   delta
evaluate_string                                     1406    1432     +26
arith                                                 36      29      -7
arith_apply                                          998     990      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 26/-15)             Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 11:03:02 +02:00
Denys Vlasenko 6221832bc1 shell/math.h: update comments, rearrange struct members for smaller code
function                                             old     new   delta
arith_apply                                         1000     998      -2
evaluate_string                                     1414    1406      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10)             Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 10:40:29 +02:00
Denys Vlasenko d6f98f214b shell/math: code shrink
function                                             old     new   delta
evaluate_string                                     1432    1414     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 00:28:49 +02:00
Denys Vlasenko 550696d492 shell/math: tweka comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-16 20:47:43 +02:00
Denys Vlasenko e127985839 shell/math: fix ?: to not evaluate not-taken branches
This fixes ash-arith-arith-ternary1/2.tests

function                                             old     new   delta
evaluate_string                                     1271    1432    +161
arith_apply                                          968    1000     +32
arith                                                 22      36     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 207/0)             Total: 207 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-16 19:51:01 +02:00
Denys Vlasenko f8263528cd shell/math: simplify handling of unary plus
function                                             old     new   delta
evaluate_string                                     1257    1271     +14
arith_apply                                          977     968      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9)               Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 17:16:46 +02:00
Denys Vlasenko 38f423cc9c shell/math: explain the logic, small tweak to make code smaller
function                                             old     new   delta
evaluate_string                                     1258    1257      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 16:46:31 +02:00
Denys Vlasenko ea6dcbe283 shell/math: fix order of expansion of variables to numbers
This fixes arith-assign-in-varexp1.tests

function                                             old     new   delta
evaluate_string                                     1132    1258    +126
arith_lookup_val                                     143       -    -143
arith_apply                                         1132     977    -155
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 126/-298)         Total: -172 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 13:56:12 +02:00
Denys Vlasenko 22cb0d573a shell: document another arithmetic discrepancy with bash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 12:44:43 +02:00
Denys Vlasenko 648f506949 libbb: code shrink: introduce and use [_]exit_FAILURE()
function                                             old     new   delta
exit_FAILURE                                           -       7      +7
_exit_FAILURE                                          -       7      +7
run                                                  198     199      +1
restore_state_and_exit                               114     115      +1
xbsd_write_bootstrap                                 399     397      -2
vfork_compressor                                     209     207      -2
sig_handler                                           12      10      -2
serial_ctl                                           154     152      -2
parse_args                                          1169    1167      -2
onintr                                                21      19      -2
make_new_session                                     493     491      -2
login_main                                           988     986      -2
gotsig                                                35      33      -2
do_iplink                                           1315    1313      -2
addgroup_main                                        397     395      -2
inetd_main                                          1911    1908      -3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/12 up/down: 16/-25)            Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 11:55:56 +02:00
Denys Vlasenko 61a4959251 shell/math: remove special code to handle a?b?c:d:e, it works without it now
The "hack" to virtually parenthesize ? EXPR : made this unnecessary.
The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated
before continuing with the second :

function                                             old     new   delta
evaluate_string                                     1148    1132     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 11:22:13 +02:00
Denys Vlasenko 5f56a03882 shell/math: fix parsing of ?: and explain why it's parsed that way
This fixes arith-precedence1.tests.

This breaks arith-ternary2.tests again (we now evaluate variables
on not-taken branches). We need a better logic here anyway:
not only bare variables should not evaluate when not-taken:
	1 ? eval_me : do_not_eval
but any (arbitrarily complex) expressions shouldn't
evaluate as well!
	1 ? var_is_set=1 : ((var_is_not_set=2,var2*=4))

function                                             old     new   delta
evaluate_string                                     1097    1148     +51

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 10:14:43 +02:00
Denys Vlasenko 3829d8b675 shell/math: simpler insertion of "fake" last RPAREN
Skip one pass through token table, since we know the result.

function                                             old     new   delta
evaluate_string                                     1095    1097      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15 09:19:48 +02:00
Denys Vlasenko 2ff01bb699 shell: sync ash/hush test scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 15:19:02 +02:00
Denys Vlasenko 66139330fc shell/math: trivial code shrink
function                                             old     new   delta
arith_apply                                         1143    1132     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 13:59:11 +02:00
Denys Vlasenko 3df885abe3 shell/math: fix the order of variable resolution in binops
function                                             old     new   delta
arith_apply                                         1134    1143      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:33:59 +02:00
Denys Vlasenko 5febdb1223 shell/math: remove now-unused second_val
function                                             old     new   delta
arith_apply                                         1137    1134      -3
evaluate_string                                     1101    1095      -6
arith_lookup_val                                     150     143      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-16)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:10:45 +02:00
Denys Vlasenko 46dccd2ec0 shell/math: fix nested ?: and do not parse variables in not-taken branch
Fixes arith-ternary1.tests and arith-ternary_nested.tests

function                                             old     new   delta
evaluate_string                                     1043    1101     +58
arith_apply                                         1087    1137     +50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 108/0)             Total: 108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 11:07:30 +02:00
Denys Vlasenko a02450ff0b shell/math: remove a redundant check
function                                             old     new   delta
arith_apply                                         1134    1087     -47

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 01:05:40 +02:00
Denys Vlasenko 8acbf31708 shell/math: document ternary ?: op's weirdness, add code comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14 00:41:18 +02:00
Denys Vlasenko 373f64eef3 syslogd: daemonize _after_ init (so that init errors are visible, if they occur)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:25:13 +02:00
Denys Vlasenko 02378ce20c syslogd: decrease stack usage, ~50 bytes
function                                             old     new   delta
syslogd_init                                           -    1007   +1007
syslogd_main                                        1619     636    -983
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 1007/-983)          Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:24:56 +02:00
Denys Vlasenko c1d7507a4d shell/math: fix one name check, other minor cleanups
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 16:15:18 +02:00
Denys Vlasenko 8ccb3f7b13 shell: add a few yet-failing arithmentic tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 15:21:22 +02:00
Denys Vlasenko a4f30f3c70 shell/math: reduce stack usage
function                                             old     new   delta
arith_apply                                         1123    1134     +11
arith_lookup_val                                     140     145      +5
evaluate_string                                     1053    1047      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-6)              Total: 10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-13 13:55:13 +02:00
Denys Vlasenko d417193cf3 shell: avoid segfault on ${0::0/0~09J}. Closes 15216
function                                             old     new   delta
evaluate_string                                     1011    1053     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 17:48:47 +02:00
Denys Vlasenko bab8828b0d hush: fix expansion of space in "a=${a:+$a }c" construct
function                                             old     new   delta
encode_then_append_var_plusminus                     554     552      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 16:39:32 +02:00
Denys Vlasenko 8f0e4c42c6 udhcpd: optional BOOTP support
from Adam Goldman <adamg@pobox.com>

This patch makes udhcpd respond correctly to queries from BOOTP clients.

It contains the following changes:

The end field, or DHCP_END option, is required in DHCP requests but
optional in BOOTP requests. However, we still send an end
field in all replies, because some BOOTP clients expect one in replies
even if they didn't send one in the request.

Requests without a DHCP_MESSAGE_TYPE are recognized as BOOTP requests
and handled appropriately, instead of being discarded. We still require
an RFC 1048 options field, but we allow it to be empty.

Since a BOOTP client will keep using the assigned IP forever, we only
send a BOOTP reply if a static lease exists for that client.

BOOTP replies shouldn't contain DHCP_* options, so we omit them if there
was no DHCP_MESSAGE_TYPE in the request. Options other than DHCP_*
options are still sent.

The options field of a BOOTP reply must be exactly 64 bytes. If we
construct a reply with more than 64 bytes of options, we give up and log
an error instead of sending it. udhcp_send_raw_packet already pads the
options field to 64 bytes if it is too short.

This implementation has been tested against an HP PA-RISC client.

function                                             old     new   delta
.rodata                                           105247  105321     +74
udhcpd_main                                         1520    1591     +71
send_offer                                           419     470     +51
init_packet                                           81      97     +16
udhcp_init_header                                     75      88     +13
udhcp_scan_options                                   192     203     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 236/0)             Total: 236 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 13:22:47 +02:00
Denys Vlasenko 4bd70463c7 libbb: pass "" rather than NULL as format string in _nomsg functions
function                                             old     new   delta
bb_perror_nomsg_and_die                                9      10      +1
bb_perror_nomsg                                        9      10      +1
bb_verror_msg                                        480     469     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 2/-11)              Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12 10:19:29 +02:00
Denys Vlasenko 2ca39ffd44 awk: fix subst code to handle "start of word" pattern correctly (needs REG_STARTEND)
function                                             old     new   delta
awk_sub                                              637     714     +77

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-08 10:42:39 +02:00
Denys Vlasenko 113685fbcd awk: fix SEGV on read error in -f PROGFILE
function                                             old     new   delta
awk_main                                             829     843     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-07 10:54:34 +02:00
Denys Vlasenko f4789164e0 awk: code shrink
function                                             old     new   delta
awk_sub                                              544     548      +4
exec_builtin                                        1136    1130      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-6)               Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-06 12:48:11 +02:00
Denys Vlasenko 5f84c56336 awk: fix backslash handling in sub() builtins
function                                             old     new   delta
awk_sub                                              559     544     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-03 00:42:10 +02:00
Denys Vlasenko 0256e00a9d awk: fix precedence of = relative to ==
Discovered while adding code to disallow assignments to non-lvalues

function                                             old     new   delta
parse_expr                                           936     991     +55
.rodata                                           105243  105247      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0)               Total: 59 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-30 16:44:04 +02:00
Denys Vlasenko fe0b798548 tunctl: code shrink
function                                             old     new   delta
.rodata                                           105246  105243      -3
tunctl_main                                          349     344      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-8)               Total: -8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-29 14:47:10 +02:00
Denys Vlasenko 721bf6eaf4 awk: printf(INVALID_FMT) prints it verbatim
function                                             old     new   delta
awk_printf                                           628     640     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-29 10:55:40 +02:00
Denys Vlasenko 4d7339204f awk: shrink - use setvar_sn() to set variables from non-NUL terminated strings
function                                             old     new   delta
setvar_sn                                              -      39     +39
exec_builtin                                        1145    1136      -9
awk_getline                                          591     559     -32
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 39/-41)             Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 18:08:06 +02:00
Denys Vlasenko 05e60007d4 awk: code shrink
function                                             old     new   delta
awk_getline                                          620     591     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 17:51:59 +02:00
Denys Vlasenko b76b420b5d awk: fix closing of non-opened file
function                                             old     new   delta
setvar_ERRNO                                           -      53     +53
.rodata                                           105252  105246      -6
awk_getline                                          639     620     -19
evaluate                                            3402    3377     -25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 53/-50)              Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 17:25:56 +02:00
Denys Vlasenko 9790eb73c8 libbb/dump: code shrink
function                                             old     new   delta
.rodata                                           105252  105246      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-28 13:32:07 +02:00
Denys Vlasenko 21dce1c3c3 awk: do not read ARGIND, only set it (gawk compat)
function                                             old     new   delta
next_input_file                                      216     243     +27
evaluate                                            3396    3402      +6
awk_main                                             826     829      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0)               Total: 36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 19:11:28 +02:00
Denys Vlasenko 5c8a9dfd97 awk: remove a local variable "caching" a struct member
Since we take its address, the variable lives on stack (not a GPR).
Thus, nothing is improved by caching it.

function                                             old     new   delta
awk_getline                                          642     639      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 18:21:38 +02:00
Denys Vlasenko 528808bcd2 awk: get rid of one indirection level for iF (input file structure)
function                                             old     new   delta
try_to_assign                                          -      91     +91
next_input_file                                      214     216      +2
awk_main                                             827     826      -1
evaluate                                            3403    3396      -7
is_assignment                                         91       -     -91
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/2 up/down: 93/-99)             Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 18:05:42 +02:00
Denys Vlasenko 84ff1825dd awk: fix splitting with default FS
function                                             old     new   delta
awk_split                                            543     544      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 16:17:38 +02:00
Denys Vlasenko 9225f9684f libbb/dump: make xxd_displayoff member conditional on xxd
With xxd not selected:

function                                             old     new   delta
display                                             1459    1444     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-27 14:52:17 +02:00
Denys Vlasenko 6d9427420b od: -l,I,L indeed depend on sizeof(long), fix this
function                                             old     new   delta
.rodata                                           105255  105252      -3
od_main                                             1917    1901     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 20:17:04 +02:00
Denys Vlasenko 5dcc443dba awk: fix use-after-realloc (CVE-2021-42380), closes 15601
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 19:36:58 +02:00
Denys Vlasenko d7814f5727 hexdump: code shrink
function                                             old     new   delta
add_format                                             -      50     +50
add_first                                             10       -     -10
hexdump_main                                         401     366     -35
.rodata                                           105306  105255     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 50/-96)            Total: -46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 16:43:40 +02:00
Denys Vlasenko 283cba78f2 hexdump, xxd: shrink strings
function                                             old     new   delta
add_first                                             12      10      -2
.rodata                                           105321  105306     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 14:46:29 +02:00
Denys Vlasenko 34751d8bf9 libbb/dump: correct handling of 1-byte signed int format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 14:10:38 +02:00
Denys Vlasenko 8fab211141 libbb/dump: use fputs_stdout where appropriate
function                                             old     new   delta
display                                             1485    1483      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:39:33 +02:00
Denys Vlasenko de851bc9b2 od, hexdump: byte 0x11 is "dc1" not "dcl"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:33:08 +02:00
Denys Vlasenko 25a10ffe1f od: actually remove -IL from --help, as comment says
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 13:01:41 +02:00
Denys Vlasenko 60d4d55b87 od: support -DOHXIL
function                                             old     new   delta
od_main                                             1866    1917     +51
.rodata                                           105306  105321     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 66/0)               Total: 66 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 12:56:17 +02:00
Denys Vlasenko 3c6f6382ee libbb/dump: conditionalize code used only by xxd and od
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 12:34:11 +02:00
Denys Vlasenko aa4d303a31 od: fix default format, shrink
function                                             old     new   delta
od_main                                              556     568     +12
.rodata                                           104613  104555     -58
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 12/-58)            Total: -46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-26 04:27:43 +02:00
Denys Vlasenko 0c3270f7e5 od: stop printing extra trailing spaces
function                                             old     new   delta
.rodata                                           104598  104613     +15
display                                             1475    1485     +10
od_main                                              549     556      +7
rewrite                                              971     967      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 32/-4)              Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 23:48:13 +02:00
Denys Vlasenko 6882a933cf od: implement -B
function                                             old     new   delta
.rodata                                           105305  105306      +1
od_main                                             1880    1866     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 1/-14)             Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 22:17:18 +02:00
Denys Vlasenko ce4cfc33ca od: correct -i, enable tests which pass for DESKTOP too
function                                             old     new   delta
.rodata                                           105302  105305      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 19:51:37 +02:00
Denys Vlasenko e2287f99fe od: for !DESKTOP, match output more closely to GNU coreutils 9.1, implement -s
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 17:40:20 +02:00
David Leonard 64bdd7566c od: add tests
* Added tests for od (non-DESKTOP little-endian)
* Allow 'optional' to invert meaning of a config option with '!'

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 15:32:03 +02:00
David Leonard 2bda790fd1 od: fix -O
od with option -O (4-byte octal) was incorrectly displaying 2-byte
decimal when built without CONFIG_DESKTOP

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 15:32:03 +02:00
Denys Vlasenko b5be8da350 hush: make "false" built-in
function                                             old     new   delta
bltins1                                              384     396     +12
builtin_false                                          -       6      +6
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 18/0)               Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 15:24:56 +02:00
Denys Vlasenko 6824298ab4 hush: fix ELIF cmd1;cmd2 THEN ... not executing cmd2, closes 15571
function                                             old     new   delta
run_list                                            1012    1024     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25 14:22:10 +02:00
Karsten Sperling 3e83699ce2 ash: use-after-free in bash pattern substitution
Commit daa66ed6 fixed a number of use-after-free bugs in bash pattern
substitution, however one "unguarded" STPUTC remained, which is fixed here.

function                                             old     new   delta
subevalvar                                          1564    1576     +12

Signed-off-by: Karsten Sperling <ksperling@apple.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-18 16:49:54 +02:00
Denys Vlasenko c5682813ab examples/var_service/README: fix an error
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-18 13:30:10 +02:00
Denys Vlasenko 2f663a6f7d cpio: tweak --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 20:35:16 +02:00
Denys Vlasenko dc84002a82 nslookup: code shrink
function                                             old     new   delta
send_queries                                         725     723      -2
nslookup_main                                        822     820      -2
add_query                                             89      86      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-7)               Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 19:32:29 +02:00
Denys Vlasenko 62775ec4b3 nslookup: ensure unique transaction IDs for the DNS queries
Based on patch by Uwe Kleine-König.

It makes sense to actually see the nitty-gritty details of DNS
querying, so bringing in (commented-out) musl's DNS request code.

function                                             old     new   delta
nslookup_main                                        760     822     +62

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 19:21:45 +02:00
Denys Vlasenko 3a7f00eadc hush: add comment about abort on syntax error %{^}
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-09 14:02:06 +02:00
Denys Vlasenko 465f05a420 build system: fix "Config.in:117 error: Overlong line"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-08 12:31:34 +02:00
Denys Vlasenko 3c8e540eb7 hush: fix an interactive abort on error
function                                             old     new   delta
parse_and_run_stream                                 140     155     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-08 12:27:50 +02:00
Uwe Kleine-König 40fa8eb998 build system: Make it possible to build with 64bit time_t
On most 32bit architectures time_t (and a few other time related types)
are a signed 32bit wide integer type.
As a consequence they can only represent dates between

	Fri Dec 13 08:45:52 PM UTC 1901

(-0x80000000 seconds before Jan 1 1970) and

	Tue Jan 19 03:14:07 AM UTC 2038

(0x7fffffff seconds after Jan 1 1970). Given that some machines that are
built today have an expected lifetime of >15 years, this needs to be
extended. To to that, define the cpp symbol _TIME_BITS to 64 which
results in some magic in glibc to make time_t (and the few other time
related types) 64 bit wide.

This new switch CONFIG_TIME64 is in the spirit of CONFIG_LFS and only
expected to have the expected effect with glibc. On musl for examples
time_t already defaults to 64bit wide types.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-07 18:57:06 +02:00
Denys Vlasenko 07f8b6feac readlink: code shrink
function                                             old     new   delta
readlink_main                                        111     103      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-07 18:44:03 +02:00
Denys Vlasenko c6058d221a nmeter: improve %T fractionals display
function                                             old     new   delta
nmeter_main                                          751     786     +35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-07 18:35:22 +02:00
Denys Vlasenko 382e163497 factor: we can pack 21, not 20, 3-bit elements into packed wheel words
function                                             old     new   delta
packed_wheel                                         192     184      -8
factor_main                                          171     163      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-16)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-23 14:02:20 +02:00
Denys Vlasenko 7ddd233c80 ip: code shrink
function                                             old     new   delta
ipaddr_list_or_flush                                1089    1079     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-23 12:37:46 +02:00
Eric Blake d2b81b3dc2 readlink: support --, -n always
POSIX will be standardizing readlink (just the -n option) and realpath
(just -E and -e options):
https://www.austingroupbugs.net/view.php?id=1457

Change things for readlink so that the POSIX-mandated -n and -- work
even when disabling the non-standard (and partially non-working) -f
when FEATURE_READLINK_FOLLOW is clear.

POSIX also wants readlink to be verbose by default (if the argument is
not a symlink, readlink must output a diagnostic); I did NOT address
that one, because I'm waiting to see what the GNU Coreutils folks do:
https://lists.gnu.org/archive/html/bug-coreutils/2023-03/msg00035.html

Partial fix for https://bugs.busybox.net/show_bug.cgi?id=15466

function                                             old     new   delta
packed_usage                                       34538   34557     +19

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-16 18:01:44 +02:00
Ron Yorston 2ffd8986e2 tr: display usage for incorrect arguments
tr must have one or two non-option arguments.  Display the usage
message if any other number is present.

function                                             old     new   delta
.rodata                                           108389  108392      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 3/0)                 Total: 3 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-16 17:54:00 +02:00
Ron Yorston acae889dd9 ash,hush: tab completion of functions and aliases
Since commit 9e2a5668f (ash,hush: allow builtins to be tab-completed,
closes 7532) ash and hush have supported tab completion of builtins.

Other shells, bash and ksh for example, also support tab completion
of functions and aliases.

Add such support to ash and hush.

function                                             old     new   delta
ash_command_name                                       -      92     +92
hush_command_name                                      -      63     +63
ash_builtin_name                                      17       -     -17
hush_builtin_name                                     38       -     -38
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/0 up/down: 169/-55)           Total: 100 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Avi Halachmi <avihpit@yahoo.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-16 17:15:05 +02:00
Denys Vlasenko 90b607d79a hush: quote variable values printed by "set" (match ash behavior)
function                                             old     new   delta
builtin_set                                          258     301     +43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-13 09:20:24 +02:00
Denys Vlasenko 8b72877bab shuf: another tweak to COMMON_PREFIX_HACK code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-13 03:02:11 +02:00
Tomas Paukrt 7c1f975cdd build system: clean more files on make clean
Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2023-04-12 20:31:44 +02:00
Denys Vlasenko f7065aa9ae shuf: fix pfx_len calculation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 14:56:05 +02:00
Denys Vlasenko 8696f5d380 shuf: remove redundant code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 14:51:11 +02:00
Denys Vlasenko 238dab322a shuf: add (disabled) code to support very long numbers in -i LO-HI
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 14:47:24 +02:00
Akos Somfai 853cfe927f lineedit: fix crash when icanon set with -echo
When icanon is set with -echo (e.g. ssh from an emacs shell) then
S.state will remain null but later it will be deferenced causing ash to
crash. Fix: additional check on state.

Signed-off-by: Akos Somfai <akos.somfai@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 13:49:14 +02:00
Denys Vlasenko 550e6d8fbd sleep: fix error exit when called as "sh" builtin
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-12 12:23:36 +02:00
Denys Vlasenko 478b5ac2bc seq: fix yet another case of negative parameters not working
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-11 20:29:59 +02:00
Thomas Devoogdt cb57abb46f seedrng: fix for glibc <= 2.24 not providing random header
- dropped the wrong define (not sure why it was there)
 - <sys/random.h> not available if glibc <= 2.24
 - GRND_NONBLOCK not defined if <sys/random.h> not included
 - ret < 0 && errno == ENOSYS has to be true to get creditable set

Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-11 13:56:12 +02:00
Denys Vlasenko 200a9669fb seedrng: fix for glibc <= 2.24 not providing getrandom()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 17:26:04 +02:00
Tomas Paukrt 85e4805ae9 appletlib: fix "warning: unused variable applet_no"
Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 16:56:55 +02:00
Denys Vlasenko 7362d29794 ash: fix sleep built-in not running INT trap immediately on ^C
function                                             old     new   delta
sleep_for_duration                                   169     149     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 16:30:27 +02:00
Denys Vlasenko 611729eff3 mkfs_vfat: do not generate same volume_id when run in rapid succession
function                                             old     new   delta
mkfs_vfat_main                                      1502    1523     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 14:47:38 +02:00
Denys Vlasenko 9bc2b6e884 seq: accept negative parameters
function                                             old     new   delta
seq_main                                             429     476     +47
packed_usage                                       34557   34538     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 47/-19)             Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-10 14:33:20 +02:00
Denys Vlasenko a26711a2d1 libbb: consolidate NOMMU fix of restoring high bit in argv[0][0]
function                                             old     new   delta
fork_or_rexec                                         46      56     +10
bootchartd_main                                     1087    1079      -8
cpio_main                                            674     661     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-21)            Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-06 21:20:28 +02:00
Denys Vlasenko 05f2bedaeb ash: sleep builtin with no arguments should not exit
function                                             old     new   delta
sleep_main                                           116     143     +27
.rodata                                           105245  105268     +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 50/0)               Total: 50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 19:54:42 +02:00
Denys Vlasenko ff8fde111e hush: printf builtin with no arguments should not exit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 19:29:57 +02:00
Denys Vlasenko 46e92e1e56 ash: code shrink: do not take address of prefix(), allowing it to inline
function                                             old     new   delta
getjob                                               281     285      +4
prefix                                                13       -     -13
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 4/-13)              Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 17:30:03 +02:00
Denys Vlasenko a33d19eba8 ash: code shrink - reuse is_prefixed_with() from libbb
function                                             old     new   delta
changepath                                            67      68      +1
legal_pathopt                                         70      66      -4
prefix                                                34      13     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-25)             Total: -24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 15:19:13 +02:00
Denys Vlasenko 94780e3e8e ash: get rid of separate mail_var_path_changed flag variable
We can just clear mailtime_hash to zero and have the same effect.

function                                             old     new   delta
changemail                                             8      11      +3
mail_var_path_changed                                  1       -      -1
cmdloop                                              398     382     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 3/-17)             Total: -14 bytes
   text	   data	    bss	    dec	    hex	filename
1054786	    559	   5020	1060365	 102e0d	busybox_old
1054773	    559	   5020	1060352	 102e00	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 15:01:00 +02:00
Denys Vlasenko 7ababc3e3c ash: fix still-broken new mail detection
padvance() exit condition is return value < 0, not == 0.
After MAIL changing twice, the logic erroneously
concluded that "you have new mail".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 14:41:01 +02:00
Denys Vlasenko 2860b2530e ash: fix broken new mail detection
Mea culpa, in "Do not allocate stack string in padvance" commit
(I left an extraneous "break" statement).

function                                             old     new   delta
cmdloop                                              329     398     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-03 14:01:36 +02:00
Denys Vlasenko 6748e6494c hush (NOMMU): fix LINENO in execed children
function                                             old     new   delta
hush_main                                           1815    1851     +36
re_execute_shell                                     601     635     +34
.rodata                                           102721  102726      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 75/0)               Total: 75 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 23:17:53 +02:00
Denys Vlasenko fd5fb2d2b5 hush: speed up "big heredoc" code
function                                             old     new   delta
hush_main                                           1810    1815      +5
.rodata                                           102723  102721      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-2)                Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 22:52:08 +02:00
Denys Vlasenko 1409432d07 hush: add TODO comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 22:16:32 +02:00
Denys Vlasenko 00fc136843 ash: code shrink
function                                             old     new   delta
describe_command                                     323     320      -3
dotcmd                                               324     309     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-01 11:11:20 +02:00
Denys Vlasenko 262a845477 ash: exec: Stricter pathopt parsing - lost chunk
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-31 21:35:50 +02:00
Ron Yorston 098cd7ece4 ash: improve trap and jobs builtins in child shells
The trap and jobs builtins can be used to report information about
traps and jobs.  This works when they're called from the current
shell but in a child shell the required information is usually
cleared.  Special hacks allow:

- trap to work with command substitution;
- jobs to work with command substitution or in a pipeline.

Neither works with process substitution.

- Relax the test for the trap hack so it also supports pipelines.

- Pass the command to be evaluated to forkshell() in evalbackcmd()
  so trap and jobs both work with process substitution.

function                                             old     new   delta
forkchild                                            629     640     +11
argstr                                              1502    1496      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 11/-6)               Total: 5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-31 14:22:56 +02:00
Denys Vlasenko af5277f883 modprobe: call finit_module with MODULE_INIT_COMPRESSED_FILE if module name doesn't end with .ko
IOW: if name doesn't end with .ko, assume it's .gz/.xz or similar,
and ask kernel to uncompress it.

If finit_module(MODULE_INIT_COMPRESSED_FILE) fails, retry with
finit_module(0).

function                                             old     new   delta
bb_init_module                                       151     197     +46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-31 13:15:58 +02:00
Ron Yorston 470fa7b364 ash: make EPOCH variables work if RANDOM is disabled
Commit 1d37186fe2 (ash: add bash-compatible EPOCH variables) added
support for the EPOCHSECONDS and EPOCHREALTIME variables.

These variables are dynamic and therefore require the VDYNAMIC flag
to be non-zero.  However, this is only the case if support for the
RANDOM variable is enabled.

Give VDYNAMIC a non-zero value if either EPOCH variables or RANDOM
are enabled.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 16:45:13 +02:00
Ron Yorston f2e659415a lineedit: fix matching of directories when searching PATH
Commit 8baa643a3 (lineedit: match local directories when searching
PATH) included subdirectories of the current directory in the search
when tab-completing commands.

Unfortunately a short time later commit 1d180cd74 (lineedit: use
strncmp instead of is_prefixed_with (we know the length)) broke
this feature by returning an incorrect length for the array of paths.

Fix the length and reinstate matching of subdirectories.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 16:45:13 +02:00
Denys Vlasenko a59e5a7d08 libbb/sha: do not read shaNI variable twice, and factor out its setting
My gcc inlines both calls, so instead of "-20 bytes" I get only this:

function                                             old     new   delta
sha256_begin                                          84      83      -1
sha1_begin                                           114     111      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-4)               Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 15:46:32 +02:00
Denys Vlasenko bd76b75f72 libbb/sha: fix sha-NI instruction detection
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-29 15:17:00 +02:00
Denys Vlasenko 3253d7fe00 httpd: do not mangle cgi-bin/SCRIPT/params URLs
If cgi-bin/ prefix is seen, do not test the rest for existence,
whether it's a dir, and such.

function                                             old     new   delta
handle_incoming_and_exit                            2200    2212     +12

Reported here:
https://lists.zx2c4.com/pipermail/cgit/2023-March/004825.html

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-28 18:56:08 +02:00
David Leonard d8a3360380 find: implement -ok
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html

  -ok  utility_name  [argument ...] ;
    The -ok primary shall be equivalent to -exec, except that the use
    of a <plus-sign> to punctuate the end of the primary expression
    need not be supported, and find shall request affirmation of the
    invocation of utility_name using the current file as an argument
    by writing to standard error as described in the STDERR section. If
    the response on standard input is affirmative, the utility shall be
    invoked. Otherwise, the command shall not be invoked and the value
    of the -ok operand shall be false.

function                                             old     new   delta
do_exec                                              438     517     +79
parse_params                                        1833    1845     +12
static.params                                        288     292      +4
.rodata                                           100771  100775      +4
packed_usage                                       34543   34541      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 99/-2)              Total: 97 bytes

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-28 18:08:02 +02:00
Arsen Arsenović 2d4a3d9e6c fixdep: avoid underflow when end of entry doesn't coincide with EOF
Bug: https://bugs.gentoo.org/893776
Closes: https://bugs.busybox.net/show_bug.cgi?id=15326
Signed-off-by: Arsen Arsenović <arsen@gentoo.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-27 13:09:44 +01:00
Denys Vlasenko 029740a3e4 unzip: document some options we might support
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-23 12:00:36 +01:00
Denys Vlasenko 75197998c2 unzip: clear SUID/GID bits, implement -K to not clear them
function                                             old     new   delta
unzip_main                                          2656    2715     +59
packed_usage                                       34517   34552     +35
.rodata                                           105250  105251      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 95/0)               Total: 95 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-22 10:50:14 +01:00
Denys Vlasenko 669c40ed8e top: stop using div() from libc, compilers now do it better
function                                             old     new   delta
div                                                   23       -     -23
display_process_list                                1237    1178     -59
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-82)             Total: -82 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-02-13 15:05:19 +01:00
Denys Vlasenko 93ae7464e6 hush: restore SIGHUP handling, this time explain why we do what we do
function                                             old     new   delta
check_and_run_traps                                  229     278     +49

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-30 18:48:36 +01:00
Denys Vlasenko 1fdb33bd07 hush: restore tty pgrp on SIGHUP
Found one case where SIGHUP does need some handling.

ash does not restore tty pgrp when killed by SIGHUP, and
this means process which started ash needs to restore it,
or it would get backgrounded when trying to use tty.

function                                             old     new   delta
check_and_run_traps                                  214     229     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-30 16:49:48 +01:00
Denys Vlasenko 6101b6d3ea hush: remove special handling of SIGHUP
Kernel should do the right thing.
(ash and dash do not have special SIGHUP handling.)

function                                             old     new   delta
check_and_run_traps                                  278     214     -64

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-30 15:57:04 +01:00
Denys Vlasenko 93e0898c66 shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256
function                                             old     new   delta
record_pending_signo                                  32      63     +31
lineedit_read_key                                    231     224      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 31/-7)              Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-26 12:56:33 +01:00
Denys Vlasenko c2739e11de nmeter: increase maximum /proc file size (needed for large machines)
function                                             old     new   delta
get_file                                             185     201     +16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-24 12:47:32 +01:00
Denys Vlasenko 1040f78176 ntpd: correct comment: 2^-20 is ~1 microsecond (confused with 10^-20)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-18 18:04:22 +01:00
Denys Vlasenko 479bd7af0d ntpd: fold d_to_tv() into its only caller
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-18 17:42:17 +01:00
Denys Vlasenko c344ca6c7f ntpd: correct fixed->float conversions of fractions
Need to divide by (1<<32), not by (1<<32)-1.
Fraction of 0xffffffff is not 1 whole second.

function                                             old     new   delta
.rodata                                           105264  105268      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-17 17:01:05 +01:00
Miroslav Lichvar 85acf71d25 ntpd: make NTP client and server Y2036/2038-ready
The 32-bit integer part of the NTP timestamp overflows in year 2036,
which starts the second NTP era.

Modify the timestamp conversion to shift values between 1900-1970 (in
the first era) to the second era to enable the client to measure its
offset correctly until year 2106 (assuming 64-bit time_t).

Also update the conversion from double used when stepping the clock to
work with 64-bit time_t after reaching the maximum 32-bit value in 2038
and the server conversion to work correctly in the next NTP era.

function                                             old     new   delta
lfp_to_d                                              51      64     +13
step_time                                            326     332      +6
.rodata                                           105260  105264      +4
d_to_lfp                                             100      86     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 23/-14)              Total: 9 bytes

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-17 16:48:54 +01:00
Sören Tempel ca96022d6e ed: don't use memcpy with overlapping memory regions
The memcpy invocations in the subCommand function, modified by this
commit, previously used memcpy with overlapping memory regions. This is
undefined behavior. On Alpine Linux, it causes BusyBox ed to crash since
we compile BusyBox with -D_FORTIFY_SOURCE=2 and our fortify-headers
implementation catches this source of undefined behavior [0]. The issue
can only be triggered if the replacement string is the same size or
shorter than the old string.

Looking at the code, it seems to me that a memmove(3) is what was
actually intended here, this commit modifies the code accordingly.

[0]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13504

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-05 16:21:48 +01:00
Denys Vlasenko b1884deb51 Start 1.37.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 15:32:00 +01:00
Denys Vlasenko 70f77e4617 Bump version to 1.36.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 15:15:41 +01:00
Denys Vlasenko 969e008168 hush: code shrink
function                                             old     new   delta
run_list                                            1032    1012     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 14:08:18 +01:00
Denys Vlasenko d488a5218b ash: trivial code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 13:39:14 +01:00
Denys Vlasenko bcb90b9c41 xxd: use bb_simple_perror_msg... where appropriate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 08:30:12 +01:00
Denys Vlasenko 27be0e8cfe shell: fix compile failures in some configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 08:28:16 +01:00
Denys Vlasenko 8ed57db65b Makefile.flags: add resolv to LDLIBS for linux compilers too (not only gnu ones)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:10:04 +01:00
Denys Vlasenko 9b2d766e0e sed: fix double-free in FEATURE_CLEAN_UP=y configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:05:55 +01:00
Denys Vlasenko cadf57b3af mv: fix error in !VERBOSE configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:04:44 +01:00
Denys Vlasenko e7977df2ca libbb/loop: fix compile failure (name collision)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:03:44 +01:00
Denys Vlasenko fb0c000567 testsuite/sha1sum.tests: fix false positive failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:02:17 +01:00
Denys Vlasenko dc068abad5 testsuite/tree.tests: fix false positive failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 17:01:14 +01:00
Denys Vlasenko adb1c7dcfe xxd: fix use of non-initialized data
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-02 16:59:40 +01:00
Denys Vlasenko c4d296aa7c xargs: implement -o, closes 15146
function                                             old     new   delta
.rodata                                           105225  105259     +34
d6_listen_socket                                     150     180     +30
packed_usage                                       34512   34532     +20
d6_read_interface                                    595     581     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 84/-14)             Total: 70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-22 10:38:08 +01:00
Denys Vlasenko 02ca565646 udhcpc6: fix binding to network aliases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 23:57:27 +01:00
Denys Vlasenko 6c2ddf808e udhcp: add a few comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 13:34:52 +01:00
Denys Vlasenko 242d056230 udhcpc6: use a different default config script
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 11:51:16 +01:00
Denys Vlasenko 301ef96892 udhcpc6: align FF02__1_2[]
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-15 11:49:00 +01:00
Natanael Copa 3636d52cbe more: accept and ignore -e
Accept and ignore -e which is specified in POSIX.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/more.html

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-14 16:05:43 +01:00
Denys Vlasenko e977853e70 udhcpc6: add some comments
RFCs for DHCPv6 are written rather badly...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-14 00:36:59 +01:00
Denys Vlasenko 9898db4c94 udhcpc6: remove stray comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 23:21:59 +01:00
Denys Vlasenko 7710250e4a libbb: shrink del_loop()
function                                             old     new   delta
del_loop                                              52      49      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 16:00:00 +01:00
Denys Vlasenko a55bd1c484 loop: restore the correct return vaule of set_loop()
It is only used by mount's error path, though...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 15:52:52 +01:00
Denys Vlasenko 45734a2351 loop: optionally use ioctl(LOOP_CONFIGURE) to set up loopdevs
LOOP_CONFIGURE is added to Linux 5.8

function                                             old     new   delta
NO_LOOP_CONFIGURE (old code):
set_loop                                             784     782      -2
LOOP_CONFIGURE:
set_loop                                             784     653    -131
TRY_LOOP_CONFIGURE:
set_loop                                             784     811     +27

Based on a patch by Xiaoming Ni <nixiaoming@huawei.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 15:21:28 +01:00
Denys Vlasenko 9df54deead testsuite/mount.tests: accomodate umount failure seen on 5.18.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 15:12:31 +01:00
Xiaoming Ni a1856934ba loop: refactor: extract subfunction set_loopdev_params()
Extract subfunction set_loop_info() from set_loop()

function                                             old     new   delta
set_loop                                             760     784     +24

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-13 14:26:20 +01:00
Xiaoming Ni 7dc76c9f21 loop: simplify code of LOOP_SET_FD failure
function                                             old     new   delta
set_loop                                             790     760     -30

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-12 19:03:06 +01:00
Xiaoming Ni ddccf6cd2f loop: refactor: extract subfunction get_next_free_loop()
Extract subfunction get_next_free_loop() from set_loop()

Also fix miss free(try) when stat(try) and mknod fail

function                                             old     new   delta
set_loop                                             807     790     -17

Fixes: 3448914e8cc5 ("mount,losetup: use /dev/loop-control is it exists")
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-12 18:57:09 +01:00
Brandon Maier 90456a6aa3 xxd: fix typo in trivial usage
Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-12-08 17:13:11 +01:00
Peter Kaestle 7ade421b1a unzip -l: add missed big-endian conversions date and time
When calling unzip -l the date and time output was missing big-endian
conversions.

Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-29 14:44:39 +01:00
Denys Vlasenko 99476502f9 Remove "select PLATFORM_LINUX"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-29 14:14:06 +01:00
Samuel Thibault 77216c368f Fix non-Linux builds
Various tools are Linuxish and should thus only attempted to build on
Linux only. Some features are also Linux-only.

Also, libresolv is used on all GNU platforms, notably GNU/Hurd and
GNU/kfreeBSD.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-29 14:10:22 +01:00
Dario Binacchi 75fbff1326 fbset: support setting pixel clock rate
Only in case the FEATURE_FBSET_FANCY configuration is enabled.

function                                             old     new   delta
fbset_main                                           733     766     +33

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-16 13:40:34 +01:00
Dario Binacchi e8dfa0c1be fbset: abort on not handled options
Not all options are actually implemented. In this case, return a message
and an error code to make it clear that the requested command has not
been executed.

function                                             old     new   delta
.rodata                                           105200  105224     +24
fbset_main                                           747     733     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 24/-14)             Total: 10 bytes

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-16 13:39:35 +01:00
Xiaoming Ni cb8d2ea8c9 loop: fix a race when a free loop device is snatched
When /dev/loop-control exists and *device is empty,
the mount may fail if a concurrent mount is running.

function                                             old     new   delta
set_loop                                             809     807      -2

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-11-15 14:54:05 +01:00
Louis Sautier 707a7ef4c7 pkill: add -e to display the name and PID of the process being killed
This mimics the behaviour of pkill -e / --echo from procps.

function                                             old     new   delta
.rodata                                           105179  105200     +21
packed_usage                                       34523   34516      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 21/-7)              Total: 14 bytes

Signed-off-by: Louis Sautier <sautier.louis@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-10-14 14:33:34 +02:00
Denys Vlasenko c8c1fcdba1 tls: move definitions around, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-09-08 16:56:54 +02:00
Denys Vlasenko 9bab580cd4 tls: include signature_algorithms extension in client hello message
function                                             old     new   delta
tls_xread_record                                     629     645     +16
.rodata                                           105167  105179     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 28/0)               Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-09-08 16:31:44 +02:00
Ludwig Nussel 526625bc83 libbb: mark stack in assembly files read-only
Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-30 17:21:53 +02:00
Denys Vlasenko dd79e1d4d3 fix [ --help ] and [[ --help ]]
function                                             old     new   delta
show_usage_if_dash_dash_help                          72      79      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-30 17:12:34 +02:00
Denys Vlasenko fe73c8d557 *: style fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-30 16:41:17 +02:00
Shawn Landden 58598eb709 ash: optional sleep builtin
function                                             old     new   delta
sleepcmd                                               -      10     +10
builtintab                                           352     360      +8
.rodata                                           105264  105271      +7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 25/0)               Total: 25 bytes

Signed-off-by: Shawn Landden <shawnlandden@tutanota.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-27 19:56:21 +02:00
Aaro Koskinen d432049f28 devmem: add 128-bit width
Add 128-bit width if the compiler provides the needed type.

function                                             old     new   delta
devmem_main                                          405     464     +59
.rodata                                           109025  109043     +18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 77/0)               Total: 77 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-26 17:09:47 +02:00
Denys Vlasenko 1a1220a5b0 tree: unicode tweak (use normal space char, 0x20)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-26 14:54:45 +02:00
Denys Vlasenko b30d345cfd tree: make it unicode-aware
function                                             old     new   delta
tree_print                                           396     420     +24
.rodata                                           105251  105266     +15
tree_main                                             86      91      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 44/0)               Total: 44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-26 14:41:42 +02:00
Denys Vlasenko 5eceafb1f8 xxd -r: handle offsets
function                                             old     new   delta
xxd_main                                            1076    1439    +363
.rodata                                           105239  105251     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 375/0)             Total: 375 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 17:28:43 +02:00
Denys Vlasenko 0011a6bc20 xxd: add two more testcases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 15:57:57 +02:00
Denys Vlasenko f318adaaab xxd -r: without -p, stop at more than one whitespace, closes 14786
function                                             old     new   delta
xxd_main                                             888    1076    +188

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 15:40:47 +02:00
Ron Yorston 5a9d2b6e02 libbb: make '--help' handling more consistent
Running an applet with '--help' as its only argument is treated
as a special case.  If additional arguments follow '--help' the
behaviour is inconsistent:

- applets which call single_argv() print help and do nothing else;

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

- expr says "expr: syntax error" and doesn't print help;

- printenv silently ignores '--help', prints any other variables
  and doesn't print help;

- realpath says "--help: No such file or directory", prints the path
  of any other files and doesn't print help.

If the first argument is '--help' ignore any other arguments and print
help.  This is more consistent and most likely what the user wanted.

See also commit 6bdfbc4cb (libbb: fix '--help' handling in
FEATURE_SH_NOFORK=y).

function                                             old     new   delta
show_usage_if_dash_dash_help                          75      69      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-6)               Total: -6 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-22 14:05:01 +02:00
Denys Vlasenko 41d5f800a1 bc: hopefully fix bug 14956 (use-after-free)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-18 16:23:55 +02:00
Sören Tempel 7c2a3bdde0 ash: fix use-after-free in bash pattern substitution
function                                             old     new   delta
subevalvar                                          1566    1564      -2

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 18:27:41 +02:00
Denys Vlasenko 84b89b4c22 udhcpc6: downgrade "opening listen socket" log level to 2
This matches udhcpc for IPv4.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 18:04:51 +02:00
Denys Vlasenko 75aaa8b311 udhcpc6: fix sending of renew messages
function                                             old     new   delta
d6_listen_socket                                       -     150    +150

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 15:33:51 +02:00
Grob Grobmann 3147552a23 vi: add 'ZQ' quitting command
Busybox vi provides the 'ZZ' command to save and close
the similar 'ZQ' command just exits without saving.

function                                             old     new   delta
do_cmd                                              4222    4244     +22

Signed-off-by: Grob Grobmann <grobgrobmann@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 15:05:12 +02:00
Henrique Rodrigues 9eddf164bf ping: fix typo in --help text
Signed-off-by: Henrique Rodrigues <henrique.rodrigues@ist.utl.pt>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 14:34:38 +02:00
Denys Vlasenko daa66ed62c ash: fix use-after-free in pattern substituon code
Patch by soeren@soeren-tempel.net

The idx variable points to a value in the stack string (as managed
by STPUTC). STPUTC may resize this stack string via realloc(3). If
this happens, the idx pointer needs to be updated. Otherwise,
dereferencing idx may result in a use-after free.

function                                             old     new   delta
subevalvar                                          1562    1566      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 12:41:18 +02:00
Denys Vlasenko 1c54552842 ash: fix ifs cleanup on error paths
Patch by Alex Gorinson <algore3698@gmail.com>

function                                             old     new   delta
evalvar                                              477     495     +18
varvalue                                             603     618     +15
subevalvar                                          1557    1572     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 48/0)               Total: 48 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02 11:18:11 +02:00
Denys Vlasenko 5479c435fd sort: fix sort -s -u, closes 14871
function                                             old     new   delta
sort_main                                            851     856      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-29 16:40:00 +02:00
Denys Vlasenko 00f2a35b83 sort: fix -k2M (wasn't skipping leading whitespace)
function                                             old     new   delta
compare_keys                                         848     862     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-29 16:05:50 +02:00
Denys Vlasenko 9b6eb2a8ef udhcpc6: add missed big-endian conversions
function                                             old     new   delta
option_to_env                                        686     694      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-13 16:15:04 +02:00
Denys Vlasenko 7b969bb2ad tls: P256: remove NOP macro sp_256_norm_8()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-13 16:11:17 +02:00
Natanael Copa e63d7cdfda awk: fix use after free (CVE-2022-30065)
fixes https://bugs.busybox.net/show_bug.cgi?id=14781

function                                             old     new   delta
evaluate                                            3343    3357     +14

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-11 17:18:07 +02:00
Denys Vlasenko 3ad3aa6441 shaNNNsum: accept one-space "HASH FILENAME" format for -c, closes 14866
function                                             old     new   delta
md5_sha1_sum_main                                    496     501      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-11 14:36:39 +02:00
Ron Yorston 298ac9507b lineedit: get PWD from ash
The line editing code and ash disagree when the current directory
is changed to a symbolic link:

   ~ $ mkdir real
   ~ $ ln -s real link
   ~ $ cd link
   ~/real $ pwd
   /home/rmyf36/link

Note the prompt says we're in ~/real.  Bash does:

   [rmy@random ~]$ cd link
   [rmy@random link]$ pwd
   /home/rmyf36/link

Ash uses the name supplied by the user while the line editing code
calls getcwd(3).  The discrepancy can be avoided by fetching the
value of PWD from ash.

Hush calls getcwd(3) when the directory is changed
so there's no disagreement with the line editing code.

There is no standard how shells should handle cd'ing into
symlinks.

function                                             old     new   delta
parse_and_put_prompt                                 838     869     +31

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-03 21:41:38 +02:00
Roger Knecht 20a4f70eca tree: new applet
Adds the tree program to list directories and files in a tree structure.

function                                             old     new   delta
tree_print                                             -     343    +343
scandir64                                              -     330    +330
scandir                                                -     330    +330
tree_main                                              -      86     +86
.rodata                                           105150  105228     +78
packed_usage                                       34511   34557     +46
alphasort64                                            -      31     +31
alphasort                                              -      31     +31
strcoll                                                -       5      +5
applet_names                                        2801    2806      +5
applet_main                                         1616    1620      +4
applet_suid                                          101     102      +1
applet_install_loc                                   202     203      +1
------------------------------------------------------------------------------
(add/remove: 11/0 grow/shrink: 6/0 up/down: 1291/0)          Total: 1291 bytes

Signed-off-by: Roger Knecht <rknecht@pm.me>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-30 17:18:12 +02:00
Ron Yorston 2617a5e4c6 vi: handle autoindent in 'cc' command
When the 'cc' command is invoked with autoindent enabled it
should use the indent of the first line being changed.

The size of the indent has to be established before char_insert()
is called as the lines being changed are deleted.  Introduce a
new global variable, newindent, to handle this.  The indentcol
global is now effectively a static variable in char_insert().

function                                             old     new   delta
do_cmd                                              4247    4308     +61
vi_main                                              416     422      +6
char_insert                                          891     875     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 67/-16)             Total: 51 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26 19:38:31 +02:00
Ron Yorston af3b585815 vi: fix regression in autoindent handling
Suppose autoindent is enabled and we have a line with an initial
tab where we want to split the words onto separate lines:

	split the words

One way to do this is with the sequence 'f r<CR>;r<CR>', but in
BusyBox vi the result is:

	split

	he
words

This is a regression introduced by commit 9659a8db1 (vi: remove
autoindent from otherwise empty lines).  The amount of indentation
is being recorded when the 'r' command inserts a newline but
isn't subsequently reset.  A fix is to only record the indent
when in insert or replace mode.  Proper handling of the 'o' and
'O' commands then requires them to switch to insert mode before
calling char_insert() to insert a newline.

function                                             old     new   delta
char_insert                                          884     891      +7
do_cmd                                              4243    4247      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/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>
2022-06-26 19:38:28 +02:00
Ron Yorston 7d1c7d8337 ash,hush: use HOME for tab completion and prompts
ash and hush correctly use the value of HOME for tilde expansion.
However the line editing code in libbb obtains the user's home
directory by calling getpwuid().  Thus tildes in tab completion
and prompts may be interpreted differently than in tilde expansion.

When the line editing code is invoked from a shell make it use the
shell's interpretation of tilde.  This is similar to how GNU readline
and bash collaborate.

function                                             old     new   delta
get_homedir_or_NULL                                   29      72     +43
optschanged                                          119     126      +7
hush_main                                           1204    1211      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 57/0)               Total: 57 bytes

v2: Always check for HOME before trying the password database:  this
    is what GNU readline does.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26 18:05:50 +02:00
Ron Yorston 95fec31be6 libbb: restore special handling of nomsg errors
The functions bb_perror_nomsg() and bb_perror_nomsg_and_die() are
used to print error messages where no specific information is
available.  For example:

   $ busybox mktemp -p /
   mktemp: (null): Permission denied

mktemp(3) doesn't tell us the name of the file it tried to create.

However, printing '(null)' is a regression introduced by commit
6937487be (libbb: reduce the overhead of single parameter bb_error_msg()
calls).  Restore the previous behaviour by reverting the changes to
the two functions mentioned:

   $ busybox mktemp -p /
   mktemp: Permission denied

function                                             old     new   delta
bb_perror_nomsg_and_die                                7      14      +7
bb_perror_nomsg                                        7      14      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 14/0)               Total: 14 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-06-26 17:17:02 +02:00
Denys Vlasenko 8d67007a4d top: improve large PID display in memory ('s') mode
function                                             old     new   delta
display_topmem_process_list                          530     564     +34

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-12 11:44:47 +02:00
Denys Vlasenko b9c2108b26 examples/var_service/dhcp_if: make helper scripts more talkative
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-12 11:07:12 +02:00
Denys Vlasenko 1099a27696 top: code shrink
function                                             old     new   delta
display_process_list                                1186    1168     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-10 14:04:34 +02:00
Denys Vlasenko 69f82e305b top: code shrink
function                                             old     new   delta
display_process_list                                1191    1186      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-10 13:51:09 +02:00
Denys Vlasenko 294881d2e9 top: fix display of large PID/PPID
function                                             old     new   delta
display_process_list                                1077    1191    +114
.rodata                                           104803  104807      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 118/0)             Total: 118 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-10 12:56:28 +02:00
Denys Vlasenko 67fd6be0bb seedrng: do not hash in a constant string, it's not adding entropy
function                                             old     new   delta
seedrng_main                                         906     880     -26
.rodata                                           104899  104873     -26
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-52)             Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-03 12:48:50 +02:00
Denys Vlasenko 3bfbcb5807 seedrng: restore error check on fsync
Or else security people will never stop nagging us.

function                                             old     new   delta
seedrng_main                                         884     906     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 15:03:32 +02:00
Denys Vlasenko 5ba56e8b95 seedrng: it's not a part of util-linux, move to miscutils
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 14:53:14 +02:00
Denys Vlasenko 1a290f889c init: do not set HOME
function                                             old     new   delta
.rodata                                           104906  104899      -7
init_main                                            786     776     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 14:47:53 +02:00
David Leonard 4642cf5b38 tsort: new applet
function                                             old     new   delta
tsort_main                                             -     578    +578
.rodata                                           104884  104906     +22
applet_names                                        2759    2765      +6
applet_main                                         1596    1600      +4
packed_usage                                       34290   34288      -2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/1 up/down: 610/-2)            Total: 608 bytes

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 14:25:36 +02:00
Paul Fox 52a7bf6fa6 crond: implement support for setting PATH in crontab files
It's very inconvenient for a cron user not to be able to set a
"personal" PATH for their cron jobs, as is possible with other crons

function                                             old     new   delta
load_crontab                                         868     942     +74
.rodata                                           104878  104884      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 80/0)               Total: 80 bytes

Signed-off-by: Paul Fox <pgf@foxharp.boston.ma.us>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-02 12:28:48 +02:00
Denys Vlasenko 9b6f44e040 style fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 17:06:00 +02:00
Bernhard Reutner-Fischer a157c4c978 seedrng: manually inline seed_rng
We can now remove a separate buffer

function                                             old     new   delta
seedrng_main                                         930     884     -46

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 17:02:20 +02:00
Denys Vlasenko 54867fec12 seedrng: shorten --help, assorted small cleanups
function                                             old     new   delta
packed_usage                                       34295   34290      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 16:51:06 +02:00
Denys Vlasenko b5624be6df seedrng: reduce MAX_SEED_LEN from 512 to 256
As proposed by Jason.
getrandom() is more likely to block on reads larger than this.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 16:37:39 +02:00
Denys Vlasenko 7471658038 seedrng: do not hash lengths, they are very predictable
function                                             old     new   delta
seedrng_main                                         982     930     -52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 02:06:20 +02:00
Denys Vlasenko fb4546c7af seedrng: code shrink
function                                             old     new   delta
seedrng_main                                         994     982     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 01:58:57 +02:00
Denys Vlasenko d5bd2e57a7 seedrng: explain why we need locking and fsync'ing
Also, do not test for locking errors: on Linux, they do not happen.

function                                             old     new   delta
.rodata                                           104900  104878     -22
seedrng_main                                        1022     994     -28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-05-01 01:50:44 +02:00
Denys Vlasenko 0bca489b24 seedrng: remove redundant assignment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 23:53:28 +02:00
Denys Vlasenko 4648754119 seedrng: re-add fsync after unlink, and explain its purpose
function                                             old     new   delta
seedrng_main                                        1003    1022     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 23:17:58 +02:00
Denys Vlasenko 267178c628 seedrng: include fiel/dir names in error messages
function                                             old     new   delta
.rodata                                           104898  104900      +2
seedrng_main                                        1011    1003      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-8)               Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:50:45 +02:00
Denys Vlasenko d49da38aa3 seedrng: use more xfuncs where appropriate
function                                             old     new   delta
.rodata                                           104929  104898     -31
seedrng_main                                        1050    1011     -39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:45:53 +02:00
Denys Vlasenko 2cbfd01c15 seedrng: code shrink
Struct initializers do this double init:
># util-linux/seedrng.c:88:              struct pollfd random_fd = {
        movl    $0, 132(%esp)   #, random_fd
        movl    $0, 136(%esp)   #, random_fd
...
># util-linux/seedrng.c:88:              struct pollfd random_fd = {
        movl    %eax, 140(%esp) # _110, random_fd.fd
        movw    $1, 144(%esp)   #, random_fd.events

and close(random_fd.fd) needs to pull the item from the stack:
        pushl   132(%esp)       # random_fd.fd
        call    close   #

function                                             old     new   delta
seedrng_main                                        1076    1050     -26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:38:44 +02:00
Denys Vlasenko 52f3cf7e5f seedrng: simplify read_new_seed() to not have error return
gcc in fact detects this and does this transformation
when generating code - no object code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:33:28 +02:00
Denys Vlasenko 282b61a649 seedrng: prepare read_new_seed() to not need a "success" retval
We do not expect /dev/[u]random to be not openable/readable.
If they are, just bail out (something is obviously very wrong).

function                                             old     new   delta
seedrng_main                                        1077    1076      -1
.rodata                                           104939  104929     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:25:55 +02:00
Denys Vlasenko 0fa16fc7a2 seedrng: do not try to continue on unexpected errors (just exit)
function                                             old     new   delta
.rodata                                           104946  104938      -8
seedrng_main                                        1225    1077    -148
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-156)           Total: -156 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 15:17:32 +02:00
Denys Vlasenko 002d6ee46d ifplugd: split -a into -a and -A, latter disables upping in iface creation
-a meant both "don't up iface before each link detection" and "don't up iface
when it newly appears". But they are not the same.

I have a dock station where eth1 appears when I attach the notebook to it
(looks like it's hanging off a USB bus). IOW: appearance of this interface
is functionally equivalent to attaching ethernet cable.
ifplugd meant to be able to *automatically* handle this case.
Currently, with -a, it couldn't: newly appearing iface stayed down,
user had to manually up it.

function                                             old     new   delta
packed_usage                                       34253   34296     +43
.rodata                                           104876  104877      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 44/0)               Total: 44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-30 14:33:14 +02:00
Denys Vlasenko 8456c21c09 seedrng: chdir to the SEED_DIRECTORY - avoid concat_path_file's
function                                             old     new   delta
seedrng_main                                        1273    1225     -48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:53:12 +02:00
Denys Vlasenko c82a0cd2b0 seedrng: shorten strings
function                                             old     new   delta
.rodata                                           104894  104876     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:33:15 +02:00
Denys Vlasenko 401356511c seedrng: remove unnecessary zero-filling of local variables
function                                             old     new   delta
seedrng_main                                        1292    1273     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:20:43 +02:00
Denys Vlasenko 6da9947358 seedrng: remove unnecessary zero-filling of local variables
function                                             old     new   delta
seedrng_main                                        1323    1292     -31

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 17:09:38 +02:00
Denys Vlasenko 137b205722 seedrng: shrink --help text
function                                             old     new   delta
packed_usage                                       34280   34253     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 16:54:18 +02:00
Denys Vlasenko 0cdd6f5792 libbb: fix fallout from nth_string() robustification, closes 14726
function                                             old     new   delta
parse_common                                         187     228     +41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-04-27 15:33:55 +02:00
Bernhard Reutner-Fischer 7fbfb2050f kbuild: Prefer -Oz over -Os
-Oz Optimize aggressively for size rather than speed.

with gcc-12 so far (i think only https://gcc.gnu.org/PR32803 and 103773 )
"shorter load imm on x86_64":
(add/remove: 0/0 grow/shrink: 4/1670 up/down: 6/-13196)    Total: -13190 bytes
   text	   data	    bss	    dec	    hex	filename
 975753	   4227	   1816	 981796	  efb24	busybox_old
 962442	   4227	   1816	 968485	  ec725	busybox_unstripped

with clang-15:
(add/remove: 394/34 grow/shrink: 161/1856 up/down: 18644/-98946)Total: -80302 bytes
   text	   data	    bss	    dec	    hex	filename
1120994	  16066	   1696	1138756	 116044	busybox_old
1040689	  16026	   1696	1058411	 10266b	busybox_unstripped

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-24 19:18:57 +02:00
Jason A. Donenfeld 05c366a560 seedrng: prune header includes
Remove redundant includes.
We have platform specific handling in libbb.h and platform.h so we can
handle quirks in a central place.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-24 10:03:59 +02:00
Jason A. Donenfeld f9ea8ba5ed seedrng: code-golf even smaller
Since we're passing 0 as the timeout, we don't need safe_poll. Remove
cleanup at end of program, since OS does that, which lets us simplify
control flow. Factor repeated function calls into ternary loop.

function                                             old     new   delta
seedrng_main                                        1061    1459    +398
seed_from_file_if_exists                             468       -    -468
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 398/-468)          Total: -70 bytes
   text    data     bss     dec     hex filename
1052781   16515    1816 1071112  105808 busybox_old
1052711   16515    1816 1071042  1057c2 busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-24 10:01:07 +02:00
Bernhard Reutner-Fischer 831c754c91 kbuild: fix building sha256
Pass down the correct EXTRA_CFLAGS to the compiler driver when building
assembler source.
Otherwise building busybox for a multilib other than the default failed
to link since hash_md5_sha256_x86-64_shaNI.o and
hash_md5_sha_x86-64_shaNI.o were built for the default arch which might
not what we requested in the EXTRA_CFLAGS.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-21 13:37:10 +02:00
Ron Yorston c93eb1a95b vi: fix backspace over tab in commands
Colon and search commands are entered on the status line.  Since
the cursor position wasn't being tracked backspacing over a tab
resulted in a mismatch between the actual and apparent content
of the command.

function                                             old     new   delta
get_input_line                                       178     180      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 2/0)                 Total: 2 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 16:06:04 +02:00
Jason A. Donenfeld 57fea029cc seedrng: compress format strings with %s arguments
- Avoid an xstrdup call with seed_dir.
- Compress format strings with %s arguments.
- Open /dev/urandom for add entropy ioctl rather than /dev/random, so that
  /dev/random is only used for the already-sightly-flawed poll() check for
  creditability.

function                                             old     new   delta
seedrng_main                                         948     958     +10
seed_from_file_if_exists                             410     417      +7
.rodata                                           108338  108206    -132
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 17/-132)          Total: -115 bytes
   text	   data	    bss	    dec	    hex	filename
 975829	   4227	   1816	 981872	  efb70	busybox_old
 975714	   4227	   1816	 981757	  efafd	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:04 +02:00
Jason A. Donenfeld 3cb40f89de seedrng: avoid needless runtime strlen() call
- Avoid needless runtime strlen() call, bloating binary.
- Replace failed seed string with series of nulls.

function                                             old     new   delta
.rodata                                           108350  108338     -12
static.seedrng_prefix                                 26       -     -26
seedrng_main                                        1000     948     -52
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-90)             Total: -90 bytes
   text	   data	    bss	    dec	    hex	filename
 975919	   4227	   1816	 981962	  efbca	busybox_old
 975829	   4227	   1816	 981872	  efb70	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld ce9a345632 seedrng: use predefined strings where possible
- Use predefined strings where possible.
- Open /dev/random with O_RDONLY for ioctl().

function                                             old     new   delta
seed_from_file_if_exists                             413     410      -3
.rodata                                           108407  108350     -57
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-60)             Total: -60 bytes
   text	   data	    bss	    dec	    hex	filename
 975979	   4227	   1816	 982022	  efc06	busybox_old
 975919	   4227	   1816	 981962	  efbca	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld 398bb3861a seedrng: further reduce size
- Remove all games with errno to further reduce code size.
- Combine error messages that don't benefit from being separated.
- Lock directory fd instead of separate file.

function                                             old     new   delta
static.longopts                                       38      26     -12
seed_from_file_if_exists                             426     413     -13
packed_usage                                       34519   34480     -39
.rodata                                           108484  108407     -77
seedrng_main                                        1088    1000     -88
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-229)           Total: -229 bytes
   text	   data	    bss	    dec	    hex	filename
 976208	   4227	   1816	 982251	  efceb	busybox_old
 975979	   4227	   1816	 982022	  efc06	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld 3c60711f83 seedrng: remove some global variables
- Remove global variables and pass dfd by value, opened once instead of
  twice, which shaves off some more bytes.

function                                             old     new   delta
seedrng_main                                        1086    1088      +2
seed_dir                                               8       -      -8
non_creditable_seed                                    8       -      -8
lock_file                                              8       -      -8
creditable_seed                                        8       -      -8
seed_from_file_if_exists                             456     426     -30
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 1/1 up/down: 2/-62)             Total: -60 bytes
   text	   data	    bss	    dec	    hex	filename
 976236	   4227	   1848	 982311	  efd27	busybox_old
 976208	   4227	   1816	 982251	  efceb	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:43:00 +02:00
Jason A. Donenfeld 31ec481baf seedrng: hoist bb_strtoul out of min/max
- Hoist bb_strtoul out of min/max to prevent quadruple evaluation.
- Don't use separate variables for boottime/realtime.
- Make use of ENABLE_FEATURE_CLEAN_UP where appropriate.
- Order hash initialization after lock taking per Bernhard's taste.
- Add comment description of theory of operation.

function                                             old     new   delta
seed_from_file_if_exists                             533     456     -77
seedrng_main                                        1218    1086    -132
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-209)           Total: -209 bytes
   text	   data	    bss	    dec	    hex	filename
 976445	   4227	   1848	 982520	  efdf8	busybox_old
 976236	   4227	   1848	 982311	  efd27	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:42:53 +02:00
Jason A. Donenfeld 4538578996 seedrng: use libbb functions
- Make extensive use of libbb.h functions, which simplify a lot of code
  and reduce binary size considerably.
- Use the already existing PID_FILE_PATH variable.

function                                             old     new   delta
seed_from_file_if_exists                             697     533    -164
.rodata                                           108665  108484    -181
seedrng_main                                        1463    1218    -245
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-590)           Total: -590 bytes
   text	   data	    bss	    dec	    hex	filename
 977035	   4227	   1848	 983110	  f0046	busybox_old
 976445	   4227	   1848	 982520	  efdf8	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:22:55 +02:00
Jason A. Donenfeld 4b407bacd4 seedrng: import SeedRNG utility for kernel RNG seed files
The RNG can't actually be seeded from a shell script, due to the
reliance on ioctls and the fact that entropy written into the
unprivileged /dev/urandom device is not immediately mixed in, making
subsequent seed reads dangerous. For this reason, the seedrng project
provides a basic "C script" meant to be copy and pasted into projects
like Busybox and tweaked as needed: <https://git.zx2c4.com/seedrng/about/>.

The SeedRNG construction has been part of systemd's seeder since
January, and recently was added to Android, OpenRC, and Void's Runit,
with more integrations on their way depending on context. Virtually
every single Busybox-based distro I have seen seeds things in wrong,
incomplete, or otherwise dangerous way. For example, fixing this issue
in Buildroot requires first for Busybox to have this fix.

This commit imports it into Busybox and wires up the basic config. The
utility itself is tiny, and unlike the example code from the SeedRNG
project, we can re-use libbb's existing hash functions, rather than
having to ship a standalone BLAKE2s, which makes this even smaller.

function                                             old     new   delta
seedrng_main                                           -    1463   +1463
.rodata                                           107858  108665    +807
seed_from_file_if_exists                               -     697    +697
packed_usage                                       34414   34519    +105
static.longopts                                        -      38     +38
static.seedrng_prefix                                  -      26     +26
seed_dir                                               -       8      +8
non_creditable_seed                                    -       8      +8
lock_file                                              -       8      +8
creditable_seed                                        -       8      +8
applet_names                                        2747    2755      +8
applet_main                                         3192    3200      +8
------------------------------------------------------------------------------
(add/remove: 9/0 grow/shrink: 4/0 up/down: 3184/0)           Total: 3184 bytes
   text	   data	    bss	    dec	    hex	filename
 973776	   4219	   1816	 979811	  ef363	busybox_old
 977035	   4227	   1848	 983110	  f0046	busybox_unstripped

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-04-20 15:20:29 +02:00
Ron Yorston fc7868602e vi: improved handling of backspace in replace mode
In replace mode ('R' command) the backspace character should get
special treatment:

- backspace only goes back to the start of the replacement;
- backspacing over replaced characters restores the original text.

Prior to this commit BusyBox vi deleted the characters both before
and after the cursor in replace mode.

function                                             old     new   delta
undo_pop                                               -     235    +235
char_insert                                          858     884     +26
indicate_error                                        81      84      +3
find_range                                           654     657      +3
static.text_yank                                      77      79      +2
do_cmd                                              4486    4243    -243
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 269/-243)           Total: 26 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-04 22:57:05 +01:00
Denys Vlasenko 55f969a006 taskset: fix printf format mismatch in !FEATURE_TASKSET_FANCY config. closes 14616
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 10:49:17 +01:00
Denys Vlasenko 5fe20cf321 ash: do not truncate failed tilde expansion on unknown user names
Do not skip over "*p = c;" statement.

Testcase: echo ~~nouser/qwe

function                                             old     new   delta
argstr                                              1396    1406     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 10:10:22 +01:00
Denys Vlasenko 7750b5a25a ash: fix unsafe use of mempcpy
function                                             old     new   delta
subevalvar                                          1549    1557      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 09:56:54 +01:00
Sören Tempel fa52ac9781 ash: don't read past end of var in subvareval for bash substitutions
Without this patch, BusyBox handles bash pattern substitutions without
a terminating '/' character incorrectly.

Consider the following shell script:

	_bootstrapver=5.0.211-r0
	_referencesdir="/usr/${_bootstrapver/-*}/Sources"
	echo $_referencesdir

This should output `/usr/5.0.211/Sources`. However, without this patch
it instead outputs `/usr/5.0.211Sources`. This is due to the fact that
BusyBox expects the bash pattern substitutions to always be terminated
with a '/' (at least in this part of subvareval) and thus reads passed
the substitution itself and consumes the '/' character which is part of
the literal string. If there is no '/' after the substitution then
BusyBox might perform an out-of-bounds read under certain circumstances.

When replacing the bash pattern substitution with `${_bootstrapver/-*/}`,
or with this patch applied, ash outputs the correct value.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 08:47:43 +01:00
Denys Vlasenko 1891fdda59 libbb/sha1: update config help text with new performance numbers
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-18 17:09:51 +01:00
Denys Vlasenko c2e7780e52 libbb/sha256: explicitly use sha256rnds2's %xmm0 (MSG) argument
Else, the code seemingly does not use MSG.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-12 00:52:12 +01:00
Denys Vlasenko 1f272c06d0 whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-11 23:03:27 +01:00
Denys Vlasenko dda77e8376 libbb/sha1: revert last commit: pshufb is a SSSE3 insn, can't use it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-11 14:53:26 +01:00
Denys Vlasenko 8154146be4 libbb/sha1: shrink unrolled x86-64 code
function                                             old     new   delta
sha1_process_block64                                3481    3384     -97

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-11 06:08:27 +01:00
Denys Vlasenko 6f56fa1713 libbb/sha: improve comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-10 15:38:10 +01:00
Denys Vlasenko 6a6c1c0ea9 whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 11:29:23 +01:00
Denys Vlasenko caa9c4f707 libbb/sha256: code shrink in x86 assembly
function                                             old     new   delta
sha256_process_block64_shaNI 32-bit                  676     673      -3
sha256_process_block64_shaNI 64-bit                  680     677      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 01:50:22 +01:00
Denys Vlasenko 11bcea7ac0 libbb/sha256: code shrink in 64-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         701     680     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 01:42:49 +01:00
Denys Vlasenko 461a994b09 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         697     676     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 01:30:23 +01:00
Denys Vlasenko c0ff0d4528 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         713     697     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-09 00:33:39 +01:00
Denys Vlasenko eb8d5f3b8f libbb/sha1: shrink x86 hardware accelerated hashing (32-bit)
function                                             old     new   delta
sha1_process_block64_shaNI                           511     507      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 15:34:02 +01:00
Denys Vlasenko eb52e7fa52 libbb/sha1: shrink x86 hardware accelerated hashing (32-bit)
function                                             old     new   delta
sha1_process_block64_shaNI                           517     511      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 15:23:26 +01:00
Denys Vlasenko 71a1cccaad libbb/sha1: shrink x86 hardware accelerated hashing
function                                             old     new   delta
sha1_process_block64_shaNI 32-bit                    524     517      -7
sha1_process_block64_shaNI 64-bit                    510     508      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 08:22:17 +01:00
Denys Vlasenko 4923f74e58 libbb/sha1: shrink unrolled x86-64 code
function                                             old     new   delta
sha1_process_block64                                3482    3481      -1
.rodata                                           108460  108412     -48
------------------------------------------------------------------------------
(add/remove: 1/4 grow/shrink: 0/2 up/down: 0/-49)             Total: -49 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-08 03:29:16 +01:00
Denys Vlasenko c193cbd6df libbb/sha1: shrink and speed up unrolled x86-64 code
function                                             old     new   delta
sha1_process_block64                                3514    3482     -32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-07 02:34:04 +01:00
Denys Vlasenko 987be932ed *: slap on a few ALIGN_PTR where appropriate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 20:07:12 +01:00
Denys Vlasenko ca466f385a *: slap on a few ALIGN* where appropriate
The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map"

function                                             old     new   delta
.rodata                                           108586  108460    -126
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-126)           Total: -126 bytes
   text	   data	    bss	    dec	    hex	filename
 970412	   4219	   1848	 976479	  ee65f	busybox_old
 970286	   4219	   1848	 976353	  ee5e1	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 19:53:10 +01:00
Denys Vlasenko 4f40735c87 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         722     713      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 00:56:13 +01:00
Denys Vlasenko 31c1c31077 libbb/sha256: code shrink in 64-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         706     701      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-06 00:33:42 +01:00
Denys Vlasenko a1429fbb8c libbb/sha256: code shrink in 64-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         730     706     -24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-03 15:17:42 +01:00
Denys Vlasenko de6cb4bed8 libbb/sha256: code shrink in 32-bit x86
function                                             old     new   delta
sha256_process_block64_shaNI                         747     722     -25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-03 15:11:23 +01:00
Denys Vlasenko 6472ac9428 libbb/sha256: optional x86 hardware accelerated hashing
64 bit:
function                                             old     new   delta
sha256_process_block64_shaNI                           -     730    +730
.rodata                                           108314  108586    +272
sha256_begin                                          31      83     +52
------------------------------------------------------------------------------
(add/remove: 5/1 grow/shrink: 2/0 up/down: 1055/-1)          Total: 1054 bytes

32 bit:
function                                             old     new   delta
sha256_process_block64_shaNI                           -     747    +747
.rodata                                           104318  104590    +272
sha256_begin                                          29      84     +55
------------------------------------------------------------------------------
(add/remove: 5/1 grow/shrink: 2/0 up/down: 1075/-1)          Total: 1074 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-02-03 14:58:02 +01:00
Denys Vlasenko 205042c07a libbb/sha1: in unrolled x86-64 code, pass initial W[] in registers, not on stack
This can be faster on some CPUs.
On Skylake, evidently load latency from L1 (or store-to-load
forwarding in LSU) is fast enough to completely hide
memory reference latencies here.

function                                             old     new   delta
sha1_process_block64                                3495    3514     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-25 17:21:45 +01:00
Denys Vlasenko 99e22d230d cut: build fix for FEATURE_CUT_REGEX
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-24 07:07:17 +01:00
Khem Raj 117a8c9b7a apply const trick to ptr_to_globals
This was missing in the previous attempt to fix it via [1]

This helps fix segfaults when compiling with clang ( seen on riscv64 )

[  452.428349] less[270]: unhandled signal 11 code 0x1 at 0x000000000000000c in busybox.nosuid[2ab7491000+ba000]
[  452.430246] CPU: 3 PID: 270 Comm: less Not tainted 5.15.13-yocto-standard #1
[  452.431323] Hardware name: riscv-virtio,qemu (DT)
[  452.431925] epc : 0000002ab74a19ee ra : 0000002ab74a19dc sp : 0000003fec6ec980
[  452.432725]  gp : 0000002ab754dcb0 tp : 0000003f88783800 t0 : 0000003f8878d4a0
[  452.433744]  t1 : 0000002ab749b00c t2 : 0000000000000000 s0 : 0000003fec6ecc38
[  452.434732]  s1 : 000000000000004c a0 : 00000000ffffffff a1 : 0000002ab754dde0
[  452.435861]  a2 : 0000000000000000 a3 : 0000000000000100 a4 : 0000002ab754f3a0
[  452.436787]  a5 : 0000002ab754f3a0 a6 : 0000000000000000 a7 : 0000002ab754f2a0
[  452.437974]  s2 : 0000000000000002 s3 : 0000002ab754b6c8 s4 : 0000002ab749b60e
[  452.438781]  s5 : 0000000000000000 s6 : 0000002ab754b6c8 s7 : 0000003f88943060
[  452.439723]  s8 : 0000003f88944050 s9 : 0000002ad8502e88 s10: 0000002ad8502de8
[  452.440538]  s11: 0000000000000014 t3 : 0000003f887fceb6 t4 : 0000003f8893af0c
[  452.441438]  t5 : 0000000000000000 t6 : 0000003f88923000

[1] https://git.busybox.net/busybox/commit/?id=1f925038a

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 23:13:44 +01:00
Timo Teräs 78fdf4d22d mkfs.vfat: fix volume label to be padded with space
The specification requires volume label to be space padded.

Latest fsck.vfat will remove the zero padded volume label
as invalid. See also:
https://github.com/dosfstools/dosfstools/issues/172

Make the default label also "NO NAME" which has the special meaning
that label is not set.

function                                             old     new   delta
mkfs_vfat_main                                      1470    1502     +32
static.NO_NAME_11                                      -      12     +12
.rodata                                           104309  104318      +9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 53/0)               Total: 53 bytes

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 23:07:07 +01:00
Walter Lozano 6dd6a6c42d Add support for long options to cmp
In order to improve compatibility with GNU cmp add support for long
options to busybox cmp.

function                                             old     new   delta
static.cmp_longopts                                    -      36     +36
cmp_main                                             589     594      +5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 41/0)               Total: 41 bytes

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 20:24:32 +01:00
Denys Vlasenko f12fb1e409 sed: fix handling of escaped delimiters in s/// replacement
function                                             old     new   delta
parse_regex_delim                                    111     140     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 19:04:27 +01:00
Denys Vlasenko e998c7c032 sed: fix handling of escaped delimiters in s/// search pattern, closes 14541
function                                             old     new   delta
copy_parsing_escapes                                  67      96     +29
parse_regex_delim                                    109     111      +2
get_address                                          213     215      +2
add_cmd                                             1176    1178      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 35/0)               Total: 35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 18:48:49 +01:00
Denys Vlasenko 33a9f34df5 add busybox_ldscript.README.txt
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 15:46:05 +01:00
Denys Vlasenko 39369ff460 libbb/sha1: use SSE2 in unrolled x86-64 code. ~10% faster
function                                             old     new   delta
.rodata                                           108241  108305     +64
sha1_process_block64                                3502    3495      -7
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 1/1 up/down: 64/-7)              Total: 57 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-23 12:57:27 +01:00
Denys Vlasenko 1e825acf8d libbb: shrink lineedit_read_key()
function                                             old     new   delta
lineedit_read_key                                    237     231      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-18 00:36:42 +01:00
Denys Vlasenko 8ad2acf352 fix "defined but not used" warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-17 23:59:46 +01:00
Denys Vlasenko 12566e7f9b ash,hush: fix handling of SIGINT while waiting for interactive input
function                                             old     new   delta
lineedit_read_key                                    160     237     +77
__pgetc                                              522     589     +67
fgetc_interactive                                    244     309     +65
safe_read_key                                          -      39     +39
read_key                                             588     607     +19
record_pending_signo                                  23      32      +9
signal_handler                                        75      81      +6
.rodata                                           104312  104309      -3
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/1 up/down: 282/-3)            Total: 279 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-17 11:46:23 +01:00
Denys Vlasenko a277506a64 shell: add comments about SIGINT-related problems
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-16 23:54:46 +01:00
Denys Vlasenko c2788f88f4 libbb: introduce and use chdir_or_warn()
function                                             old     new   delta
chdir_or_warn                                          -      37     +37
send_cgi_and_exit                                    720     711      -9
xchdir                                                27      15     -12
setup_environment                                    233     217     -16
fork_job                                             449     433     -16
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 37/-53)            Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 12:56:10 +01:00
Denys Vlasenko 931c55f9e2 libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIR
Double negatives are hard to grok.

function                                             old     new   delta
login_main                                           986     988      +2
su_main                                              474     470      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-4)               Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 12:50:48 +01:00
Denys Vlasenko b3eec1651f sulogin: util-linux does not say "normal startup" on Ctrl-D
function                                             old     new   delta
sulogin_main                                         341     331     -10
.rodata                                           104327  104312     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 01:43:11 +01:00
Denys Vlasenko 96771ec5f5 sulogin: start _login_ shell only with -p
Also, shorten/eliminate messages to be closer to util-linux.

function                                             old     new   delta
packed_usage                                       34233   34238      +5
sulogin_main                                         340     341      +1
.rodata                                           104380  104327     -53
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 6/-53)             Total: -47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 01:38:47 +01:00
Denys Vlasenko 68b402ee51 ash: ^C with SIG_INGed SIGINT should not exit the shell
function                                             old     new   delta
__pgetc                                              501     522     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 01:15:10 +01:00
Denys Vlasenko d162a7b978 sulogin: increase util-linux compatibility
Change to root's HOME. Set some envvars. Steal ctty if necessary and possible.

function                                             old     new   delta
sulogin_main                                         240     340    +100
setup_environment                                    225     233      +8
su_main                                              479     474      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 108/-5)            Total: 103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-12 23:19:11 +01:00
Denys Vlasenko 004cefa918 reset: better --help text
function                                             old     new   delta
packed_usage                                       34175   34233     +58

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-12 17:21:14 +01:00
Denys Vlasenko 524fecf7c3 nmeter: %[md] %[mw] - dirty file-backed pages, writeback pages
function                                             old     new   delta
collect_mem                                          333     387     +54
.rodata                                           104369  104380     +11
packed_usage                                       34184   34175      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 65/-9)              Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-11 19:32:16 +01:00
Denys Vlasenko ff8fda8482 ls: implement ls -sh (human-readable allocated blocks)
function                                             old     new   delta
display_single                                       979    1018     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 22:59:49 +01:00
Denys Vlasenko 143356876b libbb/sha1: add a comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 22:43:24 +01:00
Denys Vlasenko e2952dfaff awk: input numbers are never octal or hex (only program consts can be)
function                                             old     new   delta
next_token                                           825     930    +105
getvar_i                                             114     129     +15
nextchar                                              49      53      +4
my_strtod                                            138       -    -138
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/0 up/down: 124/-138)          Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 22:42:35 +01:00
Emanuele Giacomelli 84a1305888 XXXsum: handle binary sums with " " in the path
If a line specifies a binary checksum whose path contains two adjacent
spaces, when checking digests with -c the two spaces will be used as the
separator between the digest and the pathname instead of " *", as shown:

$ echo foo > "/tmp/two  spaces"
$ md5sum -b "/tmp/two  spaces"   # This is GNU md5sum
d3b07384d113edec49eaa6238ad5ff00 */tmp/two  spaces
$ md5sum -b "/tmp/two  spaces" | ./busybox md5sum -c
md5sum: can't open 'spaces': No such file or directory
spaces: FAILED
md5sum: WARNING: 1 of 1 computed checksums did NOT match

function                                             old     new   delta
md5_sha1_sum_main                                    503     496      -7

Signed-off-by: Emanuele Giacomelli <emanuele.giacomelli@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 17:16:00 +01:00
Denys Vlasenko e7ff29402d libbb/sha1: simplify cpuid code
function                                             old     new   delta
sha1_begin                                           107     106      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 01:25:23 +01:00
Denys Vlasenko 805ececa61 whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 00:41:09 +01:00
Denys Vlasenko 0bab5da37e libbb/sha1: tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 14:55:31 +01:00
Denys Vlasenko 89092c61bc powertop: fix cpuid asm: ebx saving/restoring is properly done by gcc
function                                             old     new   delta
print_intel_cstates                                  481     477      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 01:33:46 +01:00
Denys Vlasenko a96ccbefe4 libbb/sha1: optional i686 hardware accelerates hashing
function                                             old     new   delta
sha1_process_block64_shaNI                             -     524    +524
sha1_begin                                            57     114     +57
.rodata                                           104353  104369     +16
static.shaNI                                           -       1      +1
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 2/0 up/down: 598/0)             Total: 598 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 01:32:13 +01:00
Denys Vlasenko 711e20ecb8 libbb/sha1: optional x86-64 hardware accelerates hashing
function                                             old     new   delta
sha1_process_block64_shaNI                             -     510    +510
sha1_begin                                            52     107     +55
.rodata                                           108285  108301     +16
static.shaNI                                           -       1      +1
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 2/0 up/down: 582/0)             Total: 582 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-07 00:43:59 +01:00
Vincent Stehlé a93668cc42 fdisk: recognize EBBR protective partitions
The MBR partition type 0xF8 is used by the Arm EBBR specification[1] for
protective partitions over fixed-location firmware images.

[1]: https://github.com/ARM-software/ebbr

Signed-off-by: Vincent Stehlé <vincent.stehle@arm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-06 10:55:53 +01:00
Denys Vlasenko 6062c0d19b libbb: change xstrndup, xmemdup to take size_t as size parameter
Also, remove entirely usually-disabled paranoia check (was also using
wrong config option to enable itself).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 23:03:54 +01:00
Denys Vlasenko db5546ca10 libbb: code shrink: introduce and use [_]exit_SUCCESS()
function                                             old     new   delta
exit_SUCCESS                                           -       7      +7
_exit_SUCCESS                                          -       7      +7
run_pipe                                            1562    1567      +5
pseudo_exec_argv                                     399     400      +1
finish                                                86      87      +1
start_stop_daemon_main                              1109    1107      -2
shutdown_on_signal                                    38      36      -2
runsv_main                                          1662    1660      -2
redirect                                            1070    1068      -2
read_line                                             79      77      -2
pause_and_low_level_reboot                            54      52      -2
list_i2c_busses_and_exit                             483     481      -2
less_exit                                             12      10      -2
identify                                            4123    4121      -2
grep_file                                           1161    1159      -2
getty_main                                          1519    1517      -2
fsck_minix_main                                     2681    2679      -2
free_session                                         132     130      -2
fdisk_main                                          4739    4737      -2
clean_up_and_exit                                     53      51      -2
bsd_select                                          1566    1564      -2
bb_daemonize_or_rexec                                198     196      -2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/17 up/down: 21/-34)           Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 22:16:06 +01:00
Denys Vlasenko 076f5e064f less: code shrink
function                                             old     new   delta
restore_tty                                            -      29     +29
less_main                                           2107    2105      -2
getch_nowait                                         253     251      -2
buffer_print                                         614     612      -2
less_exit                                             51      12     -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 29/-45)            Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 22:04:21 +01:00
Denys Vlasenko 34e0bb3931 sort: support -h
function                                             old     new   delta
static.scale_suffix                                    -      62     +62
.rodata                                           104304  104336     +32
compare_keys                                         820     848     +28
packed_usage                                       34159   34184     +25
static.suffix                                          -       9      +9
sort_opt_str                                          37      38      +1
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/0 up/down: 157/0)             Total: 157 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-05 12:05:55 +01:00
Denys Vlasenko cc7d2e2178 sort: fix -s -r interaction: 'stable' order is not affected by -r
function                                             old     new   delta
compare_keys                                         818     820      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 23:53:21 +01:00
Denys Vlasenko dfd8aafcf5 libbb: fflush_stdout_and_exit(0) still exits with _error_ (not 0!) if fflush fails
function                                             old     new   delta
fflush_stdout_and_exit                                36      40      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 23:36:16 +01:00
Denys Vlasenko 31f45c1b36 libbb: factor out fflush_stdout_and_exit(EXIT_SUCCESS)
function                                             old     new   delta
fflush_stdout_and_exit_SUCCESS                         -       7      +7
xxd_main                                             890     888      -2
vlock_main                                           353     351      -2
uuencode_main                                        318     316      -2
uniq_main                                            427     425      -2
uname_main                                           250     248      -2
sort_main                                            853     851      -2
shuf_main                                            500     498      -2
route_main                                           238     236      -2
readlink_main                                        113     111      -2
nice_main                                            156     154      -2
last_main                                            957     955      -2
ipcs_main                                            960     958      -2
env_main                                             209     207      -2
chrt_main                                            464     462      -2
cal_main                                             921     919      -2
baseNUM_main                                         650     648      -2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/16 up/down: 7/-32)            Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 23:31:58 +01:00
Denys Vlasenko 286b33721d sed: correctly handle 'w FILE' commands writing to the same file
function                                             old     new   delta
sed_xfopen_w                                           -      84     +84

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 19:42:36 +01:00
Denys Vlasenko ed2af2e82d build system: detect if build host has no bzip2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 14:32:41 +01:00
Denys Vlasenko c3cfcc9242 libbb/sha1: x86_64 version: reorder prologue/epilogue insns
Not clear exactly why, but this increases hashing speed
on Skylake from 454 MB/s to 464 MB/s.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 01:45:52 +01:00
Denys Vlasenko 1fc520ed28 md5/shaXsum: use FEATURE_COPYBUF_KB to size the buffer instead of fixed 4k
function                                             old     new   delta
md5_sha1_sum_main                                    536     565     +29
hash_file                                            419     401     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 29/-18)             Total: 11 bytes

In my test, for unrolled sha1, COPYBUF_KB=64 increases throughput
from 367 MB/s to 457 MB/s.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-04 00:51:04 +01:00
Denys Vlasenko 7abb2bb96e libbb/sha1: x86_64 version: tidying up, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 17:02:48 +01:00
Denys Vlasenko 4387077f8e typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 13:14:09 +01:00
Denys Vlasenko 947bef0dea libbb/sha1: x86_64 version: generate from a script, optimize a bit
function                                             old     new   delta
sha1_process_block64                                3569    3502     -67

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 13:10:30 +01:00
Denys Vlasenko 05fd13ebec libbb/sha1: x86_64 version: move to a separate .S file, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-03 12:57:36 +01:00
Denys Vlasenko 5c0c558231 libbb/sha1: code shrink in medium-speed version
function                                             old     new   delta
sha1_process_block64                                 654     641     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-02 01:56:35 +01:00
Denys Vlasenko 4d4f1f2096 libbb/sha1: x86_64 version: bswap in 64-bit chunks
function                                             old     new   delta
sha1_process_block64                                3562    3570      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-01 15:42:15 +01:00
Denys Vlasenko d643010fee libbb/sha1: shrink x86_64 version - use r8..15 for W[8..15]
function                                             old     new   delta
sha1_process_block64                                3683    3562    -121

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-01 15:01:53 +01:00
Denys Vlasenko 5f68170204 libbb/sha1: assembly versions for x86
32 bits:
function                                             old     new   delta
sha1_process_block64                                3950    3657    -293
64 bits:
sha1_process_block64                                4167    3683    -484

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-01 13:57:34 +01:00
Denys Vlasenko f09d088fdf libbb/sha1: shrink and speed up fully unrolled version
function                                             old     new   delta
sha1_process_block64                                4149    3950    -199

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-31 17:07:47 +01:00
Denys Vlasenko 0b62a08777 libbb/sha1: add config-selectable partially unrolled version
function                                             old     new   delta
sha1_process_block64                                 364     732    +368
static.rconsts                                        16       -     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 368/-16)           Total: 352 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-30 18:54:02 +01:00
Denys Vlasenko 25aadc893d libbb/sha1: add config-selectable fully unrolled version, closes 14391
function                                             old     new   delta
sha1_process_block64                                 364    4167   +3803
static.rconsts                                        16       -     -16
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 3803/-16)         Total: 3787 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-30 13:17:16 +01:00
Sören Tempel 9173c9cce4 ed: add support for -s command-line option as mandated by POSIX
Apart from the -p option, POSIX also mandates an -s option which
suppresses the output of byte counts for the e, E, r, and w command.
From these commands, Busybox ed presently only implements the r and w
commands. This commit ensures that these two command do not output any
bytes counts when the -s option is passed. The shell escape command,
also effected by the -s option, is not implemented by Busybox at the
moment.

function                                             old     new   delta
packed_usage                                       34096   34115     +19
doCommands                                          1887    1900     +13
readLines                                            388     397      +9
.rodata                                           104196  104200      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 45/0)               Total: 45 bytes

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-29 19:01:32 +01:00
Denys Vlasenko 0e2cb6d1e2 echo: add FIXME comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-29 07:26:23 +01:00
Denys Vlasenko 0fcc7f5f73 scripts/echo.c: fix NUL handling in "abc\0 def"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-28 21:05:59 +01:00
Denys Vlasenko f1d06462e8 libbb: cose shrink in sha1
function                                             old     new   delta
sha1_process_block64                                 356     342     -14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-28 09:05:12 +01:00
Denys Vlasenko 44075929a8 Start 1.36.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-26 18:40:55 +01:00
Denys Vlasenko e512aeb0fb Bump version to 1.35.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-26 17:55:58 +01:00
Denys Vlasenko 97c00ae134 httpd: fix compile failure if !FEATURE_HTTPD_RANGES
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-26 14:29:37 +01:00
Dominique Martinet 4fe954c148 sed: do not ignore 'g' modifier when match starts with ^
It is perfectly valid to start a regex with ^ and have other patterns
with \| that can match more than once, e.g. the following example
should print ca, as illustrated with gnu sed:
$ echo 'abca' | sed -e 's/^a\|b//g'
ca

busybox before patch:
$ echo 'abca' | busybox sed -e 's/^a\|b//g'
bca

busybox after patch:
$ echo 'abca' | ./busybox sed -e 's/^a\|b//g'
ca

regcomp handles ^ perfectly well as illustrated with the second 'a' that
did not match in the example, we ca leave the non-repeating to it if
appropriate.
The check had been added before using regcomp and was required at the
time (f36635cec6) but no longer makes sense now.

(tested with glibc and musl libc)

function                                             old     new   delta
add_cmd                                             1189    1176     -13

Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-25 04:20:28 +01:00
Sören Tempel a05a3d5932 ed: align output of read command with POSIX.1-2008
POSIX.1-2008 mandates the following regarding the read command:

	If the read is successful, and -s was not specified, the number
	of bytes read shall be written to standard output in the
	following format:

	    "%d\n", <number of bytes read>

This commit aligns the output of busybox ed with POSIX.1-2008 by
removing the file name from the output for the read command.

This slipped through in 4836a0708fd0aaeb82871a3762b40fcf4b61e812.

function                                             old     new   delta
.rodata                                           104203  104196      -7
readLines                                            409     388     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-28)             Total: -28 bytes

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-19 23:17:52 +01:00
Sören Tempel f26eb796e2 ed: fix current line number for file passed via the command-line
POSIX.1-2008 mandates the following regarding the file command-line
argument:

	If the file argument is given, ed shall simulate an e command
	on the file named by the pathname […]

The specification for the e command mandates the following behaviour
regarding the current line number in POSIX.1-2008:

	The current line number shall be set to the address of the last
	line of the buffer.

However, without this commit, busybox ed will set the current line
number to 1 if a file is given on the command-line and this file is not
empty (lastNum != 0). This is incorrect and fixed in this commit by not
modifying the current line number in ed_main(). As such, the current
line number will be zero for empty files and otherwise be set to the
address of the last line of the buffer.

function                                             old     new   delta
ed_main                                              144     128     -16

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-19 23:16:02 +01:00
Matthew Slowe 7d49fedc86 timeout: add support for "timeout -k KILL_SECS"
function                                             old     new   delta
timeout_main                                         307     373     +66
timeout_wait                                           -      42     +42
.rodata                                           104201  104203      +2
packed_usage                                       34097   34096      -1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 110/-1)            Total: 109 bytes

Signed-off-by: Matthew Slowe <foo@mafoo.org.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 23:11:17 +01:00
Denys Vlasenko c1eac153e8 cmp: code shrink
function                                             old     new   delta
.rodata                                           104203  104201      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 22:43:45 +01:00
Sören Tempel bfd8738154 ed: add support for -p command-line option as mandated by POSIX
The POSIX.1-2008 specification of ed(1) mandates two command-line
options: -p (for specifying a prompt string) and -s (to suppress writing
of byte counts). This commit adds support for the former. Furthermore,
it also changes the default prompt string to an empty string (instead
of ": ") since this is also mandated by POSIX:

	-p string Use string as the prompt string when in command mode.
	          By default, there shall be no prompt string.

function                                             old     new   delta
ed_main                                              112     144     +32
packed_usage                                       34074   34097     +23
doCommands                                          1889    1887      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 55/-2)              Total: 53 bytes

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 22:35:25 +01:00
Walter Lozano 579894bfd2 cmp: add support for -n
Add support to for "-n" to cmp in order to compare at most n bytes.

function                                             old     new   delta
cmp_main                                             552     589     +37
.rodata                                           104198  104203      +5
packed_usage                                       34102   34074     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 42/-28)             Total: 14 bytes

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 22:07:06 +01:00
Denys Vlasenko 00d10cb6eb docs/embedded-scripts.txt: whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 21:38:02 +01:00
Aaro Koskinen aaade69ce9 find: implement -samefile
function                                             old     new   delta
parse_params                                        1461    1606    +145
func_samefile                                          -      42     +42
packed_usage                                       34079   34102     +23
static.params                                        261     271     +10
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 220/0)             Total: 220 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 21:33:15 +01:00
Ron Yorston 7105e4afdd printf: allow 0 as a flag and allow multiple flags
The '%' character in a format specification may be followed by
one or more flags from the list "+- #0".  BusyBox printf didn't
support the '0' flag or allow multiple flags to be provided.
As a result the formats '%0*d' and '%0 d' were considered to be
invalid.

The lack of support for '0' was pointed out by Andrew Snyder on the
musl mailing list:

   https://www.openwall.com/lists/musl/2021/12/14/2

function                                             old     new   delta
printf_main                                          860     891     +31
.rodata                                            99281   99282      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0)               Total: 32 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 21:13:26 +01:00
Denys Vlasenko b720629dfe httpd: do not send Last-Modified / ETag / Content-Length for error pages
function                                             old     new   delta
send_headers                                         713     701     -12
send_headers_and_exit                                 20      34     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 21:02:16 +01:00
Denys Vlasenko 70683faf38 httpd: don't send Content-Length in error pages header
function                                             old     new   delta
send_headers                                         701     713     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-17 20:37:58 +01:00
Peter Korsgaard cb91a818c8 libarchive/get_header_ar.c: fix extraction of archives from binutils in deterministic mode
GNU binutils in deterministic mode (ar rD or built with
--enable-deterministic-archives) hard codes file mode to 0644 (NOT 0100644)
since https://github.com/bminor/binutils-gdb/commit/36e4dce69dd2

This confuses busybox ar x (data_extract_all):

touch a; ar rD a.ar a
ar: creating a.ar

busybox ar x a.ar
ar: unrecognized file type
hexdump -C a.ar
00000000  21 3c 61 72 63 68 3e 0a  61 2f 20 20 20 20 20 20  |!<arch>.a/      |
00000010  20 20 20 20 20 20 20 20  30 20 20 20 20 20 20 20  |        0       |
00000020  20 20 20 20 30 20 20 20  20 20 30 20 20 20 20 20  |    0     0     |
00000030  36 34 34 20 20 20 20 20  30 20 20 20 20 20 20 20  |644     0       |
00000040  20 20 60 0a                                       |  `.|

As a workaround, force the mode bits to S_IFREG, as nothing else makes sense
for ar.

function                                             old     new   delta
get_header_ar                                        539     542      +3

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-12 23:34:43 +01:00
Denys Vlasenko e67b80f473 udhcpc6: fix udhcp_find_option to actually find DHCP6 options
udhcp_insert_new_option treats code for IPv6 as follows:

new->data[D6_OPT_CODE] = code >> 8;
new->data[D6_OPT_CODE + 1] = code & 0xff;

udhcp_find_option tests the code as follows:

while (opt_list && opt_list->data[OPT_CODE] < code)
...
if (opt_list && opt_list->data[OPT_CODE] == code)

So yes, OPT_CODE and D6_OPT_CODE are both 0, but the D6_OPT_CLIENTID =
1 value means that the 1 is in the seconds byte, and udhcp_find_option
is only looking at the first byte,  So the send_d6_release can never
find it the created option.

function                                             old     new   delta
udhcp_find_option                                     28      53     +25
attach_option                                        276     284      +8
udhcpc6_main                                        2602    2607      +5
perform_d6_release                                   262     267      +5
udhcpd_main                                         1518    1520      +2
udhcpc_main                                         2542    2544      +2
add_serverid_and_clientid_options                     46      48      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 49/0)               Total: 49 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-12 17:13:54 +01:00
Martin Kaiser 9b67880719 Makefile.flags: use all cflags for crypt and rt checks
To check if libcrypt and librt are available, we check if we can
compile and link a simple test program.

These checks do not match the actual linking if CONFIG_STATIC is enabled.
For CONFIG_STATIC, CFLAGS_busybox is set to -static. The checks don't use
CFLAGS_busybox and detect a shared libcrypt or librt. If we link busybox
later and we have no static libcrypt or librt, linking will fail.

Update the libcrypt and librt checks to use CFLAGS_busybox.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-12 13:16:40 +01:00
Ildar Shaimordanov b9fba185c5 wget: allow end-users to customize Content-Type for --post-data and --post-file
More explanation in this PR:
https://github.com/rmyorston/busybox-w32/pull/233

The real use-case:
wget https://api.github.com/markdown/raw --header "Content-Type: text/plain"

function                                             old     new   delta
wget_main                                           2560    2581     +21
wget_user_headers                                     62      76     +14
.rodata                                           104196  104197      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0)               Total: 36 bytes

Signed-off-by: Ildar Shaimordanov <ildar.shaimordanov@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-12 03:22:43 +01:00
Denys Vlasenko c7b90dc4d1 uudecode: special-case "/dev/stdout", closes 14241
function                                             old     new   delta
uudecode_main                                        295     322     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-12 00:34:15 +01:00
Denys Vlasenko 27df6aeef2 tls: P256: factor out "multiply then reduce" operation
function                                             old     new   delta
sp_256_mont_mul_and_reduce_8                           -      44     +44
sp_256_ecc_mulmod_8                                  517     442     -75
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 44/-75)            Total: -31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-11 23:27:40 +01:00
Denys Vlasenko b240733ae7 tls: x25519: code shrink by factoring out common code
function                                             old     new   delta
fe_reduce                                              -      37     +37
lm_add                                                67      43     -24
fe_mul_c                                              62      38     -24
fe_mul__distinct                                     138     112     -26
curve25519                                           800     767     -33
lm_sub                                                98      64     -34
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/5 up/down: 37/-141)          Total: -104 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-12-01 15:09:44 +01:00
Denys Vlasenko 8514b4166d tls: P256: enable 64-bit version of montgomery reduction
After more testing, (1) I'm more sure it is indeed correct, and
(2) it is a significant speedup - we do a lot of those multiplications.

function                                             old     new   delta
sp_512to256_mont_reduce_8                            191     223     +32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-28 21:43:51 +01:00
Denys Vlasenko 90b0d33044 tls: P256: add 64-bit montgomery reduce (disabled), small optimization in 32-bit code
function                                             old     new   delta
sp_512to256_mont_reduce_8                            191     185      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-28 15:44:08 +01:00
Denys Vlasenko 832626227e tls: P256: add comment on logic in sp_512to256_mont_reduce_8, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-28 12:55:20 +01:00
Denys Vlasenko 00b5051cd2 libbb: code shrink in des encryption, in setup_salt()
function                                             old     new   delta
pw_encrypt                                           978     971      -7
.rodata                                           108208  108192     -16
des_crypt                                           1211    1181     -30
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-53)             Total: -53 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-28 12:21:23 +01:00
Denys Vlasenko cfb615781d tls: P256: simplify sp_256_mont_inv_8 (no need for a temporary)
function                                             old     new   delta
sp_256_ecc_mulmod_8                                  543     517     -26

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-28 11:15:34 +01:00
Bernhard Reutner-Fischer bfefa6ab6c libarchive: remove duplicate forward declaration
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2021-11-28 10:53:22 +01:00
Denys Vlasenko 1b93c7c4ec tls: P256: pad struct sp_point to 64 bits (on 64-bit arches)
function                                             old     new   delta
curve_P256_compute_pubkey_and_premaster              198     190      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-28 02:56:02 +01:00
Denys Vlasenko 0b13ab66f4 tls: P256: trivial x86-64 fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 19:36:23 +01:00
Denys Vlasenko f92ae1dc4b tls: P256: change logic so that we don't need double-wide vectors everywhere
Change sp_256to512z_mont_{mul,sqr}_8 to not require/zero upper 256 bits.
There is only one place where we actually used that (and that's why there
used to be zeroing memset of top half!). Fix up that place.
As a bonus, 256x256->512 multiply no longer needs to care for
"r overlaps a or b" case.

This shrinks sp_point structure as well, not just temporaries.

function                                             old     new   delta
sp_256to512z_mont_mul_8                              150       -    -150
sp_256_mont_mul_8                                      -     147    +147
sp_256to512z_mont_sqr_8                                7       -      -7
sp_256_mont_sqr_8                                      -       7      +7
sp_256_ecc_mulmod_8                                  494     543     +49
sp_512to256_mont_reduce_8                            243     249      +6
sp_256_point_from_bin2x32                             73      70      -3
sp_256_proj_point_dbl_8                              353     345      -8
sp_256_proj_point_add_8                              544     499     -45
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/3 up/down: 209/-213)           Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 19:27:03 +01:00
Denys Vlasenko 9c671fe3dd tls: P256: do not open-code copying of struct variables
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 18:42:27 +01:00
Denys Vlasenko dcfd8d3d10 tls: P256: fix sp_256_div2_8 - it wouldn't use a[] if low bit is 0
It worked by chance because the only caller passed both parameters
as two pointers to the same array.
My fault (I made this error when converting from 26-bit code).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 16:24:49 +01:00
Denys Vlasenko 8cbb70365f tls: P256: remove redundant zeroing in sp_256_map_8
Previous change made it obvious that we zero out already-zeroed high bits

function                                             old     new   delta
sp_256_ecc_mulmod_8                                  534     494     -40

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 15:50:40 +01:00
Denys Vlasenko 4415f7bc06 tls: P256: explain which functions use double-wide arrays, no code changes
function                                             old     new   delta
sp_512to256_mont_reduce_8                              -     243    +243
sp_256to512z_mont_mul_8                                -     150    +150
sp_256to512z_mont_sqr_8                                -       7      +7
sp_256_mont_sqr_8                                      7       -      -7
sp_256_mont_mul_8                                    150       -    -150
sp_256_mont_reduce_8                                 243       -    -243
------------------------------------------------------------------------------
(add/remove: 3/3 grow/shrink: 0/0 up/down: 400/-400)            Total: 0 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 15:47:26 +01:00
Denys Vlasenko bbda85c74b tls: P256: remove constant-time trick in sp_256_proj_point_add_8
function                                             old     new   delta
sp_256_proj_point_add_8                              576     544     -32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 15:06:57 +01:00
Denys Vlasenko 26c8522522 tls: P256: do not open-code copying of struct variables
function                                             old     new   delta
sp_256_ecc_mulmod_8                                  536     534      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 15:00:14 +01:00
Denys Vlasenko 446d136109 tls: tweak debug printout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 12:03:43 +01:00
Denys Vlasenko 4bc9da1071 tls: P256: 64-bit optimizations
function                                             old     new   delta
sp_256_proj_point_dbl_8                              421     428      +7
sp_256_point_from_bin2x32                             78      84      +6
sp_256_cmp_8                                          38      42      +4
sp_256_to_bin_8                                       28      31      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 20/0)               Total: 20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-27 11:28:11 +01:00
Denys Vlasenko 15f7d618ea which: add -a to help text
function                                             old     new   delta
packed_usage                                       34075   34079      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-09 13:51:22 +01:00
Ariadne Conill 836b79211d cpio: add support for --renumber-inodes like GNU cpio
The --renumber-inodes option renumbers the inodes starting from 1,
so that the sequence of inodes is always stable.  This helps with
reproducibility.

function                                             old     new   delta
cpio_o                                               961    1045     +84
.rodata                                            78422   78440     +18
bbconfig_config_bz2                                 6168    6164      -4
packed_usage                                       25764   25756      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 102/-12)            Total: 90 bytes

Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-13 17:56:17 +02:00
Ariadne Conill 8aa5585ff4 cpio: add support for --ignore-devno like GNU cpio
The --ignore-devno option is used to set device numbers to (0, 0).
This can be useful in verifying whether a CPIO archive is reproducible.

function                                             old     new   delta
cpio_o                                               922     961     +39
.rodata                                            78407   78422     +15
bbconfig_config_bz2                                 6161    6167      +6
packed_usage                                       25770   25764      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 60/-6)              Total: 54 bytes

Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-13 17:53:15 +02:00
Denys Vlasenko aaf3d5ba74 shell: tweak --help
Even though formally it is -s [ARGS], "sh -s" without ARGS
is the same as just "sh". And we are already over 80 chars wide
for ash --help, so make it shorter.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-13 11:25:42 +02:00
Denys Vlasenko 62f1eed1e1 hush: in a comment, document what -i might be doing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-13 00:09:07 +02:00
Sören Tempel c33bbcb92f ed: align output of read/write commands with POSIX-1.2008
POSIX.1-2008 mandates the following regarding the write command:

	If the command is successful, the number of bytes written shall
	be written to standard output, unless the -s option was
	specified, in the following format:

		"%d\n", <number of bytes written>

function                                             old     new   delta
readLines                                            447     409     -38
doCommands                                          1940    1889     -51
.rodata                                           104219  104163     -56
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-145)           Total: -145 bytes

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-12 17:32:03 +02:00
Denys Vlasenko 94c78aa0b9 config system: move some options closer to relevalnt tool subdirectories
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-12 13:23:29 +02:00
Denys Vlasenko 7c3e96d4b3 shell: use more compact SHELL_ASH / HUSH config defines. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-12 01:24:32 +02:00
Denys Vlasenko f4fcd74a6e shell: do not read user database for every prompt - only for those which need it
function                                             old     new   delta
get_user_strings                                       -      52     +52
get_homedir_or_NULL                                    -      23     +23
parse_and_put_prompt                                 823     838     +15
null_str                                               1       -      -1
complete_cmd_dir_file                                814     812      -2
deinit_S                                              51      42      -9
read_line_input                                     3059    3015     -44
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/3 up/down: 90/-56)             Total: 34 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-11 23:08:31 +02:00
Denys Vlasenko 6ba1f2d0bc tar: prevent malicious archives with enormous long name sizes OOMing the machine
function                                             old     new   delta
get_header_tar                                      1707    1752     +45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-11 19:28:39 +02:00
Denys Vlasenko aec8fbfb83 whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-11 19:11:06 +02:00
Denys Vlasenko 5acf5e1f87 shell: fix script's comm field if ENABLE_FEATURE_PREFER_APPLETS=y
function                                             old     new   delta
re_execed_comm                                         -      46     +46
main                                                  72      86     +14
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 60/0)               Total: 60 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-11 18:44:00 +02:00
Denys Vlasenko 23aba8a9a6 tls: code shrink curve25519
function                                             old     new   delta
fe_select                                             39       -     -39
curve25519                                           849     800     -49
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-88)             Total: -88 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-11 16:31:47 +02:00
Denys Vlasenko 74ee3f2f73 tls: remove unused tls_symmetric.h (was used by old "big" AES code)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-11 13:46:30 +02:00
Bernhard Reutner-Fischer 376b2ceff6 chrt: silence analyzer warning
warning: use of uninitialized value ‘priority’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value]

chrt_main                                            499     496      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes
   text	   data	    bss	    dec	    hex	filename
 972157	   4235	   1840	 978232	  eed38	busybox_old
 972154	   4235	   1840	 978229	  eed35	busybox_unstripped

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2021-10-10 17:29:18 +02:00
Denys Vlasenko d8e39b5917 find: code shrink -{m,a,c}{time,min}
function                                             old     new   delta
time_cmp                                               -     181    +181
func_mmin                                            171      31    -140
func_mtime                                           180      34    -146
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 181/-286)         Total: -105 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-10 15:18:12 +02:00
Denys Vlasenko d3dbf4ac05 *: add more beneficial NOINLINEs
function                                             old     new   delta
dec_main                                               -    1729   +1729  -41 bytes
fallbackQSort3                                         -     671    +671  -70 bytes
verify_sun                                             -     481    +481 -107 bytes
verify                                              1330     742    -588
fallbackSort                                        1469     728    -741
unpack_xz_stream                                    2306     536   -1770
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/3 up/down: 2881/-3099)       Total: -218 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-10 14:32:05 +02:00
Denys Vlasenko 53b2fdcdba *: add NOINLINEs where code noticeably shrinks
function                                             old     new   delta
display                                               85    1463   +1378  -73 bytes
select_and_cluster                                     -    1088   +1088 -139 bytes
parse_reply                                            -     979    +979 -109 bytes
zbc_num_sqrt                                           -     632    +632 -191 bytes
show_bridge_port                                       -     585    +585  -56 bytes
sp_256_proj_point_add_8                                -     576    +576  -45 bytes
encode_then_append_var_plusminus                       -     554    +554 -118 bytes
read_mode_db                                           -     537    +537  -47 bytes
fbset_main                                          1331     747    -584
sp_256_ecc_mulmod_8                                 1157     536    -621
brctl_main                                          2189    1548    -641
expand_one_var                                      2544    1872    -672
zxc_vm_process                                      6412    5589    -823
send_queries                                        1813     725   -1088
recv_and_process_peer_pkt                           2245    1018   -1227
bb_dump_dump                                        1531      80   -1451
------------------------------------------------------------------------------
(add/remove: 7/0 grow/shrink: 1/8 up/down: 6329/-7107)       Total: -778 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-10 13:50:53 +02:00
YU Jincheng 5156b24553 Make const ptr assign as function call in clang
- This can act as memory barrier in clang to avoid
  read before assign of a const ptr

Signed-off-by: LoveSy <shana@zju.edu.cn>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09 22:30:45 +02:00
Ismael Luceno 04ad683bf9 find: implement -amin, -atime, -cmin, and -ctime
function                                             old     new   delta
func_mtime                                           130     180     +50
func_mmin                                            121     171     +50
static.params                                        235     261     +26
parse_params                                        1435    1461     +26
packed_usage                                       34025   34033      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 160/0)             Total: 160 bytes

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09 21:45:59 +02:00
Denys Vlasenko 49bcf9f40c hush: speed up ${x//\*/|} too
function                                             old     new   delta
expand_one_var                                      2502    2544     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09 03:52:04 +02:00
Denys Vlasenko 5aaeb550b7 ash: speed up ${x//\*/|} too, make it independent of ASH_OPTIMIZE_FOR_SIZE
function                                             old     new   delta
subevalvar                                          1503    1545     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09 03:33:22 +02:00
Alin Mr 21e8dbfd9d ash.c: speedup ${s:} substring (no quotes)
This trivial patch makes ${s:...} at least as fast as ${s#??..}
in simple tests. It's probably faster for longer substrings,
but then one wouldn't use ${s#"1024???s"} anyway -
one would switch away from sh.

function                                             old     new   delta
subevalvar                                          1457    1503     +46

Signed-off-by: Alin Mr <almr.oss@outlook.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09 02:15:52 +02:00
Ron Yorston 94eb1c4dc6 libbb: better coreutils compatibility for realpath
Add some tests which coreutils realpath pass but BusyBox realpath
fails (bar one).  Adjust xmalloc_realpath_coreutils() so the tests
pass:

- Expand symbolic links before testing whether the last path component
  exists.

- When the link target is a relative path canonicalize it by passing
  it through xmalloc_realpath_coreutils() as already happens for
  absolute paths.

- Ignore trailing slashes when finding the last path component and
  correctly handle the case where the only slash is at the start of
  the path.  This requires ignoring superfluous leading slashes.

- Undo all changes to the path so error messages from the caller show
  the original filename.

function                                             old     new   delta
xmalloc_realpath_coreutils                           214     313     +99

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09 01:47:12 +02:00
Denys Vlasenko 86ba007b84 xxd: fix -p -r, closes 13881
function                                             old     new   delta
xxd_main                                             893     890      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 23:03:54 +02:00
Denys Vlasenko d315a77a79 resize: use tcgetattr(TCSAFLUSH) instead of TCSANOW, closes 13811
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 22:18:24 +02:00
Andrej Valek ecac9853f2 mktemp: add --tmpdir option
Make mktemp more compatible with coreutils.
- add "--tmpdir" option
- add long variants for "d,q,u" options

Note: Upstream ca-certificate update script started using this option.

function                                             old     new   delta
.rodata                                           104179  104219     +40
mktemp_main                                          186     194      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 48/0)               Total: 48 bytes

Signed-off-by: Andrej Valek <andrej.valek@siemens.com>
Signed-off-by: Peter Marko <peter.marko@siemens.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 21:02:56 +02:00
Denys Vlasenko b198e9aa93 tar: improve comments, add FIXMEs. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 19:34:20 +02:00
Denys Vlasenko 049775b2ef libbb.h: fix logic selecting incorrect BB_STRTOOFF for !LFS configs
BB_STRTOOFF() was equal to bb_strtou(). On x86_64, it's incorrect.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 15:54:40 +02:00
Denys Vlasenko 84874785c2 httpd: if range is not specified, correctly fall back to read/write loop
range_start was staying -1, and comparison meant to detect
"is it the first sendfile that failed, or not the first?"
was making incorrect decision. The result: nothing is sent.

function                                             old     new   delta
send_file_and_exit                                   865     877     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 15:41:08 +02:00
Denys Vlasenko 50c5b36dd7 help: s/Don't daemonize/Run in foreground/g
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 15:02:53 +02:00
Denys Vlasenko d2e0d3f514 mdev: tweak --help
function                                             old     new   delta
packed_usage                                       33993   34008     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 14:30:50 +02:00
Denys Vlasenko cf4dc4a09d mount: "mount -o rw ...." should not fall back to RO mount
The reported case was an attempt to remount,rw a CD-ROM:

  mount -o remount,rw /mnt/sr0

which "succeeded" by falling back to RO:

  mount("/dev/sr0", "/mnt/sr0", 0x412862, MS_REMOUNT|MS_SILENT|MS_RELATIME, "nojoliet,check=s,map=n,blocksize"...) = -1 EROFS (Read-only file system)
  ...
  mount("/dev/sr0", "/mnt/sr0", 0x412862, MS_RDONLY|MS_REMOUNT|MS_SILENT|MS_RELATIME, "nojoliet,check=s,map=n,blocksize"...) = 0

Clearly, not what was intended!

function                                             old     new   delta
parse_mount_options                                  241     267     +26
mount_main                                          1198    1211     +13
singlemount                                         1301    1313     +12
inetd_main                                          1919    1911      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 51/-8)              Total: 43 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-08 02:20:10 +02:00
Nicholas Niro c28313bb17 ip: added support for setting netns on devices
function                                             old     new   delta
set_netns                                              -     130    +130
do_iplink                                           1252    1315     +63
.rodata                                           104173  104179      +6
packed_usage                                       34020   33993     -27
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 199/-27)           Total: 172 bytes

Signed-off-by: Nicholas Niro <blowfist@xroutine.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-07 23:24:56 +02:00
Denys Vlasenko eb048a450c ps: fix -o pid=PID,args interpreting entire "PID,args" as header
procps-ng 3.3.15 does not do this.
(It could, allowing commas in headers and requiring
"ps -opid=PID -oargs" form for this case, but it does not).

function                                             old     new   delta
parse_o                                              167     190     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-07 21:55:16 +02:00
Ismael Luceno 421c8767ba find: Unify time comparisons
Split the common part into a function, to be reused.

The tail call is optimized, meaning now mmin/mtime just prepare arguments
and jump into the common code, thus near zero overhead.

This reduces code size slightly, e.g. on x86_64:
   text    data     bss     dec     hex filename
   4806       0       0    4806    12c6 findutils/find.o.orig
   4782       0       0    4782    12ae findutils/find.o

Of course, the savings are even greater when implementing atime/ctime
variants.

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-07 16:40:37 +02:00
Ismael Luceno 0084c44799 config: find: Fix mtime/mmin description
s/modified time/modification time/

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-07 16:38:32 +02:00
YU Jincheng 1f925038ab *: generalize "const trick"
While at it, change all "__asm__" to "asm"

Co-authored-by: canyie <31466456+canyie@users.noreply.github.com>
Signed-off-by: YU Jincheng <shana@zju.edu.cn>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-07 15:22:35 +02:00
Denys Vlasenko 17e6fb06b3 tls: whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 21:22:36 +02:00
Denys Vlasenko 5e9c617021 tls: P256: sp_256_sub_8_p256_mod always subtracts in-place, use that
i386:

function                                             old     new   delta
sp_256_mont_reduce_8                                 245     243      -2
sp_256_mont_dbl_8                                     26      24      -2
sp_256_ecc_mulmod_8                                 1161    1157      -4
sp_256_proj_point_dbl_8                              359     353      -6
sp_256_sub_8_p256_mod                                 71      32     -39
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-53)             Total: -53 bytes

non-asm code:

function                                             old     new   delta
sp_256_sub_8_p256_mod                                  -      12     +12
sp_256_mont_reduce_8                                 250     243      -7
sp_256_mont_dbl_8                                     31      24      -7
sp_256_ecc_mulmod_8                                 1171    1157     -14
sp_256_proj_point_dbl_8                              374     353     -21
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 12/-49)            Total: -37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 20:19:30 +02:00
Denys Vlasenko 87e3f2e9f8 tls: P256: x86-64 optimized sp_256_sub_8_p256_mod
function                                             old     new   delta
sp_256_sub_8_p256_mod                                  -      53     +53
sp_256_mont_reduce_8                                 223     217      -6
sp_256_mont_dbl_8                                     38      32      -6
sp_256_ecc_mulmod_8                                 1535    1529      -6
sp_256_proj_point_dbl_8                              469     454     -15
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 53/-33)             Total: 20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 19:59:39 +02:00
Denys Vlasenko 911344a998 tls: P256: x86-64 assembly
function                                             old     new   delta
sp_256_mont_mul_8                                    127     155     +28
sp_256_proj_point_dbl_8                              448     469     +21
sp_256_mont_sub_8                                     23      35     +12
sp_256_mont_dbl_8                                     26      38     +12
sp_256_sub_8                                          44      49      +5
sp_256_ecc_mulmod_8                                 1530    1535      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 83/0)               Total: 83 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 17:17:34 +02:00
Denys Vlasenko 22fd8fd3f4 tls: P256: tweak arm assembly (currently disabled)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 16:10:49 +02:00
Denys Vlasenko d74993d31d tls: P@256: remove "header comment is kept intact" comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 14:28:47 +02:00
Denys Vlasenko 567eefcaf8 tls: P256: do not dumplicate sp_256_sub_8()
function                                             old     new   delta
sp_256_proj_point_dbl_8                              359     374     +15
sp_256_ecc_mulmod_8                                 1159    1171     +12
sp_256_mont_reduce_8                                 245     250      +5
sp_256_mont_dbl_8                                     26      31      +5
sp_256_sub_8_p256_mod                                 43       -     -43
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 4/0 up/down: 37/-43)             Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 14:25:54 +02:00
Denys Vlasenko 00f2cceb6a tls: P256: shrink sp_256_mul_add_8 a bit more
function                                             old     new   delta
sp_256_mont_reduce_8                                 257     245     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 10:15:29 +02:00
Denys Vlasenko c784284615 tls: P256: propagate constants, create dedicated "subtract p256_mod" function
8 instances of this subtraction probably warrant a few bytes more of code.

function                                             old     new   delta
sp_256_sub_8_p256_mod                                  -      71     +71
sp_256_mont_sub_8                                      -      29     +29
sp_256_mont_dbl_8                                      -      26     +26
sp_256_mont_reduce_8                                 262     257      -5
sp_256_ecc_mulmod_8                                 1171    1161     -10
sp_256_proj_point_dbl_8                              374     359     -15
static.sp_256_mont_sub_8                              29       -     -29
static.sp_256_mont_dbl_8                              31       -     -31
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 0/3 up/down: 126/-90)            Total: 36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 01:11:48 +02:00
Denys Vlasenko 2430fcfd8d tls: optimize sp_256_mont_reduce_8 in P256
The code size decrease is small, but we eliminate ALL multiplies!

function                                             old     new   delta
sp_256_mont_reduce_8                                 268     262      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-06 00:24:03 +02:00
Denys Vlasenko bbd723ebec tls: optimize sp_256_mul_8 in P256
function                                             old     new   delta
sp_256_mont_mul_8                                    151     150      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 23:19:18 +02:00
Denys Vlasenko 3b411ebbfc tls: replace "26-bit" P256 code with 32-bit one.
function                                             old     new   delta
sp_256_ecc_mulmod_8                                    -    1171   +1171
sp_256_mod_mul_norm_8                                  -     834    +834
sp_256_proj_point_dbl_8                                -     374    +374
sp_256_mont_reduce_8                                   -     268    +268
sp_256_mont_mul_8                                      -     151    +151
sp_256_sub_8                                           -      76     +76
sp_256_add_8                                           -      76     +76
sp_256_cmp_8                                           -      38     +38
static.sp_256_mont_dbl_8                               -      31     +31
static.sp_256_mont_sub_8                               -      29     +29
sp_256_to_bin_8                                        -      28     +28
sp_256_point_from_bin2x32                             50      73     +23
sp_256_mont_sqr_8                                      -       7      +7
sp_256_mont_sqr_10                                     7       -      -7
p256_mod                                              40      32      -8
curve_P256_compute_pubkey_and_premaster              186     167     -19
sp_256_sub_10                                         22       -     -22
sp_256_add_10                                         22       -     -22
sp_256_cmp_10                                         24       -     -24
sp_256_norm_10                                        31       -     -31
static.sp_256_mont_sub_10                             49       -     -49
static.sp_256_mont_dbl_10                             52       -     -52
static.sp_256_mul_add_10                              82       -     -82
sp_256_from_bin_10                                   119       -    -119
sp_256_to_bin_10                                     120       -    -120
sp_256_mont_reduce_10                                178       -    -178
sp_256_mont_mul_10                                   214       -    -214
sp_256_proj_point_dbl_10                             451       -    -451
sp_256_ecc_mulmod_10                                1216       -   -1216
sp_256_mod_mul_norm_10                              1305       -   -1305
------------------------------------------------------------------------------
(add/remove: 12/15 grow/shrink: 1/2 up/down: 3106/-3919)     Total: -813 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 20:01:38 +02:00
Denys Vlasenko 55578f2fb7 tls: fix the case of sp_256_mont_tpl_10() leaving striay high bits
It has no effect on correctness, but interferes with compating internal state
of different implementations.

function                                             old     new   delta
sp_256_proj_point_dbl_10                             443     451      +8
static.sp_256_mont_sub_10                             46      49      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 19:46:39 +02:00
Denys Vlasenko 81d8af1970 tls: fix (what looks like) a rare corner case bug in P256
function                                             old     new   delta
static.sp_256_mont_sub_10                             30      46     +16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 17:31:33 +02:00
Denys Vlasenko 92402d5e0a tls: remove one overzealous debugging statement
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 14:01:52 +02:00
Denys Vlasenko 137864f559 tls: add debugging scaffolding to P256 code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 13:50:11 +02:00
Denys Vlasenko 389329efbe tls: another P256 code shrink
Propagate constant arrays and scalars deeper down call chain.
Use sp_256_mont_mul_10 to implement sp_256_mont_sqr_10.

function                                             old     new   delta
sp_256_mont_mul_10                                     -     214    +214
sp_256_mont_reduce_10                                  -     178    +178
sp_256_mont_sqr_10                                     -       7      +7
static.sp_256_mont_reduce_10                         178       -    -178
static.sp_256_mont_mul_10                            214       -    -214
static.sp_256_mont_sqr_10                            234       -    -234
------------------------------------------------------------------------------
(add/remove: 3/3 grow/shrink: 0/0 up/down: 399/-626)         Total: -227 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 13:39:33 +02:00
Denys Vlasenko e730505034 tls: P256 code shrink
function                                             old     new   delta
sp_256_to_bin_10                                       -     120    +120
sp_256_from_bin_10                                     -     119    +119
sp_256_proj_point_dbl_10                             446     443      -3
curve_P256_compute_pubkey_and_premaster              191     186      -5
sp_256_point_from_bin2x32                             62      50     -12
sp_256_to_bin                                        120       -    -120
static.sp_256_from_bin                               149       -    -149
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/3 up/down: 239/-289)          Total: -50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-05 13:32:04 +02:00
Denys Vlasenko 934bb01d51 tls: "server cert is not RSA" is a fatal error
function                                             old     new   delta
tls_handshake                                       2022    2019      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-01 22:03:09 +02:00
Ron Yorston ed9aa89269 wget: implement --post-file
Add the --post-file option to send form data from a file.  As with
--post-data it's up to the user to ensure that the data is encoded
as appropriate:  all wget does is stuff the provided data into
the request.

The --post-data and --post-file options are mutually exclusive and
only one instance of either may be given.

Additionally:

- update the usage message to include missing details of the --post-data
  and --header options;

- free POST data if FEATURE_CLEAN_UP is enabled.

function                                             old     new   delta
packed_usage                                       34158   34214     +56
wget_main                                           2762    2805     +43
.rodata                                            99225   99240     +15
static.wget_longopts                                 266     278     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 126/0)             Total: 126 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-01 14:55:18 +02:00
Denys Vlasenko 1f5a44d20c tls: add scaffolding to selectively disable ciphers. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-01 14:27:10 +02:00
Denys Vlasenko 7714518f1a tls: code shrink P256 code
function                                             old     new   delta
sp_256_to_bin                                        148     120     -28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-01 13:51:39 +02:00
Denys Vlasenko ac36e70074 tls: remove unused define
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-30 00:03:23 +02:00
Ismael Luceno 35727f5741 less: Ignore -X
The flag disables termcap init/deinit of the terminal, which the applet
doesn't do anyway.

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-28 23:22:47 +02:00
Denys Vlasenko 5b026d1ecf ash: fix compile breakage in !ENABLE_ASH_ALIAS config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-28 17:41:56 +02:00
Denys Vlasenko 03ed86b39e libbb: code shrink in main() and scripted_main()
function                                             old     new   delta
main                                                  68      65      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes
   text	   data	    bss	    dec	    hex	filename
   1472	    560	     16	   2048	    800	busybox_old
   1398	    552	     16	   1966	    7ae	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-28 17:40:59 +02:00
Denys Vlasenko 1be73dd9ad shell: fix parsing of $(( (v)++ + NUM ))
function                                             old     new   delta
evaluate_string                                      988    1011     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-26 13:29:25 +02:00
Denys Vlasenko 62e433131b shell: enable more tests which are passing now
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-25 22:35:17 +02:00
Denys Vlasenko d84a604830 shell: fix arithmentic evaluation of "++7" and such (it is + + 7, i.e. 7)
function                                             old     new   delta
evaluate_string                                      945     988     +43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-25 22:04:45 +02:00
Denys Vlasenko 627821e42b libbb/lineedit: tweak #if indenting, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-25 19:36:35 +02:00
Ron Yorston 56f0e886db cal: implement -m
Some people prefer the week to start on Monday.  Add the '-m'
option to support this.

function                                             old     new   delta
cal_main                                             926     966     +40
day_array                                            316     337     +21
packed_usage                                       34151   34158      +7
.rodata                                            99224   99225      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 69/0)               Total: 69 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-21 15:25:37 +02:00
Ron Yorston f27a6a94a7 libbb: code shrink parse_datestr (again)
Commit 9fe1548bb (date,touch: allow timezone offsets in dates)
mentioned the similarity between '@' format dates and those with
timezone offsets.  It didn't notice that as a result there's
common code which can be shared.

function                                             old     new   delta
parse_datestr                                        730     687     -43
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-43)             Total: -43 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-18 22:55:46 +02:00
Denys Vlasenko 6d2463ac01 libbb/lineedit: do not escape %^=+}]:, escape ~? in tab completion
function                                             old     new   delta
.rodata                                           104185  104180      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17 17:33:32 +02:00
Denys Vlasenko 6279aec03d libbb: clarify what bb_mode_string() generates
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17 17:10:38 +02:00
Ron Yorston 3a65435eaa libbb: ensure mode_string is NUL terminated
If the mode_string array is no longer static we can't rely on
it being NUL terminated.

function                                             old     new   delta
bb_mode_string                                       115     118      +3

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17 16:51:01 +02:00
Denys Vlasenko 59ac467dc6 libbb: eliminate a static data array in bb_mode_string()
function                                             old     new   delta
print_stat                                           861     869      +8
header_verbose_list_ar                                73      77      +4
display_single                                       975     979      +4
header_verbose_list                                  237     239      +2
bb_mode_string                                       124     115      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 18/-9)               Total: 9 bytes
   text	   data	    bss	    dec	    hex	filename
1043136	    559	   5052	1048747	 1000ab	busybox_old
1043153	    559	   5020	1048732	 10009c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17 01:18:31 +02:00
Denys Vlasenko 4958c18134 libbb: code shrink bb_parse_mode
function                                             old     new   delta
bb_parse_mode                                        393     398      +5
static.who_mask                                       16       8      -8
static.perm_mask                                      24      12     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 5/-20)             Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17 00:47:23 +02:00
Denys Vlasenko 2df4e0a370 chmod: correctly report changed modes
Chmod used to incorrectly report as changed even files for which the
mode did not change. This was caused by extra bits in the st_mode, that
were not present when parsed from passed argument in the form of octal
number.

Patch by Wolf <wolf@wolfsden.cz>.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17 00:39:21 +02:00
Ron Yorston 9fe1548bbf date,touch: allow timezone offsets in dates
Allow ISO 8601 style dates to include a timezone offset.  Like
the '@' format these dates aren't relative to the user's current
timezone and shouldn't be subject to DST adjustment.

- The implementation uses the strptime() '%z' format specifier.
  This an extension which may not be available so the use of
  timezones is a configuration option.

- The 'touch' applet has been updated to respect whether DST
  adjustment is required, matching 'date'.

function                                             old     new   delta
parse_datestr                                        624     730    +106
static.fmt_str                                       106     136     +30
touch_main                                           388     392      +4
date_main                                            818     819      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 141/0)             Total: 141 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-17 00:11:30 +02:00
Ron Yorston 83e20cb81c getopt: code shrink
function                                             old     new   delta
.rodata                                            99277   99290     +13
normalize                                            177     142     -35
getopt_main                                          675     622     -53
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 13/-88)            Total: -75 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-16 01:09:32 +02:00
Denys Vlasenko 704c596563 ash: introduce bash-like $FUNCNAME
Patch adapted from Roberto A. Foglietta <roberto.foglietta@gmail.com>
work.

function                                             old     new   delta
lookupvar                                            106     150     +44
evalfun                                              369     408     +39
ash_main                                            1218    1242     +24
varinit_data                                         156     168     +12
.rodata                                           104162  104172     +10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 129/0)             Total: 129 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-15 19:31:44 +02:00
Ron Yorston 3512ef8018 libbb: code shrink parse_datestr
The default build uses strptime() in parse_datestr() to support the
'month_name d HH:MM:SS YYYY' format of GNU date.  If we've linked
with strptime() there's an advantage is using it for other formats
too.

There's no change to the non-default, non-DESKTOP build.

function                                             old     new   delta
fmt_str                                                -     106    +106
.rodata                                            99216   99145     -71
parse_datestr                                        948     624    -324
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 106/-395)         Total: -289 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-15 08:09:45 +02:00
Ron Yorston 5726df5f94 ash: let ignoreeof only affect interactive shells
Commit fb7d6c89 from Harald van Dijk's gwsh variant of ash
(https://github.com/hvdijk/gwsh):

    ignoreeof is documented as only having an effect for interactive shells,
    but is implemented as having mostly the same effect for interactive
    shells as for non-interactive shells. Change the implementation to match
    the documentation.

    Test case:

      $SHELL -o ignoreeof /dev/null

function                                             old     new   delta
cmdloop                                              359     361      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 2/0)                 Total: 2 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-14 08:25:58 +02:00
Ron Yorston 50239a665c ash: stopped jobs should only prevent exit from interactive shell
When the user tries to exit an interactive shell with stopped jobs
present the shell issues a warning and only exits if the user
insists by trying to exit again.

This shouldn't apply to non-interactive shells.

Reported-by: Roberto A. Foglietta <roberto.foglietta@gmail.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-14 08:16:15 +02:00
Ron Yorston 0beee20977 ash: fix ignoreeof option
The ignoreeof option should prevent an interactive shell from
exiting on EOF.  This hasn't worked in BusyBox ash since commit
727752d2d (ash: better fix for ash -c 'echo 5&' and ash -c 'sleep 5&'
with testcase).

Commit 3b4d04b77e (ash: input: Allow two consecutive calls to pungetc)
pulled in improved support for multiple calls to pungetc from dash,
thus rendering much of commit 727752d2d obsolete.  Removing this old
code fixes the problem with ignoreeof.

function                                             old     new   delta
__pgetc                                              605     587     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-14 08:16:15 +02:00
Denys Vlasenko 9346ea9550 df: "support" -H as an alias of -h
function                                             old     new   delta
df_main                                             1065    1068      +3
.rodata                                           104232  104233      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 4/0)                 Total: 4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-11 00:47:03 +02:00
Denys Vlasenko 40f2dd7dd2 httpd: fix config deps
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-10 10:07:42 +02:00
Denys Vlasenko c00bcf2d2c libbb: reuse "bad port" error message string
function                                             old     new   delta
.rodata                                           104251  104232     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-10 09:48:55 +02:00
Denys Vlasenko c421388dca blkdiscard: accept -f (force) as no-op
function                                             old     new   delta
.rodata                                           104250  104251      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-10 00:20:05 +02:00
Denys Vlasenko 0599e0f87b basename: implement -a and -s SUFFIX
function                                             old     new   delta
basename_main                                        145     207     +62
packed_usage                                       33914   33950     +36
.rodata                                           104241  104250      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 107/0)             Total: 107 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 23:45:13 +02:00
Denys Vlasenko 7ab9cd2398 libbb: make bb_lookup_port() abort on bad port names
Also, no need to preserve errno

function                                             old     new   delta
.rodata                                           104247  104241      -6
bb_lookup_port                                        97      83     -14
nc_main                                             1039    1018     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-41)             Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 22:00:44 +02:00
Sergey Ponomarev 82c5eb8e46 httpd,telnetd: make default port configurable
BusyBox on Termux can't use ports less than 1024 it's patched to change default port for httpd to 8080 and telnetd to 8023.

https://github.com/termux/termux-packages/blob/master/packages/busybox/0011-networking-telnetd-default-port.patch
https://github.com/termux/termux-packages/blob/master/packages/busybox/0010-networking-httpd-default-port.patch

To avoid such patches we can make port configurable.

function                                             old     new   delta
packed_usage                                       33920   33914      -6

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 21:42:48 +02:00
Denys Vlasenko 857800c655 awk: never return NULL from awk_printf()
function                                             old     new   delta
awk_printf                                           651     628     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 19:26:39 +02:00
Denys Vlasenko e60c56932e awk: code shrink
function                                             old     new   delta
awk_printf                                           652     651      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 19:13:32 +02:00
Denys Vlasenko 8a0adba9f6 awk: code shrink: avoid duplicate NUL checks and strlen()
function                                             old     new   delta
awk_printf                                           665     652     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 18:58:39 +02:00
Ron Yorston 305a30d80b awk: fix read beyond end of buffer
Commit 7d06d6e18 (awk: fix printf %%) can cause awk printf to read
beyond the end of a strduped buffer:

  2349      while (*f && *f != '%')
  2350          f++;
  2351      c = *++f;

If the loop terminates because a NUL character is detected the
character after the NUL is read.  This can result in failures
depending on the value of that character.

function                                             old     new   delta
awk_printf                                           672     665      -7

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 18:12:21 +02:00
Denys Vlasenko eb60777769 ash: eval: Prevent recursive PS4 expansion
Date: Wed, 27 May 2020 13:19:10 +1000
eval: Prevent recursive PS4 expansion

    Yaroslav Halchenko <yoh@onerussian.com> wrote:
    > I like to (ab)use PS4 and set -x for tracing execution of scripts.
    > Reporting time and PID is very useful in this context.
    >
    > I am not 100% certain if bash's behavior (of actually running the command
    > embedded within PS4 string, probably eval'ing it) is actually POSIX
    > compliant, posh seems to not do that; but I think it is definitely not
    > desired for dash to just stall:
    >
    > - the script:
    > #!/bin/sh
    > set -x
    > export PS4='+ $(date +%T.%N) [$$] '
    > echo "lets go"
    > sleep 1
    > echo "done $var"
    >
    > - bash:
    > /tmp > bash --posix test.sh
    > +export 'PS4=+ $(date +%T.%N) [$$] '
    > +PS4='+ $(date +%T.%N) [$$] '
    > + 09:15:48.982296333 [2764323] echo 'lets go'
    > lets go
    > + 09:15:48.987829613 [2764323] sleep 1
    > + 09:15:49.994485037 [2764323] echo 'done '
    > done
    >
    ...
    > - dash: (stalls it set -x)
    > /tmp > dash test.sh
    > +export PS4=+ $(date +%T.%N) [$$]
    > ^C^C

    This patch fixes the infinite loop caused by repeated expansions
    of PS4.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-09 16:29:37 +02:00
Denys Vlasenko 48cb983b13 ash: parser: Get rid of PEOA
Upstream commit:

    Date: Wed, 27 May 2020 12:19:13 +1000
    parser: Get rid of PEOA

    PEOA is a special character used to mark an alias as being finished
    so that we don't enter an infinite loop with nested aliases.  It
    complicates the parser because we have to ensure that it is skipped
    where necessary and not copied to the resulting token text.

    This patch removes it and instead delays the marking of aliases
    until the second pgetc.  This has the same effect as the current
    PEOA code while keeping the complexities within the input code.

This adds ~32 bytes of global data:

function                                             old     new   delta
__pgetc                                                -     512    +512
freestrings                                            -      95     +95
popfile                                               86     110     +24
pushstring                                           141     160     +19
basepf                                                76      84      +8
syntax_index_table                                   258     257      -1
S_I_T                                                 30      28      -2
.rodata                                           104255  104247      -8
pgetc_without_PEOA                                    13       -     -13
xxreadtoken                                          230     215     -15
popstring                                            158     120     -38
readtoken1                                          3110    3045     -65
pgetc                                                547      22    -525
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/7 up/down: 658/-667)           Total: -9 bytes
   text	   data	    bss	    dec	    hex	filename
1043102	    559	   5020	1048681	 100069	busybox_old
1043085	    559	   5052	1048696	 100078	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-08 09:52:04 +02:00
Denys Vlasenko 8c68ae8416 ash: parser: Fix alias expansion after heredoc or newlines
Upstream commit:

    Date: Wed, 29 Apr 2020 00:19:59 +1000
    parser: Fix alias expansion after heredoc or newlines

    This script should print OK:

        alias a="case x in " b=x
        a
        b) echo BAD;; esac

        alias BEGIN={ END=}
        BEGIN
    	cat <<- EOF > /dev/null
    		$(:)
    	EOF
        END
        : <<- EOF &&
    		$(:)
        EOF
        BEGIN
    	echo OK
        END

    However, because the value of checkkwd is either zeroed when it
    shouldn't, or isn't zeroed when it should, dash currently gets
    it wrong in every case.

    This patch fixes it by saving checkkwd and zeroing it where needed.

function                                             old     new   delta
readtoken                                            157     176     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-08 01:43:12 +02:00
Denys Vlasenko c540256127 ash: use pgetc_eatbnl() in more places, take 3
Adding previously skipped "readtoken1(pgetc_eatbnl(), syntax_type..." change
from upstream commit:

    Date:   Thu Mar 8 08:37:11 2018 +0100
    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.

Testcase:
	PS1='\
	:::'
should result in ::: prompt, not <newline>::: prompt

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-08 01:13:40 +02:00
Denys Vlasenko 1c06ddd8bb ash: parser: Save and restore heredoclist in expandstr
Upstream commit:

    Date: Sun, 17 May 2020 23:36:25 +1000
    parser: Save and restore heredoclist in expandstr

    On Sun, May 17, 2020 at 01:19:28PM +0100, Harald van Dijk wrote:
    > This still does not restore the state completely. It does not clean up any
    > pending heredocs. I see:
    >
    >   $ PS1='$(<<EOF "'
    >   src/dash: 1: Syntax error: Unterminated quoted string
    >   $(<<EOF ":
    >   >
    >
    > That is, after entering the ':' command, the shell is still trying to read
    > the heredoc from the prompt.

    This patch saves and restores the heredoclist in expandstr.

    It also removes a bunch of unnecessary volatiles as those variables
    are only referenced in case of a longjmp other than one started by
    a signal like SIGINT.

function                                             old     new   delta
expandstr                                            268     255     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-08 00:56:53 +02:00
Denys Vlasenko 30af5938af ash: parser: Fix handling of empty aliases
Upstream commit:

    Date: Tue, 28 Apr 2020 01:15:26 +1000
    parser: Fix handling of empty aliases

    Dash was incorrectly handling empty aliases. When attempting to use an
    empty alias with nothing else, I'm (incorrectly) prompted for more
    input:

    ```
    $ alias empty=''
    $ empty
    >
    ```

    Other shells (e.g., bash, yash) correctly handle the lone, empty alias as an
    empty command:

    ```
    $ alias empty=''
    $ empty
    $
    ```

    The problem here is that we incorrectly enter the loop eating TNLs
    in readtoken().  This patch fixes it by setting checkkwd correctly.

function                                             old     new   delta
list                                                 351     355      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-08 00:39:16 +02:00
Denys Vlasenko 6a9b3f7acf shuf: add a TODO, code shrink
function                                             old     new   delta
shuf_main                                            501     500      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 22:51:42 +02:00
Denys Vlasenko 574b9c446d hush: fix var_LINENO3.tests failure
function                                             old     new   delta
parse_and_run_string                                  40      62     +22
i_getch                                              105     102      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 22/-3)              Total: 19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 21:44:44 +02:00
Denys Vlasenko bcff3a7b5a shell/ash_test/run-all: unset locale/language variables
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 18:24:08 +02:00
Denys Vlasenko 64aa86b720 ash: LINENO starts from 0 in -c SCRIPT mode
The var_LINENO3.tests fails for hush: it does start from 0, but does not increment.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 18:16:45 +02:00
Denys Vlasenko d6c9cbc072 ash: fix LINENO in functions
From larger patch by Roberto A. Foglietta <roberto.foglietta@gmail.com>

function                                             old     new   delta
evalfun                                              348     369     +21
ash_main                                            1202    1218     +16
setinputstring                                        65      73      +8
lookupvar                                            116     106     -10
evaltree                                             772     753     -19
evalsubshell                                         192     173     -19
evalfor                                              175     156     -19
evalcase                                             273     254     -19
evalcommand                                         1560    1536     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/6 up/down: 45/-110)           Total: -65 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 18:01:49 +02:00
Denys Vlasenko 0d7dfa9012 ash: support testsuite for !FEATURE_SUID_CONFIG_QUIET configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 17:34:58 +02:00
Denys Vlasenko e53c7dbafc hush: fix set -n to act immediately, not just after run_list()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 02:25:52 +02:00
Denys Vlasenko f415e21a7d ash: eval: Do not cache value of eflag in evaltree
Upsteam commit:

    Date: Mon, 17 May 2021 15:19:23 +0800
    eval: Do not cache value of eflag in evaltree

    Patrick Brünn <P.Bruenn@beckhoff.com> wrote:
    > Since we are migrating to Debian bullseye, we discovered a new behavior
    > with our scripts, which look like this:
    >>cleanup() {
    >>        set +e
    >>        rmdir ""
    >>}
    >>set -eu
    >>trap 'cleanup' EXIT INT TERM
    >>echo 'Hello world!'
    >
    > With old dash v0.5.10.2 this script would return 0 as we expected it.
    > But since commit 62cf6955f8abe875752d7163f6f3adbc7e49ebae it returns
    > the last exit code of our cleanup function.
    ...
    Thanks for the report.  This is actually a fairly old bug with
    set -e that's just been exposed by the exit status change.  What's
    really happening is that cleanup itself is triggering a set -e
    exit incorrectly because evaltree cached the value of eflag prior
    to the function call.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 02:01:03 +02:00
Denys Vlasenko 41beb53787 ash: eval: Check nflag in evaltree instead of cmdloop
Upstream commit:

    Date: Thu, 4 Jun 2020 21:53:55 +1000
    eval: Check nflag in evaltree instead of cmdloop

    This patch moves the nflag check from cmdloop into evaltree.  This
    is so that nflag will be in force even if we enter the shell via a
    path other than cmdloop, e.g., through sh -c.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 01:52:21 +02:00
Roberto A. Foglietta e0bf3df020 ash: add bash-like ERR trap and set -E
While at it, stop incrementing LINENO inside traps

function                                             old     new   delta
evaltree                                             567     762    +195
evalfun                                              268     348     +80
trapcmd                                              286     333     +47
dotrap                                               129     157     +28
exitshell                                            120     139     +19
readtoken1                                          3096    3110     +14
nlprompt                                              25      39     +14
nlnoprompt                                            19      33     +14
.rodata                                           104245  104255     +10
forkchild                                            610     617      +7
optletters_optnames                                   64      68      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 11/0 up/down: 432/0)            Total: 432 bytes

Signed-off-by: Roberto A. Foglietta <roberto.foglietta@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07 01:28:50 +02:00
Denys Vlasenko 4b032a4d6c chat: hopefully fix infinite spinning on input EOF
function                                             old     new   delta
chat_main                                           1295    1303      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-06 17:38:18 +02:00
Daniel Thau 7d06d6e186 awk: fix printf %%
A refactor of the awk printf code in
e2e3802987
appears to have broken the printf interpretation of two percent signs,
which normally outputs only one percent sign.

The patch below brings busybox awk printf behavior back into alignment
with the pre-e2e380 behavior, the busybox printf util, and other common
(awk and non-awk) printf implementations.

function                                             old     new   delta
awk_printf                                           626     672     +46

Signed-off-by: Daniel Thau <danthau at bedrocklinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-05 03:42:51 +02:00
Denys Vlasenko f4ba69d476 shuf: make -i 99999999990-100000000000 work even on 32 bits
function                                             old     new   delta
shuf_main                                            443     501     +58
.rodata                                           104238  104245      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 65/0)               Total: 65 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-04 17:00:22 +02:00
Denys Vlasenko 8aa626ffff udhcp: add comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-04 01:50:42 +02:00
Denys Vlasenko d7e39f26d7 examples/var_service/fw/run: allow extif's to be more than one iface
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-02 23:53:48 +02:00
Ron Yorston 4a36ef11ac ash: regressions in process substitution
Stacy Harper reports that this script:

   test() { . /tmp/bb_test; }
   echo "export TEST=foo" >/tmp/bb_test
   test 2>/dev/null
   echo "$TEST"

correctly prints 'foo' in BusyBox 1.33 but hangs in 1.34.

Bisection suggested the problem was caused by commit a1b0d3856 (ash: add
process substitution in bash-compatibility mode).  Removing the call to
unwindredir() in cmdloop() introduced in that commit makes the script
work again.

Additionally, these examples of process substitution:

   while true; do cat <(echo hi); done
   f() { while true; do cat <(echo hi); done }
   f

result in running out of file descriptors.  This is a regression from
v5 of the process substitution patch caused by changes to evalcommand()
not being transferred to v6.

function                                             old     new   delta
static.pushredir                                       -      99     +99
evalcommand                                         1729    1750     +21
exitreset                                             69      86     +17
cmdloop                                              372     365      -7
unwindredir                                           28       -     -28
pushredir                                            112       -    -112
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 2/1 up/down: 137/-147)          Total: -10 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-02 17:49:00 +02:00
Denys Vlasenko f02691939e dhcprelay: change two more variables to unsigned
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-02 17:09:12 +02:00
Denys Vlasenko 3f2d969db9 udhcp: clarify aspects of relay operation, add TODOs and FIXMEs, tweak --help
function                                             old     new   delta
packed_usage                                       33891   33920     +29
dhcprelay_main                                       943     926     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 29/-17)             Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-02 16:24:52 +02:00
Denys Vlasenko 62d0c8e028 udhcpd: check config file for bad IP ranges (start > end)
function                                             old     new   delta
.rodata                                           104209  104238     +29
read_config                                          208     225     +17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 46/0)               Total: 46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-02 14:40:54 +02:00
Denys Vlasenko d99dee944e udhcpd: update --help to include -a MSEC
function                                             old     new   delta
packed_usage                                       33886   33891      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-02 14:02:23 +02:00
Ron Yorston a51d953b95 vi: further changes to colon addresses
Improved error messages:

- specify when a search fails or a mark isn't set;
- warn when line addresses are out of range or when a range of
  lines is reversed.

Addresses are limited to the number of lines in the file so a
command like ':2000000000' (go to the two billionth line) no
longer causes a long pause.

Improved vi compatibility of '+' and '-' operators that aren't
followed immediately by a number:

   :4+++=       7
   :3-2=        1
   :3 - 2=      4 (yes, really!)

In a command like ':,$' the empty address before the separator now
correctly refers to the current line.  (The similar case ':1,' was
already being handled.)

And all with a tidy reduction in bloat (32-bit build):

function                                             old     new   delta
colon                                               4029    4069     +40
.rodata                                            99348   99253     -95
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 40/-95)            Total: -55 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-29 20:07:20 +02:00
Denys Vlasenko 6d3da732a5 bzip: make ftab[] and crc32table[] member arrays of EState, do not allocate
function                                             old     new   delta
mainSort                                             941     986     +45
fallbackSort                                        1471    1469      -2
add_pair_to_block                                    194     188      -6
compressStream                                       543     515     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 45/-36)              Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-29 15:32:42 +02:00
Denys Vlasenko 49a2e484b5 shuf: in -i RANGE, accept numbers up to width of pointers
function                                             old     new   delta
.rodata                                           108468  108474      +6
shuf_main                                            555     542     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-29 14:39:01 +02:00
Denys Vlasenko 60f4843468 shuf: with -i LOW-HIGH, do not allow any argv's
function                                             old     new   delta
shuf_main                                            436     441      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-23 15:52:34 +02:00
Denys Vlasenko d59f539d57 shuf: tweak --help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-23 15:48:22 +02:00
Denys Vlasenko 1b661122a8 mount: code shrink
function                                             old     new   delta
append_mount_options                                 174     157     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-23 02:31:26 +02:00
Denys Vlasenko dbdf9e0ab1 mount: with -w, do not fall back to read-only mounts
function                                             old     new   delta
mount_it_now                                         364     358      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-23 02:30:13 +02:00
Ron Yorston 922b58b3e4 tar,smemcap: silence compiler warning
gcc 11.2.1 complains that the tar header checksum might overflow
the checksum field.  It won't and using an unsigned int for the
calculation seems to convince the compiler too.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 15:44:57 +02:00
Denys Vlasenko 1e7ca18591 Regularize "NUL terminated input" --help texts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 15:43:29 +02:00
Ron Yorston 8817e285b7 shuf: speed-up when limited output is requested
A user noted that the following command was slower than they
expected:

   busybox shuf -i "1500000000-$(date +%s)" -n 5

At time of writing the range contains 128 million values.  On my
system this takes 7.7s whereas 'shuf' from coreutils takes a
handful of milliseconds.

Optimise BusyBox 'shuf' for cases where -n is specified by stopping
shuffling once the required number of lines have been processed.
On my system the time for the example is reduced to 0.4s.

function                                             old     new   delta
shuf_main                                            520     540     +20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 20/0)               Total: 20 bytes

v2: Code shrink.  Since outlines <= numlines:
    - the loop in shuffle_lines() only needs to test the value of
      outlines;
    - shuffle_lines() can be called unconditionally.
    Update timing to allow for the 13 million seconds elapsed since v1.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 15:40:21 +02:00
Ron Yorston 74c4f356ae vi: code shrink print_literal()
Simplify the function print_literal() which is used to format a
string that may contain unprintable characters or control
characters.

- Unprintable characters were being displayed in normal text rather
  than the bold used for the rest of the message.  This doesn't seem
  particularly helpful and it upsets the calculation of the width
  of the message in show_status_line().  Use '?' rather than '.' for
  unprintable characters.

- Newlines in the string were displayed as both '^J' and '$', which
  is somewhat redundant.

function                                             old     new   delta
not_implemented                                      199     108     -91
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-91)             Total: -91 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 00:09:57 +02:00
Ron Yorston 08ad934ac4 vi: searches in colon commands should wrap
The '/' and '?' search commands wrap to the other end of the buffer
if the search target isn't found.  When searches are used to specify
addresses in colon commands they should do the same.

(In traditional vi and vim this behaviour is controlled by the
'wrapscan' option.  BusyBox vi doesn't have this option and always
uses the default behaviour.)

function                                             old     new   delta
colon                                               4033    4077     +44
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 44/0)               Total: 44 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 00:09:57 +02:00
Ron Yorston 4357569fdc rev: correct output for long input lines
The input buffer is initialised to a reasonable size and extended
if necessary.  When this happened the offset into the buffer wasn't
reset to zero so subsequent lines were appended to the long line.

Fix this and add some tests.

function                                             old     new   delta
rev_main                                             377     368      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-9)               Total: -9 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 00:08:18 +02:00
Denys Vlasenko 62d5a1e56f tar,smemcap: commonalyze checksumming code for tar header
function                                             old     new   delta
chksum_and_xwrite_tar_header                           -      99     +99
writeheader                                          280     199     -81
chksum_and_xwrite                                    102       -    -102
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 0/1 up/down: 99/-183)           Total: -84 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-20 17:58:49 +02:00
Ron Yorston 38e9c8c95b vi: don't right shift empty lines
The right shift command ('>') shouldn't affect empty lines.

function                                             old     new   delta
do_cmd                                              4860    4894     +34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 34/0)               Total: 34 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-20 15:26:09 +02:00
Ron Yorston f9217cd235 vi: support ~/.exrc
Run initialisation commands from ~/.exrc.  As with EXINIT these
commands are processed before the first file is loaded.

Commands starting with double quotes are ignored.  This is how
comments are often included in .exrc.

function                                             old     new   delta
vi_main                                              268     406    +138
colon                                               4033    4071     +38
.rodata                                           108411  108442     +31
packed_usage                                       34128   34118     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 207/-10)           Total: 197 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-20 15:26:09 +02:00
Ron Yorston f07772f19e vi: changes to handling of -c and EXINIT
Rewrite handling of command line arguments so any number of -c
commands will be processed.  Previously only two -c commands
were allowed (or one if EXINIT was set).

Process commands from EXINIT before the first file is read into
memory, as specified by POSIX.

function                                             old     new   delta
run_cmds                                               -      77     +77
.rodata                                           108410  108411      +1
vi_main                                              305     268     -37
edit_file                                            816     764     -52
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 78/-89)            Total: -11 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-20 15:26:09 +02:00
Denys Vlasenko 29b53ef03f udhcp: fix build breakage on MIPS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-20 13:38:16 +02:00
Denys Vlasenko 9d286a0a55 Start 1.35.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-19 15:06:57 +02:00
594 changed files with 15427 additions and 5521 deletions

View File

@ -181,3 +181,6 @@ Jie Zhang <jie.zhang@analog.com>
Maxime Coste <mawww@kakoune.org>
paste implementation
Roger Knecht <rknecht@pm.me>
tree

View File

@ -108,6 +108,17 @@ config LFS
programs that can benefit from large file support include dd, gzip,
cp, mount, tar.
config TIME64
bool "Support 64bit wide time types"
default y
depends on LFS
help
Make times later than 2038 representable for several libc syscalls
(stat, clk_gettime etc.). Note this switch is specific to glibc
and has no effect on platforms that already use 64bit wide time types
(i.e. all 64bit archs and some selected 32bit archs (currently riscv
and x32)).
config PAM
bool "Support PAM (Pluggable Authentication Modules)"
default n

View File

@ -1,7 +1,7 @@
VERSION = 1
PATCHLEVEL = 34
PATCHLEVEL = 37
SUBLEVEL = 0
EXTRAVERSION =
EXTRAVERSION = .git
NAME = Unnamed
# *DOCUMENTATION*
@ -967,6 +967,7 @@ endif # CONFIG_MODULES
# Directories & files removed with 'make clean'
CLEAN_DIRS += $(MODVERDIR) _install 0_lib
CLEAN_FILES += busybox busybox_unstripped* busybox.links \
busybox*.suid busybox*.nosuid \
System.map .kernelrelease \
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
@ -1301,14 +1302,6 @@ quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
cmd_rmfiles = rm -f $(rm-files)
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
$(NOSTDINC_FLAGS) $(CPPFLAGS) \
$(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
quiet_cmd_as_o_S = AS $@
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
# read all saved command lines
targets := $(wildcard $(sort $(targets)))

View File

@ -15,6 +15,7 @@ CPPFLAGS += \
-include include/autoconf.h \
-D_GNU_SOURCE -DNDEBUG \
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
$(if $(CONFIG_TIME64),-D_TIME_BITS=64) \
-DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote)
CFLAGS += $(call cc-option,-Wall,)
@ -47,7 +48,7 @@ endif
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
ifneq ($(CC),clang)
ifneq ($(lastword $(subst -, ,$(CC))),clang)
# "clang-9: warning: optimization flag '-finline-limit=0' is not supported
CFLAGS += $(call cc-option,-finline-limit=0,)
endif
@ -65,7 +66,7 @@ CFLAGS += $(call cc-option,-static-libgcc,)
endif
CFLAGS += $(call cc-option,-falign-functions=1,)
ifneq ($(CC),clang)
ifneq ($(lastword $(subst -, ,$(CC))),clang)
# "clang-9: warning: optimization flag '-falign-jumps=1' is not supported" (and same for other two)
CFLAGS += $(call cc-option,-falign-jumps=1 -falign-labels=1 -falign-loops=1,)
endif
@ -78,7 +79,7 @@ CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
CFLAGS += $(call cc-option,-fno-builtin-printf,)
# clang-9 does not like "str" + N and "if (CONFIG_ITEM && cond)" constructs
ifeq ($(CC),clang)
ifeq ($(lastword $(subst -, ,$(CC))),clang)
CFLAGS += $(call cc-option,-Wno-string-plus-int -Wno-constant-logical-operand)
endif
@ -87,14 +88,14 @@ endif
#CFLAGS += $(call cc-option,-Wconversion,)
ifneq ($(CONFIG_DEBUG),y)
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
else
CFLAGS += $(call cc-option,-g,)
#CFLAGS += "-D_FORTIFY_SOURCE=2"
ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
CFLAGS += $(call cc-option,-O0,)
else
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
endif
endif
ifeq ($(CONFIG_DEBUG_SANITIZE),y)
@ -151,8 +152,8 @@ LDLIBS += m
# gcc-4.2.1 fails if we try to feed C source on stdin:
# echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
# fall back to using a temp file:
CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
RT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) -lrt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lcrypt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
RT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lrt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
ifeq ($(CRYPT_AVAILABLE),y)
LDLIBS += crypt
endif
@ -187,6 +188,9 @@ ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
ifneq (,$(findstring linux,$(shell $(CC) $(CFLAGS) -dumpmachine)))
LDLIBS += resolv
endif
ifneq (,$(findstring gnu,$(shell $(CC) $(CFLAGS) -dumpmachine)))
LDLIBS += resolv
endif
endif
ifeq ($(CONFIG_EFENCE),y)

2
TODO
View File

@ -222,8 +222,6 @@ Minor stuff:
---
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
---
support start-stop-daemon -d <chdir-path>
---
(TODO list after discussion 11.05.2009)

View File

@ -20,5 +20,5 @@ int main(int argc, char **argv)
void bb_show_usage(void)
{
fputs_stdout(APPLET_full_usage "\n");
exit(EXIT_FAILURE);
exit_FAILURE();
}

View File

@ -196,9 +196,10 @@ static int write_ar_archive(archive_handle_t *handle)
static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
{
const char *mode = bb_mode_string(file_header->mode);
char mode[12];
char *mtime;
bb_mode_string(mode, file_header->mode);
mtime = ctime(&file_header->mtime);
mtime[16] = ' ';
memmove(&mtime[17], &mtime[20], 4);

View File

@ -415,7 +415,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config BUNZIP2
//config: bool "bunzip2 (8.7 kb)"
//config: bool "bunzip2 (9.1 kb)"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
@ -429,7 +429,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//config: should probably say N here.
//config:
//config:config BZCAT
//config: bool "bzcat (8.7 kb)"
//config: bool "bzcat (9 kb)"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
@ -485,7 +485,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config UNLZMA
//config: bool "unlzma (7.5 kb)"
//config: bool "unlzma (7.8 kb)"
//config: default y
//config: help
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
@ -494,7 +494,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//config: compressors.
//config:
//config:config LZCAT
//config: bool "lzcat (7.5 kb)"
//config: bool "lzcat (7.8 kb)"
//config: default y
//config: help
//config: Alias to "unlzma -c".

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2021 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//kbuild:lib-$(CONFIG_FEATURE_TAR_CREATE) += chksum_and_xwrite_tar_header.o
//kbuild:lib-$(CONFIG_SMEMCAP) += chksum_and_xwrite_tar_header.o
#include "libbb.h"
#include "bb_archive.h"
void FAST_FUNC chksum_and_xwrite_tar_header(int fd, struct tar_header_t *hp)
{
/* POSIX says that checksum is done on unsigned bytes
* (Sun and HP-UX gets it wrong... more details in
* GNU tar source) */
const unsigned char *cp;
unsigned int chksum, size;
strcpy(hp->magic, "ustar ");
/* Calculate and store the checksum (the sum of all of the bytes of
* the header). The checksum field must be filled with blanks for the
* calculation. The checksum field is formatted differently from the
* other fields: it has 6 digits, a NUL, then a space -- rather than
* digits, followed by a NUL like the other fields... */
memset(hp->chksum, ' ', sizeof(hp->chksum));
cp = (const unsigned char *) hp;
chksum = 0;
size = sizeof(*hp);
do { chksum += *cp++; } while (--size);
sprintf(hp->chksum, "%06o", chksum);
xwrite(fd, hp, sizeof(*hp));
}

View File

@ -38,6 +38,20 @@
//config: depends on FEATURE_CPIO_O
//config: help
//config: Passthrough mode. Rarely used.
//config:
//config:config FEATURE_CPIO_IGNORE_DEVNO
//config: bool "Support --ignore-devno like GNU cpio"
//config: default y
//config: depends on FEATURE_CPIO_O && LONG_OPTS
//config: help
//config: Optionally ignore device numbers when creating archives.
//config:
//config:config FEATURE_CPIO_RENUMBER_INODES
//config: bool "Support --renumber-inodes like GNU cpio"
//config: default y
//config: depends on FEATURE_CPIO_O && LONG_OPTS
//config: help
//config: Optionally renumber inodes when creating archives.
//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
@ -48,7 +62,7 @@
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
//usage: " [EXTR_FILE]..."
//usage:#define cpio_full_usage "\n\n"
//usage: "Extract (-i) or list (-t) files from a cpio archive"
//usage: "Extract (-i) or list (-t) files from a cpio archive on stdin"
//usage: IF_FEATURE_CPIO_O(", or"
//usage: "\ntake file list from stdin and create an archive (-o)"
//usage: IF_FEATURE_CPIO_P(" or copy files (-p)")
@ -74,7 +88,13 @@
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
//usage: "\n -R USER[:GRP] Set owner of created files"
//usage: "\n -L Dereference symlinks"
//usage: "\n -0 Input is separated by NULs"
//usage: "\n -0 NUL terminated input"
//usage: IF_FEATURE_CPIO_IGNORE_DEVNO(
//usage: "\n --ignore-devno"
//usage: )
//usage: IF_FEATURE_CPIO_RENUMBER_INODES(
//usage: "\n --renumber-inodes"
//usage: )
/* GNU cpio 2.9 --help (abridged):
@ -162,17 +182,22 @@ enum {
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
IF_LONG_OPTS( OPTBIT_QUIET ,)
IF_LONG_OPTS( OPTBIT_2STDOUT ,)
IF_FEATURE_CPIO_IGNORE_DEVNO(OPTBIT_IGNORE_DEVNO,)
IF_FEATURE_CPIO_RENUMBER_INODES(OPTBIT_RENUMBER_INODES,)
OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
OPT_IGNORE_DEVNO = IF_FEATURE_CPIO_IGNORE_DEVNO((1 << OPTBIT_IGNORE_DEVNO)) + 0,
OPT_RENUMBER_INODES = IF_FEATURE_CPIO_RENUMBER_INODES((1 << OPTBIT_RENUMBER_INODES)) + 0,
};
#define OPTION_STR "it0uvdmLF:R:"
struct globals {
struct bb_uidgid_t owner_ugid;
ino_t next_inode;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
void BUG_cpio_globals_too_big(void);
@ -206,6 +231,9 @@ static NOINLINE int cpio_o(void)
struct inodes_s *next;
struct name_s *names;
struct stat st;
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
ino_t mapped_inode;
#endif
};
struct inodes_s *links = NULL;
@ -260,6 +288,10 @@ static NOINLINE int cpio_o(void)
l = xzalloc(sizeof(*l));
l->st = st;
l->next = links;
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
if (option_mask32 & OPT_RENUMBER_INODES)
l->mapped_inode = ++G.next_inode;
#endif
links = l;
break;
}
@ -278,6 +310,11 @@ static NOINLINE int cpio_o(void)
free(line);
continue;
}
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
else if (option_mask32 & OPT_RENUMBER_INODES) {
st.st_ino = ++G.next_inode;
}
#endif
} else { /* line == NULL: EOF */
next_link:
if (links) {
@ -285,6 +322,10 @@ static NOINLINE int cpio_o(void)
st = links->st;
name = links->names->name;
links->names = links->names->next;
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
if (links->mapped_inode)
st.st_ino = links->mapped_inode;
#endif
/* GNU cpio is reported to emit file data
* only for the last instance. Mimic that. */
if (links->names == NULL)
@ -304,6 +345,11 @@ static NOINLINE int cpio_o(void)
}
}
#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
if (option_mask32 & OPT_IGNORE_DEVNO)
st.st_dev = st.st_rdev = 0;
#endif
bytes += printf("070701"
"%08X%08X%08X%08X%08X%08X%08X"
"%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
@ -379,6 +425,12 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
"null\0" No_argument "0"
"quiet\0" No_argument "\xff"
"to-stdout\0" No_argument "\xfe"
#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
"ignore-devno\0" No_argument "\xfd"
#endif
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
"renumber-inodes\0" No_argument "\xfc"
#endif
;
#endif
@ -452,7 +504,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
goto dump;
}
/* parent */
USE_FOR_NOMMU(argv[-optind][0] &= 0x7f); /* undo fork_or_rexec() damage */
xchdir(*argv++);
close(pp.wr);
xmove_fd(pp.rd, STDIN_FILENO);

View File

@ -1115,7 +1115,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
if (package_edge->type == EDGE_PRE_DEPENDS
|| package_edge->type == EDGE_DEPENDS
) {
int result=1;
int result = 1;
status_num = 0;
/* If we are inside an alternative then check

View File

@ -5,7 +5,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DPKG_DEB
//config: bool "dpkg-deb (30 kb)"
//config: bool "dpkg-deb (29 kb)"
//config: default y
//config: select FEATURE_SEAMLESS_GZ
//config: help

View File

@ -107,7 +107,7 @@ void fallbackSimpleSort(uint32_t* fmap,
#define FALLBACK_QSORT_SMALL_THRESH 10
#define FALLBACK_QSORT_STACK_SIZE 100
static
static NOINLINE
void fallbackQSort3(uint32_t* fmap,
uint32_t* eclass,
int32_t loSt,

View File

@ -99,9 +99,8 @@ void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
s->ptr = (uint32_t*)s->arr1;
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
s->block = (uint8_t*)s->arr2;
s->ftab = xmalloc(65537 * sizeof(uint32_t));
s->crc32table = crc32_filltable(NULL, 1);
crc32_filltable(s->crc32table, 1);
s->state = BZ_S_INPUT;
s->mode = BZ_M_RUNNING;
@ -369,8 +368,8 @@ void BZ2_bzCompressEnd(bz_stream *strm)
s = strm->state;
free(s->arr1);
free(s->arr2);
free(s->ftab);
free(s->crc32table);
//free(s->ftab); // made it array member of s
//free(s->crc32table); // ditto
free(s);
}

View File

@ -134,7 +134,7 @@ typedef struct EState {
/* for doing the block sorting */
uint32_t *arr1;
uint32_t *arr2;
uint32_t *ftab;
//uint32_t *ftab; //moved into this struct, see below
uint16_t *quadrant;
int32_t budget;
@ -160,9 +160,6 @@ typedef struct EState {
uint32_t bsBuff;
int32_t bsLive;
/* guess what */
uint32_t *crc32table;
/* block and combined CRCs */
uint32_t blockCRC;
uint32_t combinedCRC;
@ -185,6 +182,12 @@ typedef struct EState {
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
/* guess what */
uint32_t crc32table[256];
/* for doing the block sorting */
uint32_t ftab[65537];
/* stack-saving measures: these can be local, but they are too big */
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];

View File

@ -654,7 +654,7 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Subtract the 1 copy we'd output anyway to get extras */
--bd->writeCopies;
}
} /* for(;;) */
} /* for (;;) */
/* Decompression of this input block completed successfully */
bd->writeCRC = CRC = ~CRC;

View File

@ -92,8 +92,12 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
/* Only size is always present, the rest may be missing in
* long filename pseudo file. Thus we decode the rest
* after dealing with long filename pseudo file.
*
* GNU binutils in deterministic mode hard codes mode to 0644 (NOT
* 0100644). AR archives can only contain files, so force file
* mode.
*/
typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode));
typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)) | S_IFREG;
typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid));
typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid));
typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date));

View File

@ -147,6 +147,14 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
#endif
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static void die_if_bad_fnamesize(off_t sz)
{
if ((uoff_t)sz > 0xfff) /* more than 4k?! no funny business please */
bb_simple_error_msg_and_die("bad archive");
}
#endif
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
{
file_header_t *file_header = archive_handle->file_header;
@ -331,8 +339,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header->name = xstrdup(tar.name);
}
/* Set bits 12-15 of the files mode */
/* (typeflag was not trashed because chksum does not use getOctal) */
switch (tar_typeflag) {
case '1': /* hardlink */
/* we mark hardlinks as regular files with zero size and a link name */
@ -341,7 +347,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* ... For tar archives written by pre POSIX.1-1988
* implementations, the size field usually contains the size of
* the file and needs to be ignored as no data may follow this
* header type. For POSIX.1- 1988 compliant archives, the size
* header type. For POSIX.1-1988 compliant archives, the size
* field needs to be 0. For POSIX.1-2001 compliant archives,
* the size field may be non zero, indicating that file data is
* included in the archive.
@ -390,6 +396,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* free: paranoia: tar with several consecutive longnames */
free(p_longname);
/* For paranoia reasons we allocate extra NUL char */
die_if_bad_fnamesize(file_header->size);
p_longname = xzalloc(file_header->size + 1);
/* We read ASCIZ string, including NUL */
xread(archive_handle->src_fd, p_longname, file_header->size);
@ -400,6 +407,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
goto again;
case 'K':
free(p_linkname);
die_if_bad_fnamesize(file_header->size);
p_linkname = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, p_linkname, file_header->size);
archive_handle->offset += file_header->size;

View File

@ -9,6 +9,7 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
{
struct tm tm_time;
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
char modestr[12];
#if ENABLE_FEATURE_TAR_UNAME_GNAME
char uid[sizeof(int)*3 + 2];
@ -29,7 +30,7 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
group = utoa(file_header->gid);
}
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
bb_mode_string(file_header->mode),
bb_mode_string(modestr, file_header->mode),
user,
group,
file_header->size,
@ -46,7 +47,7 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
localtime_r(&file_header->mtime, ptm);
printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
bb_mode_string(file_header->mode),
bb_mode_string(modestr, file_header->mode),
(unsigned)file_header->uid,
(unsigned)file_header->gid,
file_header->size,

View File

@ -545,7 +545,7 @@ static enum xz_ret XZ_FUNC dec_block_header(struct xz_dec *s)
return XZ_OK;
}
static enum xz_ret XZ_FUNC dec_main(struct xz_dec *s, struct xz_buf *b)
static NOINLINE enum xz_ret XZ_FUNC dec_main(struct xz_dec *s, struct xz_buf *b)
{
enum xz_ret ret;

View File

@ -25,7 +25,7 @@
"Minimalized" for busybox by Alain Knaff
*/
//config:config LZOP
//config: bool "lzop (12 kb)"
//config: bool "lzop (13 kb)"
//config: default y
//config: help
//config: Lzop compression/decompresion.

View File

@ -254,32 +254,6 @@ static void putOctal(char *cp, int len, off_t value)
}
#define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b))
static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
{
/* POSIX says that checksum is done on unsigned bytes
* (Sun and HP-UX gets it wrong... more details in
* GNU tar source) */
const unsigned char *cp;
int chksum, size;
strcpy(hp->magic, "ustar ");
/* Calculate and store the checksum (i.e., the sum of all of the bytes of
* the header). The checksum field must be filled with blanks for the
* calculation. The checksum field is formatted differently from the
* other fields: it has 6 digits, a null, then a space -- rather than
* digits, followed by a null like the other fields... */
memset(hp->chksum, ' ', sizeof(hp->chksum));
cp = (const unsigned char *) hp;
chksum = 0;
size = sizeof(*hp);
do { chksum += *cp++; } while (--size);
putOctal(hp->chksum, sizeof(hp->chksum)-1, chksum);
/* Now write the header out to disk */
xwrite(fd, hp, sizeof(*hp));
}
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static void writeLongname(int fd, int type, const char *name, int dir)
{
@ -310,7 +284,7 @@ static void writeLongname(int fd, int type, const char *name, int dir)
/* + dir: account for possible '/' */
PUT_OCTAL(header.size, size);
chksum_and_xwrite(fd, &header);
chksum_and_xwrite_tar_header(fd, &header);
/* Write filename[/] and pad the block. */
/* dir=0: writes 'name<NUL>', pads */
@ -441,8 +415,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
header_name, S_ISDIR(statbuf->st_mode));
# endif
/* Now write the header out to disk */
chksum_and_xwrite(tbInfo->tarFd, &header);
chksum_and_xwrite_tar_header(tbInfo->tarFd, &header);
/* Now do the verbose thing (or not) */
if (tbInfo->verboseFlag) {
@ -648,7 +621,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
execlp(gzip, gzip, "-f", (char *)0);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
/* parent */

View File

@ -56,7 +56,7 @@
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
//usage:#define unzip_trivial_usage
//usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
//usage: "[-lnojpqK] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
//usage:#define unzip_full_usage "\n\n"
//usage: "Extract FILEs from ZIP archive\n"
//usage: "\n -l List contents (with -q for short form)"
@ -66,6 +66,7 @@
//usage: "\n -p Write to stdout"
//usage: "\n -t Test"
//usage: "\n -q Quiet"
//usage: "\n -K Do not clear SUID bit"
//usage: "\n -x FILE Exclude FILEs"
//usage: "\n -d DIR Extract into DIR"
@ -118,6 +119,8 @@ typedef union {
#define FIX_ENDIANNESS_ZIP(zip) \
do { if (BB_BIG_ENDIAN) { \
(zip).fmt.method = SWAP_LE16((zip).fmt.method ); \
(zip).fmt.modtime = SWAP_LE16((zip).fmt.modtime ); \
(zip).fmt.moddate = SWAP_LE16((zip).fmt.moddate ); \
(zip).fmt.crc32 = SWAP_LE32((zip).fmt.crc32 ); \
(zip).fmt.cmpsize = SWAP_LE32((zip).fmt.cmpsize ); \
(zip).fmt.ucmpsize = SWAP_LE32((zip).fmt.ucmpsize ); \
@ -492,6 +495,7 @@ int unzip_main(int argc, char **argv)
OPT_l = (1 << 0),
OPT_x = (1 << 1),
OPT_j = (1 << 2),
OPT_K = (1 << 3),
};
unsigned opts;
smallint quiet = 0;
@ -555,9 +559,14 @@ int unzip_main(int argc, char **argv)
* 204372 1 file
*/
//TODO: accept and ignore these?
// -a convert to text files with 't' label, -aa: all files
// -b do not convert to text - bbox: we don't convert anything
// -D skip restoration of timestamps for extracted items - bbox: we don't restore these (yet?)
// -X restore user:group ownership
opts = 0;
/* '-' makes getopt return 1 for non-options */
while ((i = getopt(argc, argv, "-d:lnotpqxjv")) != -1) {
while ((i = getopt(argc, argv, "-d:lnotpqxjvK")) != -1) {
switch (i) {
case 'd': /* Extract to base directory */
base_dir = optarg;
@ -579,6 +588,7 @@ int unzip_main(int argc, char **argv)
xmove_fd(xopen("/dev/null", O_WRONLY), STDOUT_FILENO);
/*fallthrough*/
// NB: -c extract files to stdout/screen (unlike -p, also prints .zip and file names to stdout)
case 'p': /* Extract files to stdout */
dst_fd = STDOUT_FILENO;
/*fallthrough*/
@ -600,6 +610,10 @@ int unzip_main(int argc, char **argv)
opts |= OPT_j;
break;
case 'K':
opts |= OPT_K;
break;
case 1:
if (!src_fn) {
/* The zip file */
@ -817,7 +831,10 @@ int unzip_main(int argc, char **argv)
# endif
if ((cdf.fmt.version_made_by >> 8) == 3) {
/* This archive is created on Unix */
dir_mode = file_mode = (cdf.fmt.external_attributes >> 16);
file_mode = (cdf.fmt.external_attributes >> 16);
if (!(opts & OPT_K))
file_mode &= ~(mode_t)(S_ISUID | S_ISGID);
dir_mode = file_mode;
}
}
#endif
@ -842,6 +859,7 @@ int unzip_main(int argc, char **argv)
unzip_skip(zip.fmt.extra_len);
/* Guard against "/abspath", "/../" and similar attacks */
// NB: UnZip 6.00 has option -: to disable this
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
/* Filter zip entries */

View File

@ -0,0 +1,47 @@
/* Add SORT_BY_ALIGNMENT to linker script (found in busybox_unstripped.out):
## .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) }
## .data : { *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) }
## .bss : { *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) }
## This will eliminate most of the padding (~3kb).
## Hmm, "ld --sort-section alignment" should do it too.
##
## There is a ld hack which is meant to decrease disk usage
## at the cost of more RAM usage (??!!) in standard ld script:
## . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1)); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
## Replace it with:
## . = ALIGN (0x1000); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
## to unconditionally align .data to the next page boundary,
## instead of "next page, plus current offset in this page"
*/
/* To reduce the number of VMAs each bbox process has,
## move *(.bss SORT_BY_ALIGNMENT(.bss.*) ...)
## part from .bss : {...} block to .data : { ... } block.
## (This usually increases .data section by only one page).
## Result:
##
## text data bss dec hex filename
## 1050792 560 7580 1058932 102874 busybox.bss
## 1050792 8149 0 1058941 10287d busybox.nobss
##
## $ exec busybox.bss pmap $$
## 0000000008048000 1028K r-xp /path/to/busybox.bss
## 0000000008149000 8K rw-p /path/to/busybox.bss
## 000000000814b000 4K rw-p [ anon ] <---- this VMA is eliminated
## 00000000085f5000 4K ---p [heap]
## 00000000085f6000 4K rw-p [heap]
## 00000000f7778000 8K rw-p [ anon ]
## 00000000f777a000 12K r--p [vvar]
## 00000000f777d000 8K r-xp [vdso]
## 00000000ff7e9000 132K rw-p [stack]
##
## $ exec busybox.nobss pmap $$
## 0000000008048000 1028K r-xp /path/to/busybox.nobss
## 0000000008149000 12K rw-p /path/to/busybox.nobss
## 00000000086f0000 4K ---p [heap]
## 00000000086f1000 4K rw-p [heap]
## 00000000f7783000 8K rw-p [ anon ]
## 00000000f7785000 12K r--p [vvar]
## 00000000f7788000 8K r-xp [vdso]
## 00000000ffac0000 132K rw-p [stack]
*/

View File

@ -703,6 +703,7 @@ CONFIG_FEATURE_INETD_RPC=y
CONFIG_IP=y
CONFIG_FEATURE_IP_ADDRESS=y
CONFIG_FEATURE_IP_LINK=y
CONFIG_FEATURE_IP_LINK_CAN=y
CONFIG_FEATURE_IP_ROUTE=y
CONFIG_FEATURE_IP_TUNNEL=y
CONFIG_FEATURE_IP_RULE=y

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHVT
//config: bool "chvt (2 kb)"
//config: bool "chvt (2.2 kb)"
//config: default y
//config: help
//config: This program is used to change to another terminal.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CLEAR
//config: bool "clear (tiny)"
//config: bool "clear (371 bytes)"
//config: default y
//config: help
//config: This program clears the terminal screen.

View File

@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DEALLOCVT
//config: bool "deallocvt (1.9 kb)"
//config: bool "deallocvt (2.2 kb)"
//config: default y
//config: help
//config: This program deallocates unused virtual consoles.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DUMPKMAP
//config: bool "dumpkmap (1.6 kb)"
//config: bool "dumpkmap (1.9 kb)"
//config: default y
//config: help
//config: This program dumps the kernel's keyboard translation table to

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FGCONSOLE
//config: bool "fgconsole (1.5 kb)"
//config: bool "fgconsole (1.8 kb)"
//config: default y
//config: help
//config: This program prints active (foreground) console number.

View File

@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config KBD_MODE
//config: bool "kbd_mode (4.1 kb)"
//config: bool "kbd_mode (4.3 kb)"
//config: default y
//config: help
//config: This program reports and sets keyboard mode.

View File

@ -10,7 +10,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LOADFONT
//config: bool "loadfont (5.2 kb)"
//config: bool "loadfont (5.4 kb)"
//config: default y
//config: help
//config: This program loads a console font from standard input.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config LOADKMAP
//config: bool "loadkmap (1.8 kb)"
//config: bool "loadkmap (2.1 kb)"
//config: default y
//config: help
//config: This program loads a keyboard translation table from

View File

@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config OPENVT
//config: bool "openvt (7.2 kb)"
//config: bool "openvt (7.4 kb)"
//config: default y
//config: help
//config: This program is used to start a command on an unused

View File

@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RESET
//config: bool "reset (345 bytes)"
//config: bool "reset (676 bytes)"
//config: default y
//config: help
//config: This program is used to reset the terminal screen, if it
@ -21,7 +21,7 @@
//usage:#define reset_trivial_usage
//usage: ""
//usage:#define reset_full_usage "\n\n"
//usage: "Reset the screen"
//usage: "Reset terminal (ESC codes) and termios (signals, buffering, echo)"
/* "Standard" version of this tool is in ncurses package */
@ -36,7 +36,7 @@ int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
static const char *const args[] = {
static const char *const args[] ALIGN_PTR = {
"stty", "sane", NULL
};

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RESIZE
//config: bool "resize (903 bytes)"
//config: bool "resize (1.2 kb)"
//config: default y
//config: help
//config: This program is used to (re)set the width and height of your current
@ -45,7 +45,7 @@ static void
onintr(int sig UNUSED_PARAM)
{
tcsetattr(STDERR_FILENO, TCSANOW, old_termios_p);
_exit(EXIT_FAILURE);
_exit_FAILURE();
}
int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@ -74,7 +74,19 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+ (1 << SIGTERM)
+ (1 << SIGALRM)
, onintr);
tcsetattr(STDERR_FILENO, TCSANOW, &new);
/* Users report:
* The resize command messes up the terminal.
* In my case it looks like it is hanging and
* I need to press ctrl-c to get a prompt.
* Actually the program does not hang but just
* the terminal is messed up.
* Replaced TCSANOW with TCSAFLUSH:
* "the change occurs after all output written to fd
* has been transmitted, and all input that has been
* received but not read will be discarded before
* the change is made.
*/
tcsetattr(STDERR_FILENO, TCSAFLUSH, &new);
/* save_cursor_pos 7
* scroll_whole_screen [r

View File

@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETCONSOLE
//config: bool "setconsole (3.6 kb)"
//config: bool "setconsole (3.8 kb)"
//config: default y
//config: help
//config: Redirect writes to /dev/console to another device,

View File

@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETKEYCODES
//config: bool "setkeycodes (2.1 kb)"
//config: bool "setkeycodes (2.4 kb)"
//config: default y
//config: help
//config: This program loads entries into the kernel's scancode-to-keycode

View File

@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETLOGCONS
//config: bool "setlogcons (1.8 kb)"
//config: bool "setlogcons (2 kb)"
//config: default y
//config: help
//config: This program redirects the output console of kernel messages.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SHOWKEY
//config: bool "showkey (4.7 kb)"
//config: bool "showkey (4.9 kb)"
//config: default y
//config: help
//config: Shows keys pressed.

View File

@ -5,10 +5,6 @@
menu "Coreutils"
INSERT
comment "Common options"
config FEATURE_VERBOSE
bool "Support verbose options (usually -v) for various applets"
default y
@ -17,6 +13,19 @@ config FEATURE_VERBOSE
Also enables long option (--verbose) if it exists.
Without this option, -v is accepted but ignored.
comment "Common options for date and touch"
config FEATURE_TIMEZONE
bool "Allow timezone in dates"
default y
depends on DESKTOP
help
Permit the use of timezones when parsing user-provided data
strings, e.g. '1996-04-09 12:45:00 -0500'.
This requires support for the '%z' extension to strptime() which
may not be available in all implementations.
comment "Common options for cp and mv"
depends on CP || MV
@ -37,4 +46,6 @@ config FEATURE_HUMAN_READABLE
help
Allow df, du, and ls to have human readable output.
INSERT
endmenu

View File

@ -14,7 +14,7 @@
* 3) Save some space by using strcmp(). Calling strncmp() here was silly.
*/
//config:config BASENAME
//config: bool "basename (438 bytes)"
//config: bool "basename (3.7 kb)"
//config: default y
//config: help
//config: basename is used to strip the directory and suffix from filenames,
@ -29,9 +29,11 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
//usage:#define basename_trivial_usage
//usage: "FILE [SUFFIX]"
//usage: "FILE [SUFFIX] | -a FILE... | -s SUFFIX FILE..."
//usage:#define basename_full_usage "\n\n"
//usage: "Strip directory path and .SUFFIX from FILE"
//usage: "Strip directory path and SUFFIX from FILE\n"
//usage: "\n -a All arguments are FILEs"
//usage: "\n -s SUFFIX Remove SUFFIX (implies -a)"
//usage:
//usage:#define basename_example_usage
//usage: "$ basename /usr/local/bin/foo\n"
@ -48,31 +50,43 @@
int basename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int basename_main(int argc UNUSED_PARAM, char **argv)
{
size_t m, n;
char *s;
unsigned opts;
const char *suffix = NULL;
if (argv[1] && strcmp(argv[1], "--") == 0) {
argv++;
}
if (!argv[1])
bb_show_usage();
/* '+': stop at first non-option */
opts = getopt32(argv, "^+" "as:"
"\0" "-1" /* At least one argument */
, &suffix
);
argv += optind;
/* It should strip slash: /abc/def/ -> def */
s = bb_get_last_path_component_strip(*++argv);
do {
char *s;
size_t m;
m = strlen(s);
if (*++argv) {
if (argv[1])
bb_show_usage();
n = strlen(*argv);
if ((m > n) && (strcmp(s+m-n, *argv) == 0)) {
m -= n;
/*s[m] = '\0'; - redundant */
/* It should strip slash: /abc/def/ -> def */
s = bb_get_last_path_component_strip(*argv++);
m = strlen(s);
if (!opts) {
if (*argv) {
suffix = *argv;
if (argv[1])
bb_show_usage();
}
}
}
if (suffix) {
size_t n = strlen(suffix);
if ((m > n) && (strcmp(s + m - n, suffix) == 0)) {
m -= n;
/*s[m] = '\0'; - redundant */
}
}
/* puts(s) will do, but we can do without stdio this way: */
s[m++] = '\n';
/* NB: != is correct here: */
if (full_write(STDOUT_FILENO, s, m) != (ssize_t)m)
return EXIT_FAILURE;
} while (opts && *argv);
/* puts(s) will do, but we can do without stdio this way: */
s[m++] = '\n';
/* NB: != is correct here: */
return full_write(STDOUT_FILENO, s, m) != (ssize_t)m;
return EXIT_SUCCESS;
}

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config CAT
//config: bool "cat (5.6 kb)"
//config: bool "cat (5.8 kb)"
//config: default y
//config: help
//config: cat is used to concatenate files and print them to the standard

View File

@ -88,10 +88,12 @@ static int FAST_FUNC fileAction(struct recursive_state *state,
if (chmod(fileName, newmode) == 0) {
if (OPT_VERBOSE
|| (OPT_CHANGED && statbuf->st_mode != newmode)
|| (OPT_CHANGED
&& (statbuf->st_mode & 07777) != (newmode & 07777))
) {
char modestr[12];
printf("mode of '%s' changed to %04o (%s)\n", fileName,
newmode & 07777, bb_mode_string(newmode)+1);
newmode & 07777, bb_mode_string(modestr, newmode)+1);
}
return TRUE;
}

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHROOT
//config: bool "chroot (3.7 kb)"
//config: bool "chroot (4 kb)"
//config: default y
//config: help
//config: chroot is used to change the root directory and run a command.

View File

@ -7,11 +7,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CKSUM
//config: bool "cksum (4.1 kb)"
//config: bool "cksum (4.3 kb)"
//config: default y
//config:
//config:config CRC32
//config: bool "crc32 (4.1 kb)"
//config: bool "crc32 (4.2 kb)"
//config: default y
// APPLET_NOEXEC:name main location suid_type help
@ -39,7 +39,7 @@ int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cksum_main(int argc UNUSED_PARAM, char **argv)
{
uint32_t *crc32_table = crc32_filltable(NULL, IS_CKSUM);
int exit_code = EXIT_SUCCESS;
exitcode_t exit_code = EXIT_SUCCESS;
#if ENABLE_DESKTOP
getopt32(argv, ""); /* cksum coreutils 6.9 compat */

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config COMM
//config: bool "comm (4.2 kb)"
//config: bool "comm (4.4 kb)"
//config: default y
//config: help
//config: comm is used to compare two files line by line and return

View File

@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CUT
//config: bool "cut (5.8 kb)"
//config: bool "cut (6.7 kb)"
//config: default y
//config: help
//config: cut is used to print selected parts of lines from
@ -167,7 +167,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
if (!cl_pos && !dcount && !shoe) {
if (option_mask32 & CUT_OPT_SUPPRESS_FLGS)
goto next_line;
} else if (dcount<cut_lists[cl_pos].startpos)
} else if (dcount < cut_lists[cl_pos].startpos)
start = linelen;
end = linelen;
} else {
@ -311,7 +311,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
}
{
int retval = EXIT_SUCCESS;
exitcode_t retval = EXIT_SUCCESS;
if (!*argv)
*--argv = (char *)"-";

View File

@ -19,7 +19,7 @@
much as possible, missed out a lot of bounds checking */
//config:config DATE
//config: bool "date (7 kb)"
//config: bool "date (7.2 kb)"
//config: default y
//config: help
//config: date is used to set the system date or display the
@ -266,6 +266,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
/* If date string is given, update tm_time, and maybe set date */
if (date_str != NULL) {
int check_dst = 1;
/* Zero out fields - take her back to midnight! */
tm_time.tm_sec = 0;
tm_time.tm_min = 0;
@ -276,12 +277,12 @@ int date_main(int argc UNUSED_PARAM, char **argv)
if (strptime(date_str, fmt_str2dt, &tm_time) == NULL)
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
} else {
parse_datestr(date_str, &tm_time);
check_dst = parse_datestr(date_str, &tm_time);
}
/* Correct any day of week and day of year etc. fields */
/* Be sure to recheck dst (but not if date is time_t format) */
if (date_str[0] != '@')
/* Be sure to recheck dst (but not if date is UTC) */
if (check_dst)
tm_time.tm_isdst = -1;
ts.tv_sec = validate_tm_time(date_str, &tm_time);
ts.tv_nsec = 0;

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DD
//config: bool "dd (7.5 kb)"
//config: bool "dd (8.3 kb)"
//config: default y
//config: help
//config: dd copies a file (from standard input to standard output,
@ -200,6 +200,7 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
}
#if ENABLE_FEATURE_DD_IBS_OBS
# ifdef O_DIRECT
static int clear_O_DIRECT(int fd)
{
if (errno == EINVAL) {
@ -211,6 +212,7 @@ static int clear_O_DIRECT(int fd)
}
return 0;
}
# endif
#endif
static ssize_t dd_read(void *ibuf, size_t ibs)
@ -225,8 +227,10 @@ static ssize_t dd_read(void *ibuf, size_t ibs)
#endif
n = safe_read(ifd, ibuf, ibs);
#if ENABLE_FEATURE_DD_IBS_OBS
# ifdef O_DIRECT
if (n < 0 && (G.flags & FLAG_IDIRECT) && clear_O_DIRECT(ifd))
goto read_again;
# endif
#endif
return n;
}
@ -239,8 +243,10 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
IF_FEATURE_DD_IBS_OBS(write_again:)
n = full_write(ofd, buf, len);
#if ENABLE_FEATURE_DD_IBS_OBS
# ifdef O_DIRECT
if (n < 0 && (G.flags & FLAG_ODIRECT) && clear_O_DIRECT(ofd))
goto write_again;
# endif
#endif
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
@ -369,7 +375,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
OP_oflag_direct,
#endif
};
smallint exitcode = EXIT_FAILURE;
exitcode_t exitcode = EXIT_FAILURE;
int i;
size_t ibs = 512;
char *ibuf;
@ -501,8 +507,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (infile) {
int iflag = O_RDONLY;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_IDIRECT)
if (G.flags & FLAG_IDIRECT) {
# ifdef O_DIRECT
iflag |= O_DIRECT;
# else
bb_error_msg_and_die("O_DIRECT not supported on this platform");
# endif
}
#endif
xmove_fd(xopen(infile, iflag), ifd);
} else {
@ -516,8 +527,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (G.flags & FLAG_APPEND)
oflag |= O_APPEND;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_ODIRECT)
if (G.flags & FLAG_ODIRECT) {
# ifdef O_DIRECT
oflag |= O_DIRECT;
# else
bb_error_msg_and_die("O_DIRECT not supported on this platform");
# endif
}
#endif
xmove_fd(xopen(outfile, oflag), ofd);

View File

@ -18,7 +18,7 @@
* Implement -P and -B; better coreutils compat; cleanup
*/
//config:config DF
//config: bool "df (6.8 kb)"
//config: bool "df (7.1 kb)"
//config: default y
//config: help
//config: df reports the amount of disk space used and available
@ -32,6 +32,26 @@
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//config:
//config:config FEATURE_SKIP_ROOTFS
//config: bool "Skip rootfs in mount table"
//config: default y
//config: depends on DF
//config: help
//config: Ignore rootfs entry in mount table.
//config:
//config: In Linux, kernel has a special filesystem, rootfs, which is initially
//config: mounted on /. It contains initramfs data, if kernel is configured
//config: to have one. Usually, another file system is mounted over / early
//config: in boot process, and therefore most tools which manipulate
//config: mount table, such as df, will skip rootfs entry.
//config:
//config: However, some systems do not mount anything on /.
//config: If you need to configure busybox for one of these systems,
//config: you may find it useful to turn this option off to make df show
//config: initramfs statistics.
//config:
//config: Otherwise, choose Y.
//applet:IF_DF(APPLET_NOEXEC(df, df, BB_DIR_BIN, BB_SUID_DROP, df))
@ -93,21 +113,22 @@ int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int df_main(int argc UNUSED_PARAM, char **argv)
{
unsigned long df_disp_hr = 1024;
int status = EXIT_SUCCESS;
exitcode_t status = EXIT_SUCCESS;
unsigned opt;
FILE *mount_table;
struct mntent *mount_entry;
struct statvfs s;
enum {
OPT_KILO = (1 << 0),
OPT_POSIX = (1 << 1),
OPT_FSTYPE = (1 << 2),
OPT_t = (1 << 3),
OPT_ALL = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
OPT_INODE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
OPT_BSIZE = (1 << 6) * ENABLE_FEATURE_DF_FANCY,
OPT_HUMAN = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_MEGA = (1 << (5 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_KILO = (1 << 0),
OPT_POSIX = (1 << 1),
OPT_FSTYPE = (1 << 2),
OPT_t = (1 << 3),
OPT_ALL = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
OPT_INODE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
OPT_BSIZE = (1 << 6) * ENABLE_FEATURE_DF_FANCY,
OPT_HUMAN = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_HUMANDEC = (1 << (5 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_MEGA = (1 << (6 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
};
const char *disp_units_hdr = NULL;
char *chp, *opt_t;
@ -124,7 +145,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
opt = getopt32(argv, "^"
"kPTt:"
IF_FEATURE_DF_FANCY("aiB:")
IF_FEATURE_HUMAN_READABLE("hm")
IF_FEATURE_HUMAN_READABLE("hHm")
"\0"
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
"k-mB:m-Bk:B-km"
@ -151,8 +172,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
got_it: ;
}
if (opt & OPT_HUMAN) {
if (opt & (OPT_HUMAN|OPT_HUMANDEC)) {
df_disp_hr = 0;
//TODO: need to add support in make_human_readable_str() for "decimal human readable"
//if (opt & OPT_HUMANDEC)
// df_disp_hr--;
disp_units_hdr = " Size";
}
if (opt & OPT_INODE)

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DIRNAME
//config: bool "dirname (329 bytes)"
//config: bool "dirname (611 bytes)"
//config: default y
//config: help
//config: dirname is used to strip a non-directory suffix from

View File

@ -12,14 +12,14 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DOS2UNIX
//config: bool "dos2unix (5.2 kb)"
//config: bool "dos2unix (5.5 kb)"
//config: default y
//config: help
//config: dos2unix is used to convert a text file from DOS format to
//config: UNIX format, and vice versa.
//config:
//config:config UNIX2DOS
//config: bool "unix2dos (5.2 kb)"
//config: bool "unix2dos (5.5 kb)"
//config: default y
//config: help
//config: unix2dos is used to convert a text file from UNIX format to

View File

@ -19,7 +19,7 @@
* 4) Fixed busybox bug #1284 involving long overflow with human_readable.
*/
//config:config DU
//config: bool "du (6.3 kb)"
//config: bool "du (6.5 kb)"
//config: default y
//config: help
//config: du is used to report the amount of disk space used

View File

@ -19,7 +19,7 @@
* The previous version did not allow 4-digit octals.
*/
//config:config ECHO
//config: bool "echo (1.8 kb)"
//config: bool "echo (2 kb)"
//config: default y
//config: help
//config: echo prints a specified string to stdout.
@ -321,6 +321,8 @@ int echo_main(int argc, char **argv)
if (*arg == '0' && (unsigned char)(arg[1] - '0') < 8) {
arg++;
}
//FIXME? we also accept non-0 starting sequences (see echo-prints-slash_41 test)
// echo -ne '-\41-' prints "-!-". bash 5.0.17 does not (prints "-\41-").
/* bb_process_escape_sequence can handle nul correctly */
c = bb_process_escape_sequence( (void*) &arg);
}

View File

@ -24,7 +24,7 @@
* - use xfunc_error_retval
*/
//config:config ENV
//config: bool "env (4 kb)"
//config: bool "env (4.3 kb)"
//config: default y
//config: help
//config: env is used to set an environment variable and run
@ -100,7 +100,7 @@ int env_main(int argc UNUSED_PARAM, char **argv)
}
}
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}
/*

View File

@ -21,13 +21,13 @@
* Caveat: this versions of expand and unexpand don't accept tab lists.
*/
//config:config EXPAND
//config: bool "expand (5.1 kb)"
//config: bool "expand (5.3 kb)"
//config: default y
//config: help
//config: By default, convert all tabs to spaces.
//config:
//config:config UNEXPAND
//config: bool "unexpand (5.3 kb)"
//config: bool "unexpand (5.5 kb)"
//config: default y
//config: help
//config: By default, convert only leading sequences of blanks to tabs.
@ -192,7 +192,7 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
FILE *file;
unsigned tab_size;
unsigned opt;
int exit_status = EXIT_SUCCESS;
exitcode_t exit_status = EXIT_SUCCESS;
init_unicode();

View File

@ -23,7 +23,7 @@
* provided they all associate ((x op x) op x).
*/
//config:config EXPR
//config: bool "expr (6.6 kb)"
//config: bool "expr (6.8 kb)"
//config: default y
//config: help
//config: expr is used to calculate numbers and print the result

View File

@ -4,7 +4,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config FACTOR
//config: bool "factor (2.7 kb)"
//config: bool "factor (3.2 kb)"
//config: default y
//config: help
//config: factor factorizes integers
@ -48,38 +48,40 @@ typedef unsigned long half_t;
* Larger wheels improve sieving only slightly, but quickly grow in size
* (adding just one prime, 13, results in 5766 element sieve).
*/
#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
(((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \
(((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31)
#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J,x) \
(((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \
(((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31) | \
((uint64_t)x << 61)
#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J,x) \
R( (a/2),(b/2),(c/2),(d/2),(e/2),(f/2),(g/2),(h/2),(i/2),(j/2), \
(A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2) )
(A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2), \
(x/2) \
)
static const uint64_t packed_wheel[] = {
/*1, 2, 2, 4, 2,*/
P( 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4), //01
P( 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2, 4), //02
P( 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4), //03
P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2), //04
P( 6, 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4), //05
P( 2, 6, 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2), //06
P( 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6), //07
P( 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6), //08
P( 8, 6, 4, 2,10, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6), //09
P( 4, 2, 4, 6, 6, 2, 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4), //10
P( 6, 6, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2), //11
P( 6, 4, 6, 2, 6, 4, 2, 4, 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2), //12
P( 4, 8,10, 6, 2, 4, 8, 6, 6, 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2), //13
P(10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 6, 6, 4, 6, 8), //14
P( 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6, 2, 6, 6, 4, 2, 4, 6, 8, 4), //15
P( 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2,10, 2, 4, 6, 8, 6, 4, 2), //16
P( 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 6), //17
P( 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2,10, 6), //18
P( 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4, 6, 2, 4, 6, 2), //19
P(12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4, 6, 2, 6, 4), //20
P( 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6, 4, 6, 2), //21
P( 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4, 2,10), //22
P( 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8, 6), //23
P( 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12), //24
/* 1, 2, */
P( 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6),
P( 8, 4, 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2),
P( 4, 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4),
P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6),
P( 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4, 2, 6),
P( 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2, 4, 6, 2),
P( 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6, 6, 2, 6, 4),
P( 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6, 8, 6, 4, 2,10),
P( 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6, 4, 2, 4, 6, 6, 2),
P( 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 6, 6, 6, 2, 6, 6, 4),
P( 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 6, 4, 6, 2, 6, 4, 2, 4),
P( 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2, 4, 8,10, 6, 2, 4, 8, 6, 6),
P( 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2),
P( 4, 6, 6, 2, 6, 6, 6, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6),
P( 2, 6, 6, 4, 2, 4, 6, 8, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2),
P(10, 2, 4, 6, 8, 6, 4, 2, 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2),
P( 4, 6, 2, 6, 6, 4, 6, 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6),
P( 2, 6, 4, 2,10, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4),
P( 6, 2, 4, 6, 2,12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4),
P( 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6),
P( 4, 6, 2, 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4),
P( 2,10, 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8),
P( 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12),
};
#undef P
#undef R
@ -93,8 +95,8 @@ static const uint64_t packed_wheel[] = {
* function old new delta
* wheel_tab - 485 +485
* 3-bit-packed insanity:
* packed_wheel - 192 +192
* factor_main 108 171 +63
* packed_wheel - 184 +184
* factor_main 108 163 +55
*/
static void unpack_wheel(void)
{
@ -104,10 +106,7 @@ static void unpack_wheel(void)
setup_common_bufsiz();
wheel_tab[0] = 1;
wheel_tab[1] = 2;
wheel_tab[2] = 2;
wheel_tab[3] = 4;
wheel_tab[4] = 2;
p = &wheel_tab[5];
p = &wheel_tab[2];
for (i = 0; i < ARRAY_SIZE(packed_wheel); i++) {
uint64_t v = packed_wheel[i];
while ((v & 0xe) != 0) {

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FALSE
//config: bool "false (tiny)"
//config: bool "false (314 bytes)"
//config: default y
//config: help
//config: false returns an exit code of FALSE (1).

View File

@ -11,7 +11,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FOLD
//config: bool "fold (4.6 kb)"
//config: bool "fold (4.8 kb)"
//config: default y
//config: help
//config: Wrap text to fit a specific width.
@ -77,7 +77,7 @@ int fold_main(int argc UNUSED_PARAM, char **argv)
char *line_out = NULL;
const char *w_opt = "80";
unsigned width;
smallint exitcode = EXIT_SUCCESS;
exitcode_t exitcode = EXIT_SUCCESS;
init_unicode();

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config HEAD
//config: bool "head (3.8 kb)"
//config: bool "head (4 kb)"
//config: default y
//config: help
//config: head is used to print the first specified number of lines
@ -76,7 +76,7 @@ print_except_N_last_bytes(FILE *fp, unsigned count)
{
unsigned char *circle = xmalloc(++count);
unsigned head = 0;
for(;;) {
for (;;) {
int c;
c = getc(fp);
if (c == EOF)
@ -105,7 +105,7 @@ print_except_N_last_lines(FILE *fp, unsigned count)
{
char **circle = xzalloc((++count) * sizeof(circle[0]));
unsigned head = 0;
for(;;) {
for (;;) {
char *c;
c = xmalloc_fgets(fp);
if (!c)
@ -127,7 +127,7 @@ print_except_N_last_lines(FILE *fp, unsigned count)
}
ret:
head = 0;
for(;;) {
for (;;) {
free(circle[head++]);
if (head == count)
break;

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config HOSTID
//config: bool "hostid (286 bytes)"
//config: bool "hostid (566 bytes)"
//config: default y
//config: help
//config: hostid prints the numeric identifier (in hexadecimal) for

View File

@ -13,13 +13,13 @@
* Added -G option Tito Ragusa (C) 2008 for SUSv3.
*/
//config:config ID
//config: bool "id (7 kb)"
//config: bool "id (7.1 kb)"
//config: default y
//config: help
//config: id displays the current user and group ID names.
//config:
//config:config GROUPS
//config: bool "groups (6.7 kb)"
//config: bool "groups (6.8 kb)"
//config: default y
//config: help
//config: Print the group names associated with current user id.

View File

@ -244,6 +244,15 @@ int install_main(int argc, char **argv)
}
}
/* Set the user and group id */
/* (must be before chmod, or else chown may clear suid/gid bits) */
if ((opts & (OPT_OWNER|OPT_GROUP))
&& lchown(dest, uid, gid) == -1
) {
bb_perror_msg("can't change %s of %s", "ownership", dest);
ret = EXIT_FAILURE;
}
/* Set the file mode (always, not only with -m).
* GNU coreutils 6.10 is not affected by umask. */
if (chmod(dest, mode) == -1) {
@ -254,13 +263,6 @@ int install_main(int argc, char **argv)
if (use_default_selinux_context)
setdefaultfilecon(dest);
#endif
/* Set the user and group id */
if ((opts & (OPT_OWNER|OPT_GROUP))
&& lchown(dest, uid, gid) == -1
) {
bb_perror_msg("can't change %s of %s", "ownership", dest);
ret = EXIT_FAILURE;
}
next:
if (ENABLE_FEATURE_CLEAN_UP && isdir)
free(dest);

View File

@ -6,7 +6,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LINK
//config: bool "link (3.2 kb)"
//config: bool "link (3.5 kb)"
//config: default y
//config: help
//config: link creates hard links between files.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config LN
//config: bool "ln (4.9 kb)"
//config: bool "ln (5.1 kb)"
//config: default y
//config: help
//config: ln is used to create hard or soft links between files.
@ -52,7 +52,7 @@
int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ln_main(int argc, char **argv)
{
int status = EXIT_SUCCESS;
exitcode_t status = EXIT_SUCCESS;
int opts;
char *last;
char *src_name;

View File

@ -16,7 +16,7 @@
* a diagnostic message and an error return.
*/
//config:config LOGNAME
//config: bool "logname (1.1 kb)"
//config: bool "logname (1.4 kb)"
//config: default y
//config: help
//config: logname is used to print the current user's login name.

View File

@ -498,12 +498,20 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
if (opt & OPT_i) /* show inode# */
column += printf("%7llu ", (long long) dn->dn_ino);
//TODO: -h should affect -s too:
if (opt & OPT_s) /* show allocated blocks */
column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
if (opt & OPT_s) { /* show allocated blocks */
if (opt & OPT_h) {
column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ",
/* print size, show one fractional, use suffixes */
make_human_readable_str((off_t)dn->dn_blocks << 9, 1, 0)
);
} else {
column += printf("%6"OFF_FMT"u ", (off_t)(dn->dn_blocks >> 1));
}
}
if (opt & OPT_l) {
/* long listing: show mode */
column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode));
char modestr[12];
column += printf("%-10s ", bb_mode_string(modestr, dn->dn_mode));
/* long listing: show number of links */
column += printf("%4lu ", (long) dn->dn_nlink);
/* long listing: show user/group */
@ -518,10 +526,10 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
#if ENABLE_FEATURE_LS_USERNAME
else {
if (opt & OPT_g) {
column += printf("%-8.8s ",
column += printf("%-8s ",
get_cached_groupname(dn->dn_gid));
} else {
column += printf("%-8.8s %-8.8s ",
column += printf("%-8s %-8s ",
get_cached_username(dn->dn_uid),
get_cached_groupname(dn->dn_gid));
}

View File

@ -6,31 +6,31 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MD5SUM
//config: bool "md5sum (6.5 kb)"
//config: bool "md5sum (6.7 kb)"
//config: default y
//config: help
//config: Compute and check MD5 message digest
//config:
//config:config SHA1SUM
//config: bool "sha1sum (5.9 kb)"
//config: bool "sha1sum (6.7 kb)"
//config: default y
//config: help
//config: Compute and check SHA1 message digest
//config:
//config:config SHA256SUM
//config: bool "sha256sum (7 kb)"
//config: bool "sha256sum (8.2 kb)"
//config: default y
//config: help
//config: Compute and check SHA256 message digest
//config:
//config:config SHA512SUM
//config: bool "sha512sum (7.4 kb)"
//config: bool "sha512sum (7.3 kb)"
//config: default y
//config: help
//config: Compute and check SHA512 message digest
//config:
//config:config SHA3SUM
//config: bool "sha3sum (6.1 kb)"
//config: bool "sha3sum (6.3 kb)"
//config: default y
//config: help
//config: Compute and check SHA3 message digest
@ -151,10 +151,12 @@ static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
return (unsigned char *)hex_value;
}
#define BUFSZ (CONFIG_FEATURE_COPYBUF_KB < 4 ? 4096 : CONFIG_FEATURE_COPYBUF_KB * 1024)
#if !ENABLE_SHA3SUM
# define hash_file(f,w) hash_file(f)
# define hash_file(b,f,w) hash_file(b,f)
#endif
static uint8_t *hash_file(const char *filename, unsigned sha3_width)
static uint8_t *hash_file(unsigned char *in_buf, const char *filename, unsigned sha3_width)
{
int src_fd, hash_len, count;
union _ctx_ {
@ -227,8 +229,7 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
}
{
RESERVE_CONFIG_UBUFFER(in_buf, 4096);
while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
while ((count = safe_read(src_fd, in_buf, BUFSZ)) > 0) {
update(&context, in_buf, count);
}
hash_value = NULL;
@ -238,7 +239,6 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
final(&context, in_buf);
hash_value = hash_bin_to_hex(in_buf, hash_len);
}
RELEASE_CONFIG_BUFFER(in_buf);
}
if (src_fd != STDIN_FILENO) {
@ -251,6 +251,7 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
int md5_sha1_sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
{
unsigned char *in_buf;
int return_value = EXIT_SUCCESS;
unsigned flags;
#if ENABLE_SHA3SUM
@ -279,6 +280,12 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
if (!*argv)
*--argv = (char*)"-";
/* The buffer is not alloc/freed for each input file:
* for big values of COPYBUF_KB, this helps to keep its pages
* pre-faulted and possibly even fully cached on local CPU.
*/
in_buf = xmalloc(BUFSZ);
do {
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
FILE *pre_computed_stream;
@ -293,12 +300,8 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
char *filename_ptr;
count_total++;
filename_ptr = strstr(line, " ");
/* handle format for binary checksums */
if (filename_ptr == NULL) {
filename_ptr = strstr(line, " *");
}
if (filename_ptr == NULL) {
filename_ptr = strchr(line, ' ');
if (!filename_ptr) {
if (flags & FLAG_WARN) {
bb_simple_error_msg("invalid format");
}
@ -307,12 +310,17 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
free(line);
continue;
}
*filename_ptr = '\0';
filename_ptr += 2;
*filename_ptr++ = '\0';
/* coreutils 9.1 allows "HASH FILENAME" format,
* with only one space. Skip the 'correct'
* " " or " *" delimiter if it is there:
*/
if (*filename_ptr == ' ' || *filename_ptr == '*')
filename_ptr++;
hash_value = hash_file(filename_ptr, sha3_width);
hash_value = hash_file(in_buf, filename_ptr, sha3_width);
if (hash_value && (strcmp((char*)hash_value, line) == 0)) {
if (hash_value && (strcasecmp((char*)hash_value, line) == 0)) {
if (!(flags & FLAG_SILENT))
printf("%s: OK\n", filename_ptr);
} else {
@ -339,7 +347,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
}
fclose_if_not_stdin(pre_computed_stream);
} else {
uint8_t *hash_value = hash_file(*argv, sha3_width);
uint8_t *hash_value = hash_file(in_buf, *argv, sha3_width);
if (hash_value == NULL) {
return_value = EXIT_FAILURE;
} else {

View File

@ -14,7 +14,7 @@
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
//config:config MKDIR
//config: bool "mkdir (4.5 kb)"
//config: bool "mkdir (4.7 kb)"
//config: default y
//config: help
//config: mkdir is used to create directories with the specified names.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MKFIFO
//config: bool "mkfifo (3.8 kb)"
//config: bool "mkfifo (4 kb)"
//config: default y
//config: help
//config: mkfifo is used to create FIFOs (named pipes).

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MKNOD
//config: bool "mknod (4.5 kb)"
//config: bool "mknod (4.6 kb)"
//config: default y
//config: help
//config: mknod is used to create FIFOs or block/character special

View File

@ -29,7 +29,7 @@
* -p; else /tmp [deprecated]
*/
//config:config MKTEMP
//config: bool "mktemp (4.2 kb)"
//config: bool "mktemp (4.5 kb)"
//config: default y
//config: help
//config: mktemp is used to create unique temporary files
@ -72,13 +72,27 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
OPT_t = 1 << 2,
OPT_p = 1 << 3,
OPT_u = 1 << 4,
OPT_tmpdir = (1 << 5) * ENABLE_LONG_OPTS,
};
path = getenv("TMPDIR");
if (!path || path[0] == '\0')
path = "/tmp";
#if ENABLE_LONG_OPTS
opts = getopt32long(argv, "^"
"dqtp:u"
"\0"
"?1" /* 1 arg max */,
"directory\0" No_argument "d"
"quiet\0" No_argument "q"
"dry-run\0" No_argument "u"
"tmpdir\0" Optional_argument "\xff"
, &path, &path
);
#else
opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path);
#endif
chp = argv[optind];
if (!chp) {
@ -95,7 +109,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv)
goto error;
}
#endif
if (opts & (OPT_t|OPT_p))
if (opts & (OPT_t|OPT_p|OPT_tmpdir))
chp = concat_path_file(path, chp);
if (opts & OPT_u) {

View File

@ -71,9 +71,9 @@ int mv_main(int argc, char **argv)
"no-target-directory\0" No_argument "T"
"target-directory\0" Required_argument "t"
IF_FEATURE_VERBOSE(
"verbose\0" No_argument "v",
&last
"verbose\0" No_argument "v"
)
, &last
);
argc -= optind;
argv += optind;

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config NICE
//config: bool "nice (2.1 kb)"
//config: bool "nice (2.3 kb)"
//config: default y
//config: help
//config: nice runs a program with modified scheduling priority.
@ -33,7 +33,7 @@ int nice_main(int argc UNUSED_PARAM, char **argv)
if (!*++argv) { /* No args, so (GNU) output current nice value. */
printf("%d\n", old_priority);
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}
adjustment = 10; /* Set default adjustment. */

View File

@ -5,7 +5,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config NL
//config: bool "nl (4.6 kb)"
//config: bool "nl (4.9 kb)"
//config: default y
//config: help
//config: nl is used to number lines of files.

View File

@ -11,7 +11,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config NOHUP
//config: bool "nohup (2 kb)"
//config: bool "nohup (2.2 kb)"
//config: default y
//config: help
//config: run a command immune to hangups, with output to a non-tty.

View File

@ -4,7 +4,7 @@
* Licensed under GPLv2, see LICENSE in this source tree
*/
//config:config NPROC
//config: bool "nproc (3.7 kb)"
//config: bool "nproc (3.9 kb)"
//config: default y
//config: help
//config: Print number of CPUs
@ -23,13 +23,11 @@
//usage: "\n --ignore=N Exclude N CPUs"
//usage: )
#include <sched.h>
#include "libbb.h"
int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
unsigned long mask[1024];
int count = 0;
#if ENABLE_LONG_OPTS
int ignore = 0;
@ -52,16 +50,16 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
}
} else
#endif
if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) {
{
int i;
for (i = 0; i < ARRAY_SIZE(mask); i++) {
unsigned long m = mask[i];
while (m) {
if (m & 1)
count++;
m >>= 1;
}
unsigned sz = 2 * 1024;
unsigned long *mask = get_malloc_cpu_affinity(0, &sz);
sz /= sizeof(long);
for (i = 0; i < sz; i++) {
if (mask[i] != 0) /* most mask[i] are usually 0 */
count += bb_popcnt_long(mask[i]);
}
IF_FEATURE_CLEAN_UP(free(mask);)
}
IF_LONG_OPTS(count -= ignore;)

View File

@ -22,7 +22,9 @@
//usage:#if !ENABLE_DESKTOP
//usage:#define od_trivial_usage
//usage: "[-aBbcDdeFfHhIiLlOovXx] [FILE]"
//usage: "[-abcdeFfhiloxsv] [FILE]"
// We also support -BDOHXIL, but they are not documented in coreutils 9.1
// manpage/help, so don't show them either.
//usage:#define od_full_usage "\n\n"
//usage: "Print FILE (or stdin) unambiguously, as octal bytes by default"
//usage:#endif
@ -144,29 +146,50 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
}
}
static const char *const add_strings[] = {
"16/1 \"%3_u \" \"\\n\"", /* a */
"8/2 \" %06o \" \"\\n\"", /* B, o */
"16/1 \"%03o \" \"\\n\"", /* b */
"16/1 \"%3_c \" \"\\n\"", /* c */
"8/2 \" %05u \" \"\\n\"", /* d */
"4/4 \" %010u \" \"\\n\"", /* D */
"2/8 \" %21.14e \" \"\\n\"", /* e (undocumented in od), F */
"4/4 \" %14.7e \" \"\\n\"", /* f */
"4/4 \" %08x \" \"\\n\"", /* H, X */
"8/2 \" %04x \" \"\\n\"", /* h, x */
"4/4 \" %11d \" \"\\n\"", /* I, L, l */
"8/2 \" %6d \" \"\\n\"", /* i */
"4/4 \" %011o \" \"\\n\"", /* O */
// bb_dump_add():
// A format string contains format units separated by [optional] whitespace.
// A format unit contains up to three items: an iteration count, a byte count,
// and a format.
// The iteration count is an optional integer (default 1).
// Each format is applied iteration count times.
// The byte count is an optional integer. It defines the number
// of bytes to be interpreted by each iteration of the format.
// If an iteration count and/or a byte count is specified, a slash must be
// placed after the iteration count and/or before the byte count
// to disambiguate them.
// The printf-style format is required and must be surrounded by " "s.
// (Below, each string contains two format units)
static const char *const add_strings[] ALIGN_PTR = {
"16/1 \" %3_u\"" "\"\n\"", /* 0: a */
"8/2 \" %06o\"" "\"\n\"", /* 1: B (undocumented in od), o */
"16/1 \" %03o\"" "\"\n\"", /* 2: b */
"16/1 \" %3_c\"" "\"\n\"", /* 3: c */
"8/2 \" %5u\"" "\"\n\"", /* 4: d */
"4/4 \" %10u\"" "\"\n\"", /* 5: D */
"2/8 \" %24.14e\"" "\"\n\"", /* 6: e (undocumented in od), F */
"4/4 \" %15.7e\"" "\"\n\"", /* 7: f */
"4/4 \" %08x\"" "\"\n\"", /* 8: H, X */
"8/2 \" %04x\"" "\"\n\"", /* 9: h, x */
"4/4 \" %11d\"" "\"\n\"", /* 10: i */
"4/4 \" %011o\"" "\"\n\"", /* 11: O */
"8/2 \" %6d\"" "\"\n\"", /* 12: s */
/* -I,L,l: depend on word width of the arch (what is "long"?) */
#if ULONG_MAX > 0xffffffff
"2/8 \" %20lld\"" "\"\n\"", /* 13: I, L, l */
#define L_ 13
#else
/* 32-bit arch: -I,L,l are the same as -i */
#define L_ 10
#endif
};
static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv";
static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv";
static const char od_o2si[] ALIGN1 = {
0, 1, 2, 3, 5,
4, 6, 6, 7, 8,
9, 0xa, 0xb, 0xa, 0xa,
0xb, 1, 8, 9,
0, 1, 2, 3, 5, /* aBbcD */
4, 6, 6, 7, 8, /* deFfH */
9, L_, 10, L_, L_, /* hIiLl */
11, 1, 8, 9, 12 /* OoXxs */
};
int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@ -184,19 +207,21 @@ int od_main(int argc, char **argv)
if (first) {
first = 0;
bb_dump_add(dumper, "\"%07.7_Ao\n\"");
bb_dump_add(dumper, "\"%07.7_ao \"");
bb_dump_add(dumper, "\"%07.7_ao\"");
} else {
bb_dump_add(dumper, "\" \"");
bb_dump_add(dumper, "\" \"");
}
bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]);
} else { /* P, p, s, w, or other unhandled */
} else { /* P, p, w, or other unhandled */
bb_show_usage();
}
}
if (!dumper->fshead) {
bb_dump_add(dumper, "\"%07.7_Ao\n\"");
bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\"");
bb_dump_add(dumper, "\"%07.7_ao\"");
bb_dump_add(dumper, add_strings[1]); /* -o format is default */
}
dumper->od_eofstring = "\n";
argc -= optind;
argv += optind;
@ -205,7 +230,7 @@ int od_main(int argc, char **argv)
return bb_dump_dump(dumper, argv);
}
#endif /* ENABLE_DESKTOP */
#endif /* !ENABLE_DESKTOP */
/*-
* Copyright (c) 1990 The Regents of the University of California.

View File

@ -27,6 +27,8 @@
//usage:#if ENABLE_DESKTOP
//usage:#define od_trivial_usage
//usage: "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE]..."
// We also support -BDOHXIL, but they are not documented in coreutils 9.1
// manpage/help, so don't show them either.
// We don't support:
// ... [FILE] [[+]OFFSET[.][b]]
// Support is buggy for:
@ -43,26 +45,33 @@ enum {
OPT_b = 1 << 3,
OPT_c = 1 << 4,
OPT_d = 1 << 5,
OPT_f = 1 << 6,
OPT_h = 1 << 7,
OPT_i = 1 << 8,
OPT_j = 1 << 9,
OPT_l = 1 << 10,
OPT_o = 1 << 11,
OPT_t = 1 << 12,
OPT_D = 1 << 6, /* undocumented in coreutils 9.1 */
OPT_f = 1 << 7,
OPT_h = 1 << 8,
OPT_H = 1 << 9, /* undocumented in coreutils 9.1 */
OPT_i = 1 << 10,
OPT_I = 1 << 11, /* undocumented in coreutils 9.1 */
OPT_j = 1 << 12,
OPT_l = 1 << 13,
OPT_L = 1 << 14, /* undocumented in coreutils 9.1 */
OPT_o = 1 << 15,
OPT_O = 1 << 16, /* undocumented in coreutils 9.1 */
OPT_B = 1 << 17, /* undocumented synonym to -o */
OPT_t = 1 << 18,
/* When zero and two or more consecutive blocks are equal, format
only the first block and output an asterisk alone on the following
line to indicate that identical blocks have been elided: */
OPT_v = 1 << 13,
OPT_x = 1 << 14,
OPT_s = 1 << 15,
OPT_S = 1 << 16,
OPT_w = 1 << 17,
OPT_traditional = (1 << 18) * ENABLE_LONG_OPTS,
OPT_v = 1 << 19,
OPT_x = 1 << 20,
OPT_X = 1 << 21, /* undocumented in coreutils 9.1 */
OPT_s = 1 << 22,
OPT_S = 1 << 23,
OPT_w = 1 << 24,
OPT_traditional = (1 << 25) * ENABLE_LONG_OPTS,
};
#define OD_GETOPT32() getopt32long(argv, \
"A:N:abcdfhij:lot:*vxsS:w:+:", od_longopts, \
"A:N:abcdDfhHiIj:lLoOBt:*vxXsS:w:+:", od_longopts, \
/* -w with optional param */ \
/* -S was -s and also had optional parameter */ \
/* but in coreutils 6.3 it was renamed and now has */ \
@ -1239,20 +1248,29 @@ int od_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_N) {
max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes);
}
if (opt & OPT_a) decode_format_string("a");
if (opt & OPT_b) decode_format_string("oC");
if (opt & OPT_c) decode_format_string("c");
if (opt & OPT_d) decode_format_string("u2");
if (opt & OPT_D) decode_format_string("uI");
if (opt & OPT_f) decode_format_string("fF");
if (opt & OPT_h) decode_format_string("x2");
if (opt & OPT_i) decode_format_string("d2");
if (opt & (OPT_h|OPT_x)) decode_format_string("x2");
if (opt & (OPT_H|OPT_X)) decode_format_string("xI");
/* -I,L,l: depend on word width of the arch (what is "long"?) */
#if ULONG_MAX > 0xffffffff
if (opt & OPT_i) decode_format_string("dI");
if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("dL");
#else
/* 32-bit arch: -I,L,l are the same as -i */
if (opt & (OPT_i|OPT_I|OPT_l|OPT_L)) decode_format_string("dI");
#endif
if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes);
if (opt & OPT_l) decode_format_string("d4");
if (opt & OPT_o) decode_format_string("o2");
if (opt & (OPT_o|OPT_B)) decode_format_string("o2");
if (opt & OPT_O) decode_format_string("oI");
while (lst_t) {
decode_format_string(llist_pop(&lst_t));
}
if (opt & OPT_x) decode_format_string("x2");
if (opt & OPT_s) decode_format_string("d2");
if (opt & OPT_S) {
G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PASTE
//config: bool "paste (4.9 kb)"
//config: bool "paste (5.1 kb)"
//config: default y
//config: help
//config: paste is used to paste lines of different files together

View File

@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PRINTENV
//config: bool "printenv (1.3 kb)"
//config: bool "printenv (1.6 kb)"
//config: default y
//config: help
//config: printenv is used to print all or part of environment.

View File

@ -38,7 +38,7 @@
/* 19990508 Busy Boxed! Dave Cinege */
//config:config PRINTF
//config: bool "printf (3.8 kb)"
//config: bool "printf (4.1 kb)"
//config: default y
//config: help
//config: printf is used to format and print specified strings.
@ -313,7 +313,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
}
break;
}
if (*f && strchr("-+ #", *f)) {
while (*f && strchr("-+ #0", *f)) {
++f;
++direc_length;
}
@ -425,10 +425,10 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
/* bash builtin errors out on "printf '-%s-\n' foo",
* coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo".
* We will mimic coreutils. */
if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
argv++;
if (!argv[1]) {
if (ENABLE_ASH_PRINTF
argv = skip_dash_dash(argv);
if (!argv[0]) {
if ((ENABLE_ASH_PRINTF || ENABLE_HUSH_PRINTF)
&& applet_name[0] != 'p'
) {
bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]");
@ -437,8 +437,8 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
}
format = argv[1];
argv2 = argv + 2;
format = argv[0];
argv2 = argv + 1;
conv_err = 0;
do {

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PWD
//config: bool "pwd (3.7 kb)"
//config: bool "pwd (4 kb)"
//config: default y
//config: help
//config: pwd is used to print the current directory.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config READLINK
//config: bool "readlink (4 kb)"
//config: bool "readlink (4.8 kb)"
//config: default y
//config: help
//config: This program reads a symbolic link and returns the name
@ -25,12 +25,14 @@
//kbuild:lib-$(CONFIG_READLINK) += readlink.o
//usage:#define readlink_trivial_usage
//usage: IF_FEATURE_READLINK_FOLLOW("[-fnv] ") "FILE"
//usage: IF_FEATURE_READLINK_FOLLOW("[-fnv] ")
//usage: IF_NOT_FEATURE_READLINK_FOLLOW("[-n] ")
//usage: "FILE"
//usage:#define readlink_full_usage "\n\n"
//usage: "Display the value of a symlink"
//usage: IF_FEATURE_READLINK_FOLLOW( "\n"
//usage: "\n -f Canonicalize by following all symlinks"
//usage: "Display the value of a symlink" "\n"
//usage: "\n -n Don't add newline"
//usage: IF_FEATURE_READLINK_FOLLOW(
//usage: "\n -f Canonicalize by following all symlinks"
//usage: "\n -v Verbose"
//usage: )
@ -66,35 +68,27 @@ int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int readlink_main(int argc UNUSED_PARAM, char **argv)
{
char *buf;
char *fname;
unsigned opt;
IF_FEATURE_READLINK_FOLLOW(
unsigned opt;
/* We need exactly one non-option argument. */
opt = getopt32(argv, "^" "fnvsq" "\0" "=1");
fname = argv[optind];
)
IF_NOT_FEATURE_READLINK_FOLLOW(
const unsigned opt = 0;
if (argc != 2) bb_show_usage();
fname = argv[1];
)
/* -n must use bit 0 (see printf below) */
opt = getopt32(argv, "^" "n" IF_FEATURE_READLINK_FOLLOW("fvsq")
"\0" "=1");
/* compat: coreutils readlink reports errors silently via exit code */
if (!(opt & 4)) /* not -v */
logmode = LOGMODE_NONE;
/* NOFORK: only one alloc is allowed; must free */
if (opt & 1) { /* -f */
buf = xmalloc_realpath_coreutils(fname);
if (opt & 2) { /* -f */
buf = xmalloc_realpath_coreutils(argv[optind]);
} else {
buf = xmalloc_readlink_or_warn(fname);
buf = xmalloc_readlink_or_warn(argv[optind]);
}
if (!buf)
return EXIT_FAILURE;
printf((opt & 2) ? "%s" : "%s\n", buf);
printf("%s%s", buf, &"\n"[opt & 1]);
free(buf);
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}

View File

@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config REALPATH
//config: bool "realpath (1.6 kb)"
//config: bool "realpath (2.5 kb)"
//config: default y
//config: help
//config: Return the canonicalized absolute pathname.

View File

@ -11,7 +11,7 @@
* Size reduction.
*/
//config:config RM
//config: bool "rm (5.4 kb)"
//config: bool "rm (5.5 kb)"
//config: default y
//config: help
//config: rm is used to remove files or directories.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RMDIR
//config: bool "rmdir (3.5 kb)"
//config: bool "rmdir (3.8 kb)"
//config: default y
//config: help
//config: rmdir is used to remove empty directories.

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SEQ
//config: bool "seq (3.8 kb)"
//config: bool "seq (4 kb)"
//config: default y
//config: help
//config: print a sequence of numbers
@ -22,7 +22,7 @@
//usage:#define seq_full_usage "\n\n"
//usage: "Print numbers from FIRST to LAST, in steps of INC.\n"
//usage: "FIRST, INC default to 1.\n"
//usage: "\n -w Pad to last with leading zeros"
//usage: "\n -w Pad with leading zeros"
//usage: "\n -s SEP String separator"
#include "libbb.h"
@ -41,6 +41,7 @@ int seq_main(int argc, char **argv)
unsigned width;
unsigned frac_part;
const char *sep, *opt_s = "\n";
char *saved;
unsigned opt;
#if ENABLE_LOCALE_SUPPORT
@ -49,7 +50,29 @@ int seq_main(int argc, char **argv)
setlocale(LC_NUMERIC, "C");
#endif
opt = getopt32(argv, "+ws:", &opt_s);
/* Cater for negative arguments: if we see one, truncate argv[] on it */
n = 0;
for (;;) {
char c;
saved = argv[++n];
if (!saved)
break;
if (saved[0] != '-') {
// break; // "seq -s : -1 1" won't be treated correctly
continue;
}
// "seq -s -1 1 9" is not treated correctly, but such usage
// (delimiter string which looks like negative number) is very unlikely
c = saved[1];
if (c == '.' || (c >= '0' && c <= '9')) {
argv[n] = NULL;
break;
}
}
opt = getopt32(argv, "+ws:", &opt_s); /* "+": stop at first non-option */
/* Restore possibly truncated argv[] */
argv[n] = saved;
argc -= optind;
argv += optind;
first = increment = 1;

View File

@ -5,7 +5,7 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SHRED
//config: bool "shred (4.9 kb)"
//config: bool "shred (5.5 kb)"
//config: default y
//config: help
//config: Overwrite a file to hide its contents, and optionally delete it

View File

@ -7,7 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SHUF
//config: bool "shuf (5.4 kb)"
//config: bool "shuf (6 kb)"
//config: default y
//config: help
//config: Generate random permutations
@ -17,14 +17,14 @@
//kbuild:lib-$(CONFIG_SHUF) += shuf.o
//usage:#define shuf_trivial_usage
//usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]"
//usage: "[-n NUM] [-o FILE] [-z] [FILE | -e [ARG...] | -i L-H]"
//usage:#define shuf_full_usage "\n\n"
//usage: "Randomly permute lines\n"
//usage: "\n -e Treat ARGs as lines"
//usage: "\n -i L-H Treat numbers L-H as lines"
//usage: "\n -n NUM Output at most NUM lines"
//usage: "\n -o FILE Write to FILE, not standard output"
//usage: "\n -z End lines with zero byte, not newline"
//usage: "\n -z NUL terminated output"
//usage: "\n -e Treat ARGs as lines"
//usage: "\n -i L-H Treat numbers L-H as lines"
#include "libbb.h"
@ -39,36 +39,54 @@
/*
* Use the Fisher-Yates shuffle algorithm on an array of lines.
* If the required number of output lines is less than the total
* we can stop shuffling early.
*/
static void shuffle_lines(char **lines, unsigned numlines)
static void shuffle_lines(char **lines, unsigned numlines, unsigned outlines)
{
unsigned i;
unsigned r;
char *tmp;
srand(monotonic_us());
for (i = numlines-1; i > 0; i--) {
r = rand();
while (outlines != 0) {
char *tmp;
unsigned r = rand();
/* RAND_MAX can be as small as 32767 */
if (i > RAND_MAX)
if (numlines > RAND_MAX)
r ^= rand() << 15;
r %= i + 1;
tmp = lines[i];
lines[i] = lines[r];
r %= numlines;
//TODO: the above method is seriously non-uniform when numlines is very large.
//For example, with numlines of 0xf0000000,
//values of (r % numlines) in [0, 0x0fffffff] range
//are more likely: e.g. r=1 and r=0xf0000001 both map to 1,
//whereas only one value, r=0xefffffff, maps to 0xefffffff.
numlines--;
tmp = lines[numlines];
lines[numlines] = lines[r];
lines[r] = tmp;
outlines--;
}
}
/* We can handle insanity like this:
* shuf -i 333333333333333333333333333333001-333333333333333333333333333333019
* but do we want to have +200 bytes of code (~40% code growth)?
*/
#define COMMON_PREFIX_HACK 0
int shuf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int shuf_main(int argc, char **argv)
{
unsigned opts;
char *opt_i_str, *opt_n_str, *opt_o_str;
unsigned i;
char **lines;
unsigned numlines;
unsigned long long lo = lo;
unsigned numlines, outlines;
unsigned i;
char eol;
#if COMMON_PREFIX_HACK
unsigned pfx_len = 0;
unsigned padding_width = padding_width;
const char *pfx = pfx;
#endif
opts = getopt32(argv, "^"
OPT_STR
@ -87,35 +105,78 @@ int shuf_main(int argc, char **argv)
} else
if (opts & OPT_i) {
/* create a range of numbers */
unsigned long long hi;
char *dash;
unsigned lo, hi;
if (argv[0])
bb_show_usage();
dash = strchr(opt_i_str, '-');
if (!dash) {
bb_error_msg_and_die("bad range '%s'", opt_i_str);
}
*dash = '\0';
lo = xatou(opt_i_str);
hi = xatou(dash + 1);
*dash = '-';
if (hi < lo) {
*dash++ = '\0';
#if COMMON_PREFIX_HACK
{
const char *a = opt_i_str;
const char *b = dash;
/* Skip leading zeros (they may mask that common prefix does exist) */
while (*a == '0') a++;
while (*b == '0') b++;
/* Do we have a common prefix (long enough to bother)? */
padding_width = strlen(a);
if (padding_width > 5 && padding_width == strlen(b)) {
/* How long is it? */
pfx = a;
while (isdigit(*a) && *a == *b
&& a[1] /* "111111-111111" case: avoid xatoull("") */
) {
a++;
b++;
}
pfx_len = a - pfx; /* can end up being 0 */
padding_width -= pfx_len;
} else {
/* Undo leading zero 'eating' (think "0-9") */
a = opt_i_str;
b = dash;
}
lo = xatoull(a);
hi = xatoull(b);
}
#else
lo = xatoull(opt_i_str);
hi = xatoull(dash);
#endif
dash[-1] = '-';
if (hi < lo)
bb_error_msg_and_die("bad range '%s'", opt_i_str);
hi -= lo;
if (sizeof(size_t) > sizeof(numlines)) {
if (hi >= UINT_MAX)
bb_error_msg_and_die("bad range '%s'", opt_i_str);
} else {
if (hi >= UINT_MAX / sizeof(lines[0]))
bb_error_msg_and_die("bad range '%s'", opt_i_str);
}
numlines = (hi+1) - lo;
lines = xmalloc(numlines * sizeof(lines[0]));
numlines = hi + 1;
lines = xmalloc((size_t)numlines * sizeof(lines[0]));
for (i = 0; i < numlines; i++) {
lines[i] = (char*)(uintptr_t)lo;
lo++;
lines[i] = (char*)(uintptr_t)i;
}
} else {
/* default - read lines from stdin or the input file */
FILE *fp;
const char *fname = "-";
if (argc > 1)
bb_show_usage();
if (argv[0]) {
if (argv[1])
bb_show_usage();
fname = argv[0];
}
fp = xfopen_stdin(argv[0] ? argv[0] : "-");
fp = xfopen_stdin(fname);
lines = NULL;
numlines = 0;
for (;;) {
@ -128,29 +189,33 @@ int shuf_main(int argc, char **argv)
fclose_if_not_stdin(fp);
}
if (numlines != 0)
shuffle_lines(lines, numlines);
outlines = numlines;
if (opts & OPT_n) {
outlines = xatou(opt_n_str);
if (outlines > numlines)
outlines = numlines;
}
shuffle_lines(lines, numlines, outlines);
if (opts & OPT_o)
xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
if (opts & OPT_n) {
unsigned maxlines;
maxlines = xatou(opt_n_str);
if (numlines > maxlines)
numlines = maxlines;
}
eol = '\n';
if (opts & OPT_z)
eol = '\0';
for (i = 0; i < numlines; i++) {
if (opts & OPT_i)
printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
else
for (i = numlines - outlines; i < numlines; i++) {
if (opts & OPT_i) {
#if COMMON_PREFIX_HACK
if (pfx_len != 0)
printf("%.*s%0*llu%c", pfx_len, pfx, padding_width, lo + (uintptr_t)lines[i], eol);
else
#endif
printf("%llu%c", lo + (uintptr_t)lines[i], eol);
} else
printf("%s%c", lines[i], eol);
}
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}

View File

@ -13,18 +13,19 @@
* time suffixes for seconds, minutes, hours, and days.
*/
//config:config SLEEP
//config: bool "sleep (2 kb)"
//config: bool "sleep (2.4 kb)"
//config: default y
//config: help
//config: sleep is used to pause for a specified number of seconds.
//config: It comes in 3 versions:
//config: It comes in 2 versions:
//config: - small: takes one integer parameter
//config: - fancy: takes multiple integer arguments with suffixes:
//config: sleep 1d 2h 3m 15s
//config: - fancy with fractional numbers:
//config: sleep 2.3s 4.5h sleeps for 16202.3 seconds
//config: Last one is "the most compatible" with coreutils sleep,
//config: but it adds around 1k of code.
//config: - fancy:
//config: * takes multiple integer arguments with suffixes:
//config: sleep 1d 2h 3m 15s
//config: * allows fractional numbers:
//config: sleep 2.3s 4.5h sleeps for 16202.3 seconds
//config: fancy is more compatible with coreutils sleep, but it adds around
//config: 1k of code.
//config:
//config:config FEATURE_FANCY_SLEEP
//config: bool "Enable multiple arguments and s/m/h/d suffixes"
@ -37,6 +38,7 @@
//applet:IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SLEEP) += sleep.o
//kbuild:lib-$(CONFIG_ASH_SLEEP) += sleep.o
/* BB_AUDIT SUSv3 compliant */
/* BB_AUDIT GNU issues -- fancy version matches except args must be ints. */
@ -64,15 +66,29 @@ int sleep_main(int argc UNUSED_PARAM, char **argv)
{
duration_t duration;
++argv;
if (!*argv)
/* Note: sleep_main may be directly called from ash as a builtin.
* This brings some complications:
* + we can't use xfunc here
* + we can't use bb_show_usage
* + applet_name can be the name of the shell
*/
argv = skip_dash_dash(argv);
if (!argv[0]) {
/* Without this, bare "sleep" in ash shows _ash_ --help */
/* (ash can be the "sh" applet as well, so check 2nd char) */
if (ENABLE_ASH_SLEEP && applet_name[1] != 'l') {
bb_simple_error_msg("sleep: missing operand");
return EXIT_FAILURE;
}
bb_show_usage();
}
/* GNU sleep accepts "inf", "INF", "infinity" and "INFINITY" */
if (strncasecmp(argv[0], "inf", 3) == 0)
for (;;)
sleep(INT_MAX);
//FIXME: in ash, "sleep 123qwerty" as a builtin aborts the shell
#if ENABLE_FEATURE_FANCY_SLEEP
duration = 0;
do {

View File

@ -12,13 +12,13 @@
* http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
*/
//config:config SORT
//config: bool "sort (7.7 kb)"
//config: bool "sort (8.1 kb)"
//config: default y
//config: help
//config: sort is used to sort lines of text in specified files.
//config:
//config:config FEATURE_SORT_BIG
//config: bool "Full SuSv3 compliant sort (support -ktcbdfiogM)"
//config: bool "Full SuSv3 compliant sort (support -ktcbdfioghM)"
//config: default y
//config: depends on SORT
//config: help
@ -43,7 +43,7 @@
//usage:#define sort_trivial_usage
//usage: "[-nru"
//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k START[.OFS][OPTS][,END[.OFS][OPTS]] [-t CHAR")
//usage: IF_FEATURE_SORT_BIG("ghMcszbdfiokt] [-o FILE] [-k START[.OFS][OPTS][,END[.OFS][OPTS]] [-t CHAR")
//usage: "] [FILE]..."
//usage:#define sort_full_usage "\n\n"
//usage: "Sort lines of text\n"
@ -59,6 +59,7 @@
//usage: "\n -n Sort numbers"
//usage: IF_FEATURE_SORT_BIG(
//usage: "\n -g General numerical sort"
//usage: "\n -h Sort human readable numbers (2K 1G)"
//usage: "\n -M Sort month"
//usage: "\n -V Sort version"
//usage: "\n -t CHAR Field separator"
@ -94,31 +95,32 @@
enum {
FLAG_n = 1 << 0, /* Numeric sort */
FLAG_g = 1 << 1, /* Sort using strtod() */
FLAG_M = 1 << 2, /* Sort date */
FLAG_V = 1 << 3, /* Sort version */
FLAG_h = 1 << 2, /* Sort using strtod(), plus KMGT suffixes */
FLAG_M = 1 << 3, /* Sort date */
FLAG_V = 1 << 4, /* Sort version */
/* ucsz apply to root level only, not keys. b at root level implies bb */
FLAG_u = 1 << 4, /* Unique */
FLAG_c = 1 << 5, /* Check: no output, exit(!ordered) */
FLAG_s = 1 << 6, /* Stable sort, no ascii fallback at end */
FLAG_z = 1 << 7, /* Input and output is NUL terminated, not \n */
FLAG_u = 1 << 5, /* Unique */
FLAG_c = 1 << 6, /* Check: no output, exit(!ordered) */
FLAG_s = 1 << 7, /* Stable sort, no ascii fallback at end */
FLAG_z = 1 << 8, /* Input and output is NUL terminated, not \n */
/* These can be applied to search keys, the previous four can't */
FLAG_b = 1 << 8, /* Ignore leading blanks */
FLAG_r = 1 << 9, /* Reverse */
FLAG_d = 1 << 10, /* Ignore !(isalnum()|isspace()) */
FLAG_f = 1 << 11, /* Force uppercase */
FLAG_i = 1 << 12, /* Ignore !isprint() */
FLAG_m = 1 << 13, /* ignored: merge already sorted files; do not sort */
FLAG_S = 1 << 14, /* ignored: -S, --buffer-size=SIZE */
FLAG_T = 1 << 15, /* ignored: -T, --temporary-directory=DIR */
FLAG_o = 1 << 16,
FLAG_k = 1 << 17,
FLAG_t = 1 << 18,
FLAG_b = 1 << 9, /* Ignore leading blanks */
FLAG_r = 1 << 10, /* Reverse */
FLAG_d = 1 << 11, /* Ignore !(isalnum()|isspace()) */
FLAG_f = 1 << 12, /* Force uppercase */
FLAG_i = 1 << 13, /* Ignore !isprint() */
FLAG_m = 1 << 14, /* ignored: merge already sorted files; do not sort */
FLAG_S = 1 << 15, /* ignored: -S, --buffer-size=SIZE */
FLAG_T = 1 << 16, /* ignored: -T, --temporary-directory=DIR */
FLAG_o = 1 << 17,
FLAG_k = 1 << 18,
FLAG_t = 1 << 19,
FLAG_bb = 0x80000000, /* Ignore trailing blanks */
FLAG_no_tie_break = 0x40000000,
};
static const char sort_opt_str[] ALIGN1 = "^"
"ngMVucszbrdfimS:T:o:k:*t:"
"nghMVucszbrdfimS:T:o:k:*t:"
"\0" "o--o:t--t"/*-t, -o: at most one of each*/;
/*
* OPT_STR must not be string literal, needs to have stable address:
@ -253,6 +255,25 @@ static struct sort_key *add_key(void)
#define GET_LINE(fp) xmalloc_fgetline(fp)
#endif
#if ENABLE_FEATURE_SORT_BIG
static int scale_suffix(const char *tail)
{
static const char suffix[] ALIGN1 = "kmgtpezy";
const char *s;
int n;
if (!tail[0])
return -1;
s = strchr(suffix, tail[0] | 0x20);
if (!s)
return -1;
n = s - suffix;
if (n != 0 && tail[0] >= 'a')
return -1; /* mg... not accepted, only MG... */
return n;
}
#endif
/* Iterate through keys list and perform comparisons */
static int compare_keys(const void *xarg, const void *yarg)
{
@ -275,7 +296,7 @@ static int compare_keys(const void *xarg, const void *yarg)
y = *(char **)yarg;
#endif
/* Perform actual comparison */
switch (flags & (FLAG_n | FLAG_g | FLAG_M | FLAG_V)) {
switch (flags & (FLAG_n | FLAG_g | FLAG_h | FLAG_M | FLAG_V)) {
default:
bb_simple_error_msg_and_die("unknown sort type");
break;
@ -293,7 +314,8 @@ static int compare_keys(const void *xarg, const void *yarg)
#endif
break;
#if ENABLE_FEATURE_SORT_BIG
case FLAG_g: {
case FLAG_g:
case FLAG_h: {
char *xx, *yy;
//TODO: needs setlocale(LC_NUMERIC, "C")?
double dx = strtod(x, &xx);
@ -308,16 +330,26 @@ static int compare_keys(const void *xarg, const void *yarg)
retval = (dy != dy) ? 0 : -1;
else if (dy != dy)
retval = 1;
/* Check for infinity. Could underflow, but it avoids libm. */
else if (1.0 / dx == 0.0) {
if (dx < 0)
retval = (1.0 / dy == 0.0 && dy < 0) ? 0 : -1;
else {
if (flags & FLAG_h) {
int xs = scale_suffix(xx);
int ys = scale_suffix(yy);
if (xs != ys) {
retval = xs - ys;
break;
}
}
/* Check for infinity. Could underflow, but it avoids libm. */
if (1.0 / dx == 0.0) {
if (dx < 0)
retval = (1.0 / dy == 0.0 && dy < 0) ? 0 : -1;
else
retval = (1.0 / dy == 0.0 && dy > 0) ? 0 : 1;
} else if (1.0 / dy == 0.0)
retval = (dy < 0) ? 1 : -1;
else
retval = (1.0 / dy == 0.0 && dy > 0) ? 0 : 1;
} else if (1.0 / dy == 0.0)
retval = (dy < 0) ? 1 : -1;
else
retval = (dx > dy) ? 1 : ((dx < dy) ? -1 : 0);
retval = (dx > dy) ? 1 : ((dx < dy) ? -1 : 0);
}
break;
}
case FLAG_M: {
@ -325,9 +357,9 @@ static int compare_keys(const void *xarg, const void *yarg)
int dx;
char *xx, *yy;
xx = strptime(x, "%b", &thyme);
xx = strptime(skip_whitespace(x), "%b", &thyme);
dx = thyme.tm_mon;
yy = strptime(y, "%b", &thyme);
yy = strptime(skip_whitespace(y), "%b", &thyme);
if (!xx)
retval = (!yy) ? 0 : -1;
else if (!yy)
@ -380,7 +412,9 @@ static int compare_keys(const void *xarg, const void *yarg)
/* If x > y, 1, else -1 */
retval = (x32 > y32) * 2 - 1;
} else
/* Here, -r has no effect! */
return retval;
}
if (!(option_mask32 & FLAG_no_tie_break)) {
/* fallback sort */
flags = option_mask32;
@ -474,6 +508,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
FLAG_allowed_for_k =
FLAG_n | /* Numeric sort */
FLAG_g | /* Sort using strtod() */
FLAG_h | /* Sort using strtod(), plus KMGT suffixes */
FLAG_M | /* Sort date */
FLAG_b | /* Ignore leading blanks */
FLAG_r | /* Reverse */
@ -617,11 +652,12 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
/* Handle -u */
if (option_mask32 & FLAG_u) {
int j = 0;
/* coreutils 6.3 drop lines for which only key is the same
* -- disabling last-resort compare, or else compare_keys()
* will be the same only for completely identical lines.
/* coreutils 6.3 drop lines for which only key is the same:
* - disabling last-resort compare, or else compare_keys()
* will be the same only for completely identical lines
* - disabling -s (same reasons)
*/
option_mask32 |= FLAG_no_tie_break;
option_mask32 = (option_mask32 | FLAG_no_tie_break) & (~FLAG_s);
for (i = 1; i < linecount; i++) {
if (compare_keys(&lines[j], &lines[i]) == 0)
free(lines[i]);
@ -644,5 +680,5 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
printf("%s%c", lines[i], ch);
}
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit_SUCCESS();
}

View File

@ -6,7 +6,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SPLIT
//config: bool "split (5 kb)"
//config: bool "split (5.2 kb)"
//config: default y
//config: help
//config: Split a file into pieces.

View File

@ -339,7 +339,8 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
strcat(pformat, "lo");
printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)));
} else if (m == 'A') {
printfs(pformat, bb_mode_string(statbuf->st_mode));
char modestr[12];
printfs(pformat, bb_mode_string(modestr, statbuf->st_mode));
} else if (m == 'f') {
strcat(pformat, "lx");
printf(pformat, (unsigned long) statbuf->st_mode);
@ -702,6 +703,7 @@ static bool do_stat(const char *filename, const char *format)
bb_putchar('\n');
# endif
} else {
char modestr[12];
char *linkname = NULL;
struct passwd *pw_ent;
struct group *gw_ent;
@ -736,7 +738,7 @@ static bool do_stat(const char *filename, const char *format)
bb_putchar('\n');
printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n",
(unsigned long) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)),
bb_mode_string(statbuf.st_mode),
bb_mode_string(modestr, statbuf.st_mode),
(unsigned long) statbuf.st_uid,
(pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN",
(unsigned long) statbuf.st_gid,

View File

@ -10,7 +10,7 @@
* Special for busybox ported by Vladimir Oleynik <dzo@simtreas.ru> 2001
*/
//config:config STTY
//config: bool "stty (8.9 kb)"
//config: bool "stty (9.2 kb)"
//config: default y
//config: help
//config: stty is used to change and print terminal line settings.

View File

@ -13,7 +13,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SUM
//config: bool "sum (4 kb)"
//config: bool "sum (4.2 kb)"
//config: default y
//config: help
//config: checksum and count the blocks in a file

View File

@ -8,7 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SYNC
//config: bool "sync (3.8 kb)"
//config: bool "sync (4 kb)"
//config: default y
//config: help
//config: sync is used to flush filesystem buffers.
@ -113,7 +113,7 @@ int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FSYNC
//config: bool "fsync (3.6 kb)"
//config: bool "fsync (3.8 kb)"
//config: default y
//config: help
//config: fsync is used to flush file-related cached blocks to disk.

Some files were not shown because too many files have changed in this diff Show More