Commit Graph

2199 Commits

Author SHA1 Message Date
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
Denys Vlasenko
4a0eb0370c gcc-9.x warning fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 03:07:22 +02:00
Denys Vlasenko
b1c7a66ca6 libbb: extend "errno pointer" trick to other than __GLIBC__
Savings on musl:

function                                             old     new   delta
resume_main                                          582     614     +32
lbb_prepare                                            -      20     +20
seq_main                                             432     449     +17
fgetsetversion                                        74      88     +14
...
script_main                                         1207    1180     -27
close_silently                                        28       -     -28
shell_builtin_ulimit                                 655     626     -29
lineedit_read_key                                    280     247     -33
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 25/123 up/down: 182/-882)      Total: -700 bytes
   text	   data	    bss	    dec	    hex	filename
1005858	    551	   5676	1012085	  f7175	busybox_old
1005136	    551	   5680	1011367	  f6ea7	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 00:34:44 +02:00
Steffen Trumtrar
6561e07460 mount: support the sizelimit and offset option for loop devices
Starting with linux kernel v5.4 squashfs has a more strict parameter
checking implemented. Unlike util-linux mount, busybox never supported
the sizelimit option but simply forwards it to the kernel.
Since v5.4 mounting will fail with

    squashfs: Unknown parameter 'sizelimit'

Support the sizelimit parameter by setting it in the LOOP_SET_STATUS64
structure before handing it to the kernel.

While at it also add support for the offset option, which currently will
always be set to 0.

function                                             old     new   delta
cut_out_ull_opt                                        -     167    +167
singlemount                                         1230    1266     +36
set_loop                                             834     862     +28
losetup_main                                         479     483      +4
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 235/0)             Total: 235 bytes

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 00:31:11 +02:00
Denys Vlasenko
9a2d899273 ntpd: fix refid reported in server mode, closes 13056
function                                             old     new   delta
resolve_peer_hostname                                129     196     +67
recv_and_process_peer_pkt                           2475    2476      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 68/0)               Total: 68 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-20 00:04:33 +02:00
Denys Vlasenko
5fa5c4bde8 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-23 21:28:19 +02:00
Denys Vlasenko
d206b1651a randomconfig fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-23 09:38:53 +02:00
Denys Vlasenko
6eb38fded2 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-23 02:46:53 +02:00
Ron Yorston
9e2a5668fd ash,hush: allow builtins to be tab-completed, closes 7532
function                                             old     new   delta
complete_cmd_dir_file                                678     830    +152
get_builtin_name                                       -      35     +35
optschanged                                          125     132      +7
hush_main                                           1069    1076      +7
save_command_ps_at_cur_history                        76      78      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/0 up/down: 203/0)             Total: 203 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29 15:23:17 +01:00
Denys Vlasenko
af7169b4a7 clang/llvm 9 fix - do not eliminate a store to a fake "const"
This is *much* better (9 kbytes better) than dropping "*const"
optimization trick.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25 12:12:22 +02:00
James Byrne
6937487be7 libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d437 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().

This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.

Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.

This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.

The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):

Arm:     -92 bytes
MIPS:    -52 bytes
PPC:   -1836 bytes
x86_64: -938 bytes

Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.

Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 11:35:03 +02:00
Denys Vlasenko
3b69ba799f mount,losetup: use /dev/loop-control is it exists
function                                             old     new   delta
get_free_loop                                          -      58     +58
set_loop                                             597     649     +52
losetup_main                                         482     476      -6
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 110/-6)            Total: 104 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-09 23:20:49 +02:00
Denys Vlasenko
45e3967c20 libbb: move netlink socket binding to the utility function
function                                             old     new   delta
create_and_bind_to_netlink                             -     134    +134
ifplugd_main                                        1117    1052     -65
uevent_main                                          399     306     -93
mdev_main                                            314     215     -99
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 134/-257)         Total: -123 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-03 14:16:52 +02:00
Jack O'Sullivan
726cbb1be8 losetup: Add partition scanning option
Add -P option from util-linux losetup to scan for partitions.

function                                             old     new   delta
losetup_main                                         449     482     +33
packed_usage                                       33264   33292     +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0)               Total: 61 bytes

