Commit Graph

995 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Denys Vlasenko
1746218bee move iterate_on_dir() from e2fsprogs to libbb
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-24 11:42:55 +02:00
Denys Vlasenko
56bbbfae7d cp: implement -n
function                                             old     new   delta
.rodata                                           103681  103722     +41
packed_usage                                       33698   33717     +19
copy_file                                           1678    1696     +18
cp_main                                              500     492      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 78/-8)              Total: 70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-22 15:28:34 +02:00
Denys Vlasenko
0ec52d438a cp: implement -t DIR
function                                             old     new   delta
packed_usage                                       33713   33734     +21
.rodata                                           103670  103672      +2
cp_main                                              506     500      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 23/-6)              Total: 17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-21 19:38:39 +02:00
Denys Vlasenko
dc30f3dce2 free: implement -h
function                                             old     new   delta
.rodata                                           103331  103363     +32
packed_usage                                       33652   33654      +2
free_main                                            657     588     -69
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-69)            Total: -35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-18 12:08:02 +02:00
Denys Vlasenko
5dadd497ff runsv: robustify signal handling - SIGTERM to child between vfork and exec could mess things up
While at it, rename bb_signals_recursive_norestart() to bb_signals_norestart():
"recursive" was implying we are setting SA_NODEFER allowing signal handler
to be entered recursively, but we do not do that.

function                                             old     new   delta
bb_signals_norestart                                   -      70     +70
startservice                                         380     394     +14
bb_signals_recursive_norestart                        70       -     -70
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/0 up/down: 84/-70)             Total: 14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-05 16:20:05 +02:00
Sören Tempel
3d9c649158 ls: don't output any colors with TERM=dumb
The TERM variable is usually set to "dumb" to indicate that the terminal
does not support any ANSI escape sequences. Presently, ls does not honor
this variable and outputs colors anyhow which results in unreadable
output, unless the user explicitly disables colors using `ls
--color=never`. The rational behind this change is that ls should "just
work" by default, even on dumb terminals.

For this reason, this patch adds a check which additionally consults the
TERM variable before printing any colors. This is analogous to the
existing check for ensuring that standard output is a tty. As such,
colors can still be forced with `--color=force`, even if TERM is set to
dumb.

