Commit graph

18105 commits

Author SHA1 Message Date
Denys Vlasenko
1ef0c69db4 vmstat: fix "vmstat N 0" to act compatibly (do not print infinitely)
function                                             old     new   delta
vmstat_main                                          559     561      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-19 02:52:06 +01:00
Denys Vlasenko
afb92adf47 vmstat: smarter handling of header re-printing
function                                             old     new   delta
vmstat_main                                          230     559    +329
print_row                                            340       -    -340
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 329/-340)          Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-19 02:16:10 +01:00
Denys Vlasenko
fd2ce3fa27 vmstat: show shorter, human-readable accumulating counts if they grow large
function                                             old     new   delta
print_row                                            247     340     +93
.rodata                                           106717  106716      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 93/-1)              Total: 92 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 18:57:37 +01:00
Denys Vlasenko
6ba6f5f6ab vmstat: reduce the chances of misaligned columns
function                                             old     new   delta
print_row                                            215     247     +32

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 18:09:12 +01:00
Denys Vlasenko
c21d8ff8c5 vmstat: code shrink
function                                             old     new   delta
load_row                                             667     661      -6
next_col                                             105      59     -46
coldescs                                             239     146     -93
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-145)           Total: -145 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 16:51:35 +01:00
David Leonard
c385dac31c procps: new applet: vmstat
Adds a compact vmstat applet that matches the default behaviour
of procps's vmstat.

function                                             old     new   delta
load_row                                               -     667    +667
.rodata                                           106441  106717    +276
coldescs                                               -     239    +239
vmstat_main                                            -     230    +230
print_row                                              -     215    +215
next_col                                               -     105    +105
find_col                                               -      78     +78
packed_usage                                       35828   35868     +40
applet_names                                        2849    2856      +7
applet_main                                         1640    1644      +4
applet_install_loc                                   205     206      +1
------------------------------------------------------------------------------
(add/remove: 7/0 grow/shrink: 5/0 up/down: 1862/0)           Total: 1862 bytes

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 10:58:46 +01:00
Achill Gilgenast
6f43f948bc adduser: remove preconfigured GECOS full name field
Pre-configuring "Linux User" as Full Name is confusing a lot of users
downstream.[1] For example, in geary e-mails were sent out as "Linux
User"[2] and I also saw a couple of git commits with this name. This name
does not bring any more improvements than just leaving this field
empty, and let applications most likely fallback to the username.

Alternative would be to set the field to `&` (Capitalized username,
according to passwd(5)) or that we just set the GECOS field downstream.

[1] https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2214
[2] https://gitlab.gnome.org/GNOME/geary/-/issues/1486

function                                             old     new   delta
.rodata                                           106455  106441     -14

Signed-off-by: Achill Gilgenast <achill@achill.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 03:17:00 +01:00
Martin Storsjö
993d416d02 md5/sha1sum: Honor the -b flag in the output
The output of md5sum/sha1sum contains a character to indicate
what mode was used to read the file - '*' for binary, and ' '
for text or where binary is insignificant.

This flag character makes a difference for the ffmpeg testsuite.
This testsuite contains a number of reference files (e.g. [1]),
containing the expected md5sum output for those files, which is
checked verbatim.

By making busybox's md5sum honor this flag in the output,
ffmpeg's testsuite can run successfully on top of busybox.

The flag is only partially implemented; in coreutils md5sum,
a later "-t" option overrides an earlier "-b" option. Here,
just check if a "-b" option was specified or not. Neither
flag affects how the files actually are read.

[1] 894da5ca7d/tests/ref/acodec/flac

Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 03:09:52 +01:00
Denys Vlasenko
fc9d352b4c cmp: fix -n causing all diffs to be output, implement size suffixes for SKIP
function                                             old     new   delta
packed_usage                                       35802   35828     +26
cmp_main                                             616     595     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 26/-21)              Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 02:41:20 +01:00
Giorgi Tchankvetadze
3bfbce8312 cmp: stop skipping bytes if EOF is reached
Currently, if a skip value is larger than the file size, cmp will continue
to loop and call getc() until the skip count is satisfied, even though
EOF has been reached.