Signed-off-by: Jack O'Sullivan <jackos1998@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-30 16:22:52 +02:00
Denys Vlasenko
dff2bd733f libarchive: treat one "FIXME: avoid seek"
function                                             old     new   delta
xmalloc_read_with_initial_buf                          -     205    +205
setup_transformer_on_fd                              154     150      -4
xmalloc_open_zipped_read_close                       143     135      -8
xmalloc_read                                         201      10    -191
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 205/-203)            Total: 2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-24 17:03:28 +02:00
James Byrne
253c4e787a Optionally re-introduce bb_info_msg()
Between Busybox 1.24.2 and 1.25.0 the bb_info_msg() function was
eliminated and calls to it changed to be bb_error_msg(). The downside of
this is that daemons now log all messages to syslog at the LOG_ERR level
which makes it hard to filter errors from informational messages.

This change optionally re-introduces bb_info_msg(), controlled by a new
option FEATURE_SYSLOG_INFO, restores all the calls to bb_info_msg() that
were removed (only in applets that set logmode to LOGMODE_SYSLOG or
LOGMODE_BOTH), and also changes informational messages in ifplugd and
ntpd.

The code size change of this is as follows (using 'defconfig' on x86_64
with gcc 7.3.0-27ubuntu1~18.04)

function                                             old     new   delta
bb_info_msg                                            -     182    +182
bb_vinfo_msg                                           -      27     +27
static.log7                                          194     198      +4
log8                                                 190     191      +1
log5                                                 190     191      +1
crondlog                                              45       -     -45
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/0 up/down: 215/-45)           Total: 170 bytes

If you don't care about everything being logged at LOG_ERR level
then when FEATURE_SYSLOG_INFO is disabled Busybox actually gets smaller:

function                                             old     new   delta
static.log7                                          194     200      +6
log8                                                 190     193      +3
log5                                                 190     193      +3
syslog_level                                           1       -      -1
bb_verror_msg                                        583     581      -2
crondlog                                              45       -     -45
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 3/1 up/down: 12/-48)            Total: -36 bytes

Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-30 10:51:27 +02:00
Ron Yorston
3193cb56d6 libbb: mark scripted_main() as externally visible
Building with individual binaries enabled fails when embedded
script applets are included:

   /tmp/ccIvMFZg.o: In function `main':
   applet.c:(.text.main+0x20): undefined reference to `scripted_main'

Mark scripted_main() as externally visible.

Reported-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-30 16:46:27 +01:00
Denys Vlasenko
5059653882 do not duplicate CONFIG_PID_FILE_PATH and ".pid" strings
text	   data	    bss	    dec	    hex	filename
 981737	    485	   7296	 989518	  f194e	busybox_old
 981704	    485	   7296	 989485	  f192d	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-17 19:48:39 +01:00
Denys Vlasenko
0ddc742c04 watch: support fractional -n SEC
function                                             old     new   delta
watch_main                                           212     232     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-12 18:56:51 +01:00
Denys Vlasenko
088fec36fe start-stop-daemon: create pidfile before parent exits, closes 8596
This removes DAEMON_DOUBLE_FORK flag from bb_daemonize_or_rexec(),
as SSD was the only user.

Also includes fix for -S: now works without -a and -x,
does not print pids
(compat with "start-stop-daemon (OpenRC) 0.34.11 (Gentoo Linux)").

function                                             old     new   delta
start_stop_daemon_main                              1018    1084     +66
add_interface                                         99     103      +4
fail_hunk                                            139     136      -3
bb_daemonize_or_rexec                                205     183     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 70/-25)             Total: 45 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-14 14:47:21 +01:00
Denys Vlasenko
aad76968cd pmap: make 32-bit version work better on 64-bit kernels
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-31 15:18:45 +01:00
Denys Vlasenko
b437df1157 inetd: suppress aliasing warning
function                                             old     new   delta
sigprocmask2                                           -       8      +8
wait_for_child_or_signal                             213     218      +5
dowait                                               424     429      +5
block_CHLD_HUP_ALRM                                   62      59      -3
sigprocmask_SIG_SETMASK                               16       -     -16
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/1 up/down: 18/-19)             Total: -1 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08 15:35:24 +01:00
Denys Vlasenko
136fe9bede suppress gcc 8 aliasing warnings
function                                             old     new   delta
sigprocmask_SIG_SETMASK                                -      16     +16
wait_for_child_or_signal                             221     213      -8
dowait                                               432     424      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08 13:49:15 +01:00
Denys Vlasenko
a68a87cd60 bc: unbreak FEATURE_CLEAN_UP build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-06 11:12:38 +01:00
Denys Vlasenko
c100535571 cat,nl: fix handling of open errors
$ cat -n does_not_exist; echo $?
cat: does_not_exist: No such file or directory
1