function                                             old     new   delta
is_TERM_dumb                                           -      40     +40
ls_main                                              579     598     +19
.rodata                                           103246  103251      +5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 64/0)               Total: 64 bytes

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-04 22:39:10 +02:00
Denys Vlasenko
d005c9f4c7 libbb.h: inline byteswaps
function                                             old     new   delta
recv_and_process_peer_pkt                           2173    2245     +72
machtime_dg                                           97     114     +17
machtime_stream                                       29      45     +16
fmt_time_bernstein_25                                132     139      +7
aesgcm_GHASH                                         183     184      +1
dumpleases_main                                      519     516      -3
__bswap_32                                             3       -      -3
udhcp_run_script                                     743     739      -4
tls_xread_record                                     634     630      -4
select_lease_time                                     56      52      -4
rdate_main                                           260     256      -4
get_prefix                                           327     323      -4
udhcp_listen_socket                                  185     180      -5
sha1_process_block64                                 361     356      -5
sendping6                                             81      76      -5
sendping4                                            107     102      -5
read32                                                27      22      -5
ll_proto_a2n                                         112     107      -5
bb_lookup_port                                       102      97      -5
udhcpc_main                                         2615    2609      -6
tftpd_main                                           579     573      -6
str2sockaddr                                         558     552      -6
GMULT                                                136     130      -6
sha1_end                                              73      66      -7
ntpd_main                                           1361    1354      -7
ntohl                                                  7       -      -7
inet_addr_match                                       93      86      -7
htonl                                                  7       -      -7
do_iplink                                           1259    1252      -7
do_add_or_delete                                    1138    1131      -7
create_and_bind_or_die                               117     110      -7
bind_for_passive_mode                                124     117      -7
xconnect_ftpdata                                      98      90      -8
rpm_getint                                           118     110      -8
read_leases                                          304     296      -8
read_config                                          216     208      -8
udhcp_send_kernel_packet                             336     327      -9
udhcp_recv_kernel_packet                             143     134      -9
sha256_process_block64                               451     442      -9
d6_send_kernel_packet_from_client_data_ifindex       275     266      -9
write_leases                                         215     205     -10
wget_main                                           2518    2508     -10
udhcpd_main                                         1528    1518     -10
tftp_protocol                                       2019    2009     -10
ftpd_main                                           2159    2149     -10
des_crypt                                           1318    1308     -10
send_ACK                                             138     127     -11
ipaddr_modify                                       1618    1607     -11
udhcp_str2optset                                     650     638     -12
init_d6_packet                                       115     103     -12
xwrite_encrypted                                     512     499     -13
tls_handshake                                       2060    2047     -13
pscan_main                                           607     594     -13
perform_d6_release                                   240     227     -13
ip_port_str                                          135     122     -13
handle_incoming_and_exit                            2230    2217     -13
INET_setroute                                        751     737     -14
traceroute_init                                     1153    1137     -16
nc_main                                             1055    1039     -16
udhcp_init_header                                     92      75     -17
volume_id_probe_hfs_hfsplus                          512     494     -18
send_offer                                           455     435     -20
do_lzo_decompress                                    507     487     -20
add_client_options                                   229     209     -20
ipcalc_main                                          554     533     -21
dhcprelay_main                                       966     943     -23
change_listen_mode                                   345     321     -24
send_packet                                          188     162     -26
static.xmalloc_optname_optval                        709     681     -28
rpm_gettags                                          447     419     -28
machtime                                              28       -     -28
catcher                                              299     270     -29
sfp_to_d                                              78      48     -30
reread_config_file                                   917     886     -31
lfp_to_d                                              84      51     -33
udhcp_recv_raw_packet                                594     559     -35
nbdclient_main                                      1182    1145     -37
d_to_lfp                                             137     100     -37
lzo_compress                                         567     529     -38
d6_recv_raw_packet                                   299     254     -45
d_to_sfp                                             133      85     -48
d6_send_raw_packet_from_client_data_ifindex          427     379     -48
common_ping_main                                    1935    1887     -48
udhcp_send_raw_packet                                467     416     -51
zcip_main                                           1219    1160     -59
udhcpc6_main                                        2636    2568     -68
do_lzo_compress                                      327     258     -69
send_arp_request                                     201     129     -72
common_traceroute_main                              1699    1621     -78
arpping                                              523     437     -86
arping_main                                         1597    1481    -116
print_tunnel                                         678     550    -128
dnsd_main                                           1304    1164    -140
parse_args                                          1370    1169    -201
------------------------------------------------------------------------------
(add/remove: 0/6 grow/shrink: 5/85 up/down: 113/-2246)      Total: -2133 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-24 11:54:50 +02:00
Denys Vlasenko
fe2d8065e3 fix gcc-11.0 warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-04-14 17:52:18 +02:00
Denys Vlasenko
6bdfbc4cb5 libbb: fix '--help' handling in FEATURE_SH_NOFORK=y
Most BusyBox applets respond to the '--help' option by printing
a usage message.  This is normally handled by busybox_main() so
applet main routines don't have support for '--help'.

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

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

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

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

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

Bug found by Ron Yorston.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-18 23:30:24 +01:00
Ron Yorston
cad3fc743a libbb: introduce and use fputs_stdout
function                                             old     new   delta
fputs_stdout                                           -      12     +12
zxc_vm_process                                      7237    7230      -7
yes_main                                              85      78      -7
write_block                                          380     373      -7
wrapf                                                305     298      -7
strings_main                                         437     430      -7
show_bridge                                          353     346      -7
rev_main                                             384     377      -7
put_prompt_custom                                     58      51      -7
put_cur_glyph_and_inc_cursor                         168     161      -7
print_numbered_lines                                 152     145      -7
print_named_ascii                                    130     123      -7
print_name                                           135     128      -7
print_login_issue                                    386     379      -7
print_ascii                                          208     201      -7
powertop_main                                       1249    1242      -7
od_main                                             1789    1782      -7
logread_main                                         518     511      -7
head_main                                            804     797      -7
display_process_list                                1319    1312      -7
cut_main                                            1002     995      -7
bb_dump_dump                                        1550    1543      -7
bb_ask_noecho                                        393     386      -7
baseNUM_main                                         702     695      -7
expand_main                                          755     745     -10
dumpleases_main                                      497     487     -10
write1                                                12       -     -12
putcsi                                                37      23     -14
print_login_prompt                                    55      41     -14
paste_main                                           525     511     -14
cat_main                                             440     426     -14
print_it                                             245     230     -15
print_addrinfo                                      1188    1171     -17
print_rule                                           770     750     -20
print_linkinfo                                       842     822     -20
httpd_main                                           791     771     -20
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/34 up/down: 12/-341)         Total: -329 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-03 20:52:40 +01:00
Alex Samorukov
4a4b453a87 Fix for the FEATURE_UTMP on the FreeBSD
FreeBSD is not using <utmp.h> and does not define _PATH_UTMPX.
Tested with busybox applets depending on FEATURE_UTMP (e.g. who, users, etc)