For large skip values (e.g., 1 billion), this results in significant
CPU waste and execution time (e.g., 11 seconds on a modern CPU).

This patch checks for EOF inside the skip loop and breaks early.

Test case:
$ touch empty.txt
$ time ./busybox cmp empty.txt empty.txt 1000000000 1000000000

Before:
real    0m10.937s

After:
real    0m0.002s

function                                             old     new   delta
cmp_main                                             594     616     +22

Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 01:41:19 +01:00
Denys Vlasenko
26e9afe22d coreutils: fixes for coreutils/id_test.sh script
Patch from Tito

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-18 01:37:53 +01:00
Giorgi Tchankvetadze
3b785b18d2 networking/udhcp: fix typo in comment
Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2026-01-14 08:08:26 +01:00
Denys Vlasenko
d755846906 xxd: fix -pANYTHING handling (-pc50 does not mean -p -c50)
function                                             old     new   delta
packed_usage                                       35768   35802     +34
xxd_main                                            1447    1449      +2
.rodata                                           106438  106439      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 37/0)               Total: 37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-30 06:13:15 +01:00
Denys Vlasenko
b143b3f1d4 tls: better error message when TLS record is truncated
function                                             old     new   delta
.rodata                                           106388  106438     +50
tls_xread_record                                     650     681     +31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 81/0)               Total: 81 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-25 02:47:10 +01:00
Denys Vlasenko
8d7ae80eda eject: fix missing -s option in trivial usage
Fixes missing [-s] option in trivial usage section of `eject --help`

function                                             old     new   delta
packed_usage                                       35125   35127      +2

Signed-off-by: Nir Lichtman <nir@lichtman.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko
b8cf048880 dd: fix overflow for very large count/seek/skip values
function                                             old     new   delta
xatoull_range_sfx                                      -      49     +49
dd_main                                             1607    1640     +33
bb_banner                                             47      46      -1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 82/-1)              Total: 81 bytes

Signed-off-by: Sertonix <sertonix@posteo.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko
4ee218a2d2 pgrep/pkill: fix -x to also match comm field
When running `pgrep -x example` against a process `/bin/example --arg`,
BusyBox fails to match, while GNU pgrep succeeds. The reason is that the
comparison is done only against the full argv[0] rather than comm. This
patch changes pgrep -x to also try /proc/[pid]/comm for exact matching.

function                                             old     new   delta
pgrep_main                                           681     670     -11

Signed-off-by: Paulius Zaleckas <paulius.zaleckas@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko
d549c8be86 ls: restore functionality of --color
Since commit 551bfdb97 (ls: implement -q, fix -w0, reduce startup
time) the '--color' option behaves as though the default argument
'always' had been specified.

This is due to an explicit short option for '--color' being given,
but without specifying that an argument is expected.

function                                             old     new   delta
.rodata                                           106027  106029      +2

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko
8cafd7a908 lineedit: fix PS1='\W' for root directory
'\W' in PS1 returned an empty string for the root directory.  bash
displays '/' in similar circumstances.

Avoid returning an empty string for the directory.

function                                             old     new   delta
parse_and_put_prompt                                 873     883     +10

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko
782e3fc2b4 last: fix ignoring the first login entry
The first login entry is ignored if a log file contains more than one
entry. To fix it, do not break the while loop if the offset is zero.

Signed-off-by: Dmitry Klochkov <dmitry.klochkov@bell-sw.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-11-08 07:42:34 +01:00
Denys Vlasenko
b99a529177 busybox: optional --version support
function                                             old     new   delta
busybox_main                                         695     734     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-13 21:56:47 +02:00
Denys Vlasenko
3ff3cb483d ntpd: set tmx.maxerror properly - avoid STA_UNSYNC
function                                             old     new   delta
update_local_clock                                   872     951     +79

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-11 23:48:04 +02:00
Denys Vlasenko
3621595939 nsenter,unshare: don't use xvfork_parent_waits_and_exits(), it SEGVs on ppc64le
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-08 14:49:26 +02:00
Denys Vlasenko
a0017a5b50 cp: fix cp -aT overwriting symlink to directories
busybox cp refuses to overwrite another symlink to a directory due to
an incorrect stat() call that should be lstat(). When using -T, we want
to consider the target argument directly without resolving symlinks.