function                                             old     new   delta
print_numbered_lines                                 118     129     +11
nl_main                                              196     201      +5
cat_main                                             421     425      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 20/0)               Total: 20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-29 11:44:10 +01:00
Ron Yorston
71df2d3589 hush: allow hush to run embedded scripts
Embedded scripts require a shell to be present in the BusyBox
binary.  Allow either ash or hush to be used for this purpose.
If both are enabled ash takes precedence.

The size of the binary is unchanged in the default configuration:
both ash and hush are present but support for embedded scripts
isn't compiled into hush.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-27 16:13:07 +01:00
Ron Yorston
7b42f8fc76 Tweaks to build process for embedded scripts
- Force a rebuild if a script in applets_sh is changed.

- Move the dummy usage messages for custom applets to usage.h and
  change the name from 'dummy' to 'scripted'.

- Hide an error from gen_build_files.sh if an embed directory exists
  but is empty.

- Tidy up embedded_scripts script.

v2: Remove a couple of unnecessary tests in embedded_scripts, as
    pointed out by Xabier Oneca.
    Drop the stripping of comments.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-27 10:38:10 +01:00
Denys Vlasenko
eb53d01be5 tls: code shrink
function                                             old     new   delta
xwrite_and_update_handshake_hash                      81      80      -1
tls_handshake                                       1987    1957     -30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25 14:45:55 +01:00
Denys Vlasenko
26602b85a3 wget: print the final newline only for non-tty output
$ busybox wget URL 2>&1 | cat
Connecting to ....
install.iso          0% |                                | 2629k  0:02:05 ETA
install.iso          7% |**                              | 25.7M  0:00:23 ETA
install.iso         16% |*****                           | 54.1M  0:00:14 ETA
install.iso         20% |******                          | 67.4M  0:00:15 ETA
install.iso         25% |********                        | 81.0M  0:00:14 ETA
install.iso         30% |*********                       | 97.3M  0:00:13 ETA
install.iso         36% |***********                     |  117M  0:00:12 ETA
install.iso         41% |*************                   |  134M  0:00:11 ETA
install.iso         47% |***************                 |  152M  0:00:10 ETA
install.iso         54% |*****************               |  176M  0:00:08 ETA
install.iso         61% |*******************             |  200M  0:00:06 ETA
install.iso         66% |*********************           |  215M  0:00:06 ETA
install.iso         71% |**********************          |  231M  0:00:05 ETA
install.iso         75% |************************        |  244M  0:00:04 ETA
install.iso         79% |*************************       |  257M  0:00:03 ETA
install.iso         84% |***************************     |  275M  0:00:02 ETA
install.iso         91% |*****************************   |  297M  0:00:01 ETA
install.iso         99% |******************************* |  321M  0:00:00 ETA
install.iso        100% |********************************|  323M  0:00:00 ETA
  <-- no empty line here
$

function                                             old     new   delta
bb_progress_update                                   622     632     +10
progress_meter                                       152     158      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 16/0)               Total: 16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23 19:14:52 +01:00
Denys Vlasenko
219c9d4b5d tls: code shrink
function                                             old     new   delta
xwrite_encrypted                                     599     585     -14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23 18:48:20 +01:00
Denys Vlasenko
83e5c627e1 tls: add support for TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher
function                                             old     new   delta
xwrite_encrypted                                     209     605    +396
GHASH                                                  -     395    +395
aes_encrypt_1                                          -     382    +382
GMULT                                                  -     192    +192
tls_xread_record                                     489     659    +170
aes_encrypt_one_block                                  -      65     +65
aesgcm_setkey                                          -      58     +58
FlattenSzInBits                                        -      52     +52
tls_handshake                                       1890    1941     +51
xwrite_and_update_handshake_hash                      46      81     +35
xorbuf                                                 -      24     +24
aes_setkey                                             -      16     +16
psRsaEncryptPub                                      413     421      +8
stty_main                                           1221    1227      +6
ssl_client_main                                      138     143      +5
next_token                                           841     845      +4
spawn_ssl_client                                     218     219      +1
volume_id_probe_hfs_hfsplus                          564     563      -1
read_package_field                                   232     230      -2
i2cdetect_main                                       674     672      -2
fail_hunk                                            139     136      -3
parse_expr                                           891     883      -8
curve25519                                           802     793      -9
aes_cbc_decrypt                                      971     958     -13
xwrite_handshake_record                               43       -     -43
aes_cbc_encrypt                                      644     172    -472
------------------------------------------------------------------------------
(add/remove: 9/1 grow/shrink: 9/8 up/down: 1860/-553)        Total: 1307 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23 17:48:07 +01:00
Ron Yorston
3778898f97 Treat custom and applet scripts as applets
BusyBox has support for embedded shell scripts.  Two types can be
distinguished:  custom scripts and scripts implementing applets.