Signed-off-by: Alex Samorukov <samm@os2.kiev.ua>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-01-04 21:59:40 +01:00
Denys Vlasenko
3c13da3dab libbb: introduce and use xgettimeofday(), do not truncate 64-bit time_t in shells
function                                             old     new   delta
xgettimeofday                                          -      11     +11
get_local_var_value                                  280     281      +1
svlogd_main                                         1323    1322      -1
change_epoch                                          67      66      -1
timestamp_and_log                                    461     458      -3
hwclock_main                                         301     298      -3
fmt_time_bernstein_25                                135     132      -3
step_time                                            331     326      -5
script_main                                         1207    1202      -5
machtime                                              34      28      -6
curtime                                               61      54      -7
ts_main                                              423     415      -8
nmeter_main                                          761     751     -10
gettime1900d                                          67      46     -21
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/12 up/down: 12/-73)           Total: -61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-30 23:48:01 +01:00
Denys Vlasenko
00eb23b47a bc: do not allocate line editing state until needed
function                                             old     new   delta
xc_read_line                                         324     353     +29
free_line_input_t                                     34      39      +5
xc_vm_init                                           656     640     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-16)             Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 21:36:58 +01:00
Denys Vlasenko
eb0c2e218c libbb: introduce and use xsettimeofday()
function                                             old     new   delta
xsettimeofday                                          -      25     +25
rdate_main                                           274     260     -14
step_time                                            348     331     -17
set_kernel_timezone_and_clock                        119     102     -17
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 25/-48)            Total: -23 bytes
   text	   data	    bss	    dec	    hex	filename