function                                             old     new   delta
cp_main                                              496     514     +18

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko
3cc2460952 chrt: support passing -p 0 to operate on self
Specifying a PID of 0 for the -p option of chrt would previously result
in a "number 0... not in range" error. Now, it means instead that the
calling process (i.e. chrt itself) should be operated on; this is to be
consistent with the behavior of util-linux's version of chrt.

function                                             old     new   delta
chrt_main                                            462     474     +12

Signed-off-by: Zuo An <zuoan.penguin@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko
552003dbd6 selinux: fix potential segfault in sestatus
Remove the puts(cterm) call that was likely leftover debugging code.
The controlling terminal name is already properly displayed via the
'Controlling term:' label, so the raw terminal name output was redundant
and could cause issues when cterm is NULL.

Also add proper cleanup for the allocated cterm string.

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

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko
9443b0bc5e vi: warn about range in ':!' command
Currently vi in Busybox doesn't support filtering text through an
external command with ':1,2!cmd'.  Instead it behaves as if no
range had been supplied and displays the output of the command.

Issue a warning and do nothing in such cases.

function                                             old     new   delta
colon                                               3993    4010     +17

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-10-07 10:05:08 +02:00
Denys Vlasenko
f5e1bf966b archival/libarchive: sanitize filenames on output (prevent control sequence attacks
This fixes CVE-2025-46394 (terminal escape sequence injection)

Original credit: Ian.Norton at entrust.com

function                                             old     new   delta
header_list                                            9      15      +6
header_verbose_list                                  239     244      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-24 03:30:12 +02:00
Denys Vlasenko
381a40a049 ash: change procargs() to match recent dash change
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-23 04:46:49 +02:00
Denys Vlasenko
3681b5f618 hush: changes to comments and whitespace, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-03 13:36:35 +02:00
Denys Vlasenko
106546961d ash: implement <<<here_string syntax
function                                             old     new   delta
write2pipe                                             -     133    +133
.rodata                                           105992  106009     +17
readtoken1                                          3101    3111     +10
cmdtxt                                               631     641     +10
nodesize                                              27      28      +1
redirect                                             961     916     -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 171/-45)           Total: 126 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-09-02 11:46:11 +02:00
Denys Vlasenko
b4cedd4c9a hush: fix several syntax corner cases with function definitions
function                                             old     new   delta
parse_stream                                        3063    3075     +12
done_word                                            777     784      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 19/0)               Total: 19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 14:52:46 +02:00
Denys Vlasenko
5d66c8a602 hush: shrink "function" code
function                                             old     new   delta
done_word                                            766     777     +11
static.reserved_match                                 16      12      -4
reserved_list                                        240     168     -72
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 11/-76)            Total: -65 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 13:55:09 +02:00
Denys Vlasenko
5c2c2916fc hush: do not SEGV on if { echo foo; } then { echo bar; } fi
For some reason, it was only happening in interactive use