Custom scripts should be placed in the 'embed' directory at build
time.  They are given a default applet configuration and appear
as applets to the user but no further configuration is possible.

Applet scripts are integrated with the BusyBox build system and
are intended to be used to ship standard applets that just happen
to be implemented as scripts.  They can be configured at build time
and appear just like native applets.

Such scripts should be placed in the 'applets_sh' directory.  A stub
C program should be written to provide the usual applet configuration
details and placed in a suitable subsystem directory.  It may be
helpful to have a configuration option to enable any dependencies the
script requires:  see the 'nologin' applet for an example.

function                                             old     new   delta
scripted_main                                          -      41     +41
applet_names                                        2773    2781      +8
applet_main                                         1600    1604      +4
i2cdetect_main                                       672     674      +2
applet_suid                                          100     101      +1
applet_install_loc                                   200     201      +1
applet_flags                                         100     101      +1
packed_usage                                       33180   33179      -1
tryexec                                              159     152      -7
evalcommand                                         1661    1653      -8
script_names                                           9       -      -9
packed_scripts                                       123     114      -9
complete_cmd_dir_file                                826     811     -15
shellexec                                            271     254     -17
find_command                                        1007     990     -17
busybox_main                                         642     624     -18
run_applet_and_exit                                  100      78     -22
find_script_by_name                                   51       -     -51
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 6/9 up/down: 58/-174)          Total: -116 bytes
   text	   data	    bss	    dec	    hex	filename
 950034	    477	   7296	 957807	  e9d6f	busybox_old
 949918	    477	   7296	 957691	  e9cfb	busybox_unstripped

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-17 21:16:33 +01:00
Ron Yorston
c339c7f7b3 libarchive: add a function to unpack embedded data
Similar code to unpack embedded data is used to decompress usage
messages, embedded scripts and the config file (in the non-default
bbconfig applet).

Moving this code to a common function reduces the size of the default
build and hides more of the internals of libarchive.

function                                             old     new   delta
unpack_bz2_data                                        -     135    +135
bb_show_usage                                        137     157     +20
get_script_content                                    32      47     +15
unpack_scripts                                       119       -    -119
unpack_usage_messages                                124       -    -124
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 2/0 up/down: 170/-243)          Total: -73 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-02 14:14:51 +01:00
Ron Yorston
151de441e7 ash: recognize embedded scripts in SH_STANDALONE mode
function                                             old     new   delta
find_script_by_name                                    -      51     +51
shellexec                                            254     271     +17
find_command                                         990    1007     +17
evalcommand                                         1653    1661      +8
doCommands                                          2233    2222     -11
run_applet_and_exit                                  128     100     -28
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/4 up/down: 104/-52)            Total: 52 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01 11:07:26 +01:00
Denys Vlasenko
4f2ef4a836 ash: allow shell scripts to be embedded in the binary
To assist in the deployment of shell scripts it may be convenient
to embed them in the BusyBox binary.

'Embed scripts in the binary' takes any files in the directory
'embed', concatenates them with null separators, compresses them
and embeds them in the binary.

When scripts are embedded in the binary, scripts can be run as
'busybox SCRIPT [ARGS]' or by usual (sym)link mechanism.

embed/nologin is provided as an example.