1020753	    559	   5052	1026364	  fa93c	busybox_old
1020708	    559	   5052	1026319	  fa90f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 21:36:36 +01:00
Denys Vlasenko
eaced1ec85 lineedit: remove ->path_lookup if ash is not configured
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 10:01:21 +01:00
Denys Vlasenko
01004f9796 libbb: enable fixed 4k pagesize for 32bit ARM
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 21:24:04 +01:00
Denys Vlasenko
c7b858ff8d libbb: add and use infrastructure for fixed page size optimization
function                                             old     new   delta
procps_scan                                         1121    1118      -3
getpagesize                                            6       -      -6
rpm_main                                            1037    1027     -10
rpm2cpio_main                                        120     110     -10
ptok                                                  38      21     -17
time_main                                           1282    1261     -21
mkswap_main                                          317     278     -39
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/6 up/down: 0/-106)           Total: -106 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 18:54:30 +01:00
Denys Vlasenko
fd3c512f88 libbb: create and use mmap() helpers
function                                             old     new   delta
mmap_anon                                              -      22     +22
mmap_read                                              -      21     +21
xmmap_anon                                             -      16     +16
rpm_gettags                                          465     447     -18
bb_full_fd_action                                    498     480     -18
uevent_main                                          337     310     -27
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/3 up/down: 59/-63)             Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 18:25:28 +01:00
Denys Vlasenko
f4f6e5144b libbb: exec_login_shell() - new function
function                                             old     new   delta
exec_login_shell                                       -      12     +12
sulogin_main                                         247     240      -7
login_main                                           960     953      -7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 12/-14)             Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 21:51:08 +01:00
Denys Vlasenko
2075aa93e0 libbb: rename run_shell() to exec_shell()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 21:28:47 +01:00
Denys Vlasenko
965b795b87 decrease paddign: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nilly
text	   data	    bss	    dec	    hex	filename
1021988	    559	   5052	1027599	  fae0f	busybox_old
1021236	    559	   5052	1026847	  fab1f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 13:03:03 +01:00
Denys Vlasenko
6a55b4e403 libbb: introduce and use msleep()
function                                             old     new   delta
msleep                                                 -      45     +45
watchdog_main                                        271     266      -5
common_traceroute_main                              3546    3530     -16
beep_main                                            277     248     -29
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 45/-50)             Total: -5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-29 12:40:25 +01:00
Denys Vlasenko
ec16c030bd libbb: introduce and use sleep1()
function                                             old     new   delta
sleep1                                                 -       9      +9
run_shutdown_and_kill_processes                       97      95      -2
restore_state_and_exit                               116     114      -2
reread_partition_table                                67      65      -2
flush_buffer_cache                                    80      78      -2
chat_main                                           1302    1300      -2
timeout_main                                         310     307      -3
telnet_main                                         1235    1232      -3
stop_handler                                          86      83      -3
process_action                                      1078    1075      -3
nbdclient_main                                      1185    1182      -3
init_main                                            789     786      -3
getty_main                                          1541    1538      -3
do_time                                              410     407      -3
runsv_main                                          1682    1677      -5
pause_and_low_level_reboot                            59      54      -5
inetd_main                                          1917    1911      -6
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/16 up/down: 9/-50)            Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-29 11:37:34 +01:00
Denys Vlasenko
87bd558f3f libbb: bb_do_delay(3) -> pause_after_failed_login(), and stop looping there
function                                             old     new   delta
pause_after_failed_login                               -       9      +9
vlock_main                                           358     353      -5
sulogin_main                                         252     247      -5
su_main                                              484     479      -5
passwd_main                                          936     931      -5
login_main                                           967     962      -5
bb_do_delay                                           68       -     -68
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/5 up/down: 9/-93)             Total: -84 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-29 11:32:48 +01:00
Denys Vlasenko
885121e25d libbb: change decode_base32/64 API to return the end of _dst_, not _src_.
function                                             old     new   delta
decode_base64                                        173     178      +5
read_base64                                          222     220      -2
decode_base32                                        186     182      -4
handle_incoming_and_exit                            2263    2239     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-30)             Total: -25 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 13:27:36 +01:00
Denys Vlasenko
20900489a1 base32: new applet
function                                             old     new   delta
baseNUM_main                                           -     568    +568
decode_base32                                          -     275    +275
bb_uuenc_tbl_base32                                    -      34     +34
read_base64                                          218     236     +18
applet_names                                        2732    2739      +7
applet_main                                         1580    1584      +4
packed_usage                                       33480   33478      -2
base64_main                                          208       -    -208
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 3/1 up/down: 906/-210)          Total: 696 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-26 09:04:16 +01:00
Denys Vlasenko
689d0650ab libbb: shrink recursive_action() by reducing memory pressure
function                                             old     new   delta
recursive_action1                                      -     316    +316
file_action_grep                                     161     164      +3
add_to_prg_cache_if_socket                           202     205      +3
depmod_main                                          509     511      +2
writeFileToTarball                                   488     489      +1
parse_module                                         281     282      +1
fileAction                                           207     208      +1
act                                                  189     190      +1
add_to_dirlist                                        65      64      -1
writeTarFile                                         196     194      -2
uuidcache_init                                        47      45      -2
uuidcache_check_device                               109     107      -2
true_action                                            8       6      -2
run_parts_main                                       310     308      -2
netstat_main                                         534     532      -2
lsusb_main                                            29      27      -2
lspci_main                                            45      43      -2
initial_scan                                         138     136      -2
grep_main                                            845     843      -2
find_main                                            482     480      -2
config_file_action                                   437     435      -2
chmod_main                                           142     140      -2
dirAction                                             14      10      -4
diff_main                                           1544    1540      -4
chown_main                                           154     148      -6
skip_dir                                             136     129      -7
dir_act                                              191     184      -7
recursive_action                                     453      69    -384
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 7/20 up/down: 328/-439)        Total: -111 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 21:52:16 +02:00
Denys Vlasenko
3c3928fc65 tydy up a few uses of recursive_action(), no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 20:27:28 +02:00