function                                             old     new   delta
initialize_context                                    39      54     +15
parse_stream                                        3077    3063     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 15/-14)              Total: 1 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 13:37:09 +02:00
Denys Vlasenko
2bdec03def hush: disentangle keyword detection, no logic changes
function                                             old     new   delta
done_word                                            790     766     -24

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-18 13:14:26 +02:00
Denys Vlasenko
2ccb891819 hush: make "function" keyword support optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 17:59:30 +02:00
Denys Vlasenko
84d4ac3754 hush: with --login, errors /etc/profile in must not exit shell
function                                             old     new   delta
die_if_script                                         28      34      +6
hush_main                                           1146    1150      +4
run_list                                            1031    1028      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 10/-3)               Total: 7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 17:39:04 +02:00
Denys Vlasenko
96466951bf hush: recognize "function FUNC { cmd; }" syntax
function                                             old     new   delta
reserved_list                                          -     240    +240
parse_stream                                        2923    3077    +154
done_word                                            771     790     +19
.rodata                                           105975  105992     +17
static.reserved_match                                 12      16      +4
static.reserved_list                                 168       -    -168
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 4/0 up/down: 434/-168)          Total: 266 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 14:33:00 +02:00
Denys Vlasenko
a30882dec5 hush: remove always-true conditional
function                                             old     new   delta
parse_stream                                        2940    2923     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 13:47:34 +02:00
Denys Vlasenko
36f1b16b05 hush: fix infinite loop expanding alias a="nice&&a"
function                                             old     new   delta
parse_stream                                        2857    2940     +83
i_peek                                                55      69     +14
i_free_alias_buffer                                   33      37      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 101/0)             Total: 101 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 05:03:41 +02:00
Denys Vlasenko
1a947654b5 hush: comment fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 04:17:45 +02:00
Denys Vlasenko
94cb769b65 hush: make "alias" print aliases in properly escaped form
function                                             old     new   delta
print_pfx_escaped_nl                                   -      83     +83
builtin_alias                                        216     218      +2
.rodata                                           105985  105975     -10
parse_stream                                        2873    2857     -16
builtin_set                                          301     259     -42
builtin_readonly                                     107      59     -48
builtin_export                                       145      93     -52
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/5 up/down: 85/-168)           Total: -83 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 04:07:42 +02:00
Denys Vlasenko
7423bbbe98 hush: fix nested alias expansion
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 03:24:13 +02:00
Denys Vlasenko
5ba6ad7733 hush: optional alias support
function                                             old     new   delta
parse_stream                                        2540    2873    +333
i_getch                                               85     410    +325
builtin_alias                                          -     216    +216
builtin_unalias                                        -     185    +185
.rodata                                           105806  105985    +179
word_matches_alias                                     -      82     +82
find_alias_slot                                        -      77     +77
end_of_alias_name                                      -      69     +69
builtin_type                                         128     179     +51
i_free_alias_buffer                                    -      33     +33
enable_all_aliases                                     -      29     +29
bltins1                                              396     420     +24
o_reset_to_empty_unquoted                              -      21     +21
run_pipe                                            1554    1566     +12
i_peek                                                57      55      -2
parse_redirect                                       351     346      -5
redirect_opt_num                                      63      53     -10
encode_then_append_var_plusminus                     552     532     -20
done_word                                            796     771     -25
i_getch_interactive                                  308       -    -308
------------------------------------------------------------------------------
(add/remove: 8/1 grow/shrink: 6/5 up/down: 1636/-370)        Total: 1266 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-17 02:51:35 +02:00
Denys Vlasenko
5806d2a3db hush: optimization in set_local_var()
function                                             old     new   delta
set_local_var                                        416     409      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-16 01:53:46 +02:00
Denys Vlasenko
3e766dce5f hush: implement <<<here_string syntax
function                                             old     new   delta
setup_heredoc                                        299     351     +52
parse_stream                                        2514    2540     +26
parse_redirect                                       335     351     +16
redir_table                                           40      48      +8
static.setup_redirects                               394     400      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 108/0)             Total: 108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-15 00:08:11 +02:00
Denys Vlasenko
0d1f6a54f7 hush: allow faster parsing for "./:@" characters
function                                             old     new   delta
parse_stream                                        2513    2514      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 20:08:19 +02:00
Denys Vlasenko
a8f20420a5 hush: shrink syntax error handling
Was trying to add code to reject more invalid "case" syntaxes, but it's not that easy

function                                             old     new   delta
done_word                                            795     796      +1
parse_stream                                        2529    2513     -16
.rodata                                           105825  105806     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-35)             Total: -34 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 19:47:20 +02:00
Denys Vlasenko
6cc3380105 hush: undo incorrect change which allows a'b'=c to be assignment
While at it, remove now-unused WORD_IS_KEYWORD

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 16:19:58 +02:00
Denys Vlasenko
cad5a79bd4 hush: explain "empty quoted str marker" trick
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-14 12:03:24 +02:00