function                                             old     new   delta
packed_scripts                                         -     123    +123
unpack_scripts                                         -      87     +87
ash_main                                            1103    1171     +68
run_applet_and_exit                                   78     128     +50
get_script_content                                     -      32     +32
script_names                                           -      10     +10
expmeta                                              663     659      -4
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 2/1 up/down: 370/-4)            Total: 366 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01 10:15:13 +01:00
Denys Vlasenko
349d72c19c unzip: use printable_string() for printing filenames
function                                             old     new   delta
unzip_main                                          2726    2792     +66
printable_string2                                      -      57     +57
identify                                            4329    4336      +7
expmeta                                              659     663      +4
add_interface                                         99     103      +4
beep_main                                            286     289      +3
changepath                                           192     194      +2
builtin_type                                         115     117      +2
devmem_main                                          469     470      +1
input_tab                                           1076    1074      -2
create_J                                            1821    1819      -2
poplocalvars                                         314     311      -3
doCommands                                          2222    2214      -8
do_load                                              918     902     -16
printable_string                                      57       9     -48
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 8/6 up/down: 146/-79)            Total: 67 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-30 16:56:56 +02:00
Denys Vlasenko
abfa3ec059 move storage helpers to libbb.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-28 15:13:04 +02:00
Denys Vlasenko
4c20d9f2b0 extend fractional duration support to "top -d N.N" and "timeout"
function                                             old     new   delta
parse_duration_str                                     -     168    +168
sleep_for_duration                                     -     157    +157
top_main                                             885     928     +43
timeout_main                                         269     312     +43
handle_input                                         571     614     +43
duration_suffixes                                      -      40     +40
sfx                                                   40       -     -40
sleep_main                                           364      79    -285
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 3/1 up/down: 494/-325)          Total: 169 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-03 18:17:12 +02:00
Denys Vlasenko
79fb6ac7a5 cp: optional --reflink support
function                                             old     new   delta
cp_main                                              428     512     +84
copy_file                                           1676    1742     +66

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-13 20:30:02 +02:00
Denys Vlasenko
817a20296f randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-26 15:35:17 +02:00
Denys Vlasenko
747162109f realpath,readlink -f: coreutils compat, closes 11021
function                                             old     new   delta
xmalloc_realpath_coreutils                             -     121    +121

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-24 17:31:00 +02:00
Harald van Dijk
8c24af9dcf tar: fix interaction of delayed symlink and hardlink creation
function                                             old     new   delta
create_or_remember_link                                -     106    +106
create_links_from_list                                 -      93     +93
find_applet_by_name                                  124     128      +4
unzip_main                                          2724    2726      +2
data_extract_all                                     891     873     -18
create_symlinks_from_list                             64       -     -64
create_or_remember_symlink                            94       -     -94
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/1 up/down: 205/-176)           Total: 29 bytes

Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:34:31 +02:00
Denys Vlasenko
2aeb201c97 libbb: new option FEATURE_ETC_SERVICES: if off, /etc/services reads often avoided
In practice, "wget http://host.com/" always uses port 80.
People explicitly set non-standard ports via options or parameters
("telnet 1.2.3.4 567" or "telnet 1.2.3.4 ftp") instead of modifying
/etc/services.

function                                             old     new   delta
telnet_main                                         1466    1464      -2
rdate_main                                           215     198     -17
fakeidentd_main                                      269     252     -17
parse_url                                            459     392     -67
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-103)           Total: -103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-17 12:43:54 +02:00
Denys Vlasenko
058a153b69 less: fix fallout from "use common routine to set raw termios"
Testcase: (sleep 10; ls) | busybox less

[...]
~           LICENSE
~                  Makefile
~                          Makefile.custom
~                                         Makefile.flags
[...]

less did not want this part:
+		/* dont convert NL to CR+NL on output */
+		newterm->c_oflag &= ~(ONLCR);

function                                             old     new   delta
get_termios_and_make_raw                             108     115      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-16 10:24:48 +02:00
Denys Vlasenko
b74e490629 ar: stop using static data
function                                             old     new   delta
static.ar_long_names                                   4       -      -4
static.ar_long_name_size                               4       -      -4
get_header_ar                                        546     532     -14
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-22)             Total: -22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-15 14:18:16 +02:00
Denys Vlasenko
38ccd6af8a bzip2: fix two crashes on corrupted archives
As it turns out, longjmp'ing into freed stack is not healthy...

function                                             old     new   delta
unpack_usage_messages                                  -      97     +97
unpack_bz2_stream                                    369     409     +40
get_next_block                                      1667    1677     +10
get_bits                                             156     155      -1
start_bunzip                                         212     183     -29
bb_show_usage                                        181     120     -61
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/3 up/down: 147/-91)            Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 20:05:04 +02:00
Denys Vlasenko
7bcde5f00d libbb.h: always include sys/resource.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 17:23:27 +02:00
Denys Vlasenko
17058a06c4 libbb: switch bb_ask_noecho() to "mallocing" string return API
function                                             old     new   delta
bb_ask_noecho                                        313     330     +17
get_cred_or_die                                      125     115     -10
passwd_main                                          995     958     -37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 17/-47)            Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 15:50:30 +02:00
Denys Vlasenko
bae8fc4436 xargs: use bb_ask_y_confirmation_FILE() instead of homegrown copy
function                                             old     new   delta
bb_ask_y_confirmation_FILE                             -      83     +83
inetd_main                                          2033    2043     +10
udhcp_send_kernel_packet                             295     301      +6
rmescapes                                            306     310      +4
send_tree                                            353     355      +2
i2cdetect_main                                       674     672      -2
confirm_or_abort                                      43      38      -5
get_terminal_width_height                            242     234      -8
bb_ask_y_confirmation                                 76      10     -66
xargs_main                                           823     755     -68
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/5 up/down: 105/-149)          Total: -44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-07 15:23:10 +02:00