Compare commits

...
245 Commits
Author SHA1 Message Date
Denys Vlasenko be947c4d97 Apply post-1.23.1 patches, bump version to 1.23.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-23 03:59:44 +01:00
Denys Vlasenko 1ecfe811fe Apply post-1.23.0 patches, bump version to 1.23.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-27 09:52:18 +01:00
Denys Vlasenko 6968e08123 Bump version to 1.23.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-24 01:48:20 +01:00
Denys Vlasenko ca9c4653a9 libbb: add sanity check in bb_arg_max()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-24 01:46:29 +01:00
Denys Vlasenko 11775edbfc randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-22 19:37:05 +01:00
Peter Kümmel a6588fa102 Make it possible to override LOGIN_FAIL_DELAY in CONFIG_EXTRA_CFLAGS
Signed-off-by: Peter Kümmel <syntheticpp@gmx.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-22 01:55:54 +01:00
Denys Vlasenko 28634924f0 udhcpc: account for script run time
Based on the following user report:

I ran into an issue where I was seeing a long delay in the scripts called
in udhcp_run_script. I was using an old version of OpenWrt (kamikaze)
and a satellite modem. An NTP script was being called and the modem
would sometimes take a long time to respond to the DNS lookup when
it was offline.

This delay started affecting my lease time. The lease that I would
get from my satellite modem before it was online would be short:
only 60 seconds. The delay with NTP and the modem would typically
be about 18 seconds. This would cause the first DHCP renew request
from dhcpc to be a little late. Under certain circumstances,
I could even see the first DHCP renew to occur after the lease
had expired!

function                                             old     new   delta
udhcpc_main                                         2816    2837     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-21 16:10:22 +01:00
Baruch Siach ad0d009e0c nanddump: don't show --bb in usage when disabled
The --bb options now depends on LONG_OPTS. Omit mentions of --bb from usage
text when LONG_OPTS is disabled.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-18 11:55:08 +01:00
Baruch Siach e835afadfe nandwrite: fix build when long options are disabled
The Required_argument macro is only defined when long options are enabled.
Fixes the following build error:

miscutils/nandwrite.c: In function 'nandwrite_main':
miscutils/nandwrite.c:120:10: error: expected ',' or ';' before 'Required_argument'

Reported-by: Christian Kästner <kaestner at cs.cmu.edu>
Signed-off-by: Baruch Siach <baruch at tkos.co.il>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-17 17:02:37 +01:00
Ron Yorston 20cd31a2d7 lineedit: don't block when looking for escape sequence in vi-mode
In vi-mode lineedit tries to detect some escape sequences.
After the ESC it reads the next character to check for certain
values.  This read should have a timeout or a user-entered ESC to
switch to command mode doesn't properly handle the next character.

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-15 13:30:58 +01:00
Denys Vlasenko acb8be7217 tar: fix "tar -cJ" ignoring -J option. closes 7706
function                                             old     new   delta
tar_main                                             895     938     +43
vfork_compressor                                     206     191     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 43/-15)             Total: 28 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-11 15:34:02 +01:00
Denys Vlasenko d598a8d4e6 lineedit: don't fall back to simple line input if tty is in raw mode
Testcase: shell command input after python ^Z should still work

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-10 17:22:13 +01:00
Bartosz Golaszewski 202d9a6464 Config: select PLATFORM_LINUX if using sendfile()
Man entry for sendfile:

  Not specified in POSIX.1-2001, or other standards.

  Other UNIX systems implement sendfile() with different  semantics  and
  prototypes. It should not be used in portable programs.

Select PLATFORM_LINUX if enabling FEATURE_USE_SENDFILE.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-10 13:46:53 +01:00
Jacob Kjaergaard bd7c1f2d13 flashcp: change BUFSIZE to 4k
some flash partitions can be smaller than the existing BUFSIZE thus write
BUFSIZE will fail with "no space left on device"

Signed-off-by: Jacob Kjaergaard <jacob.kjaergaard@prevas.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-10 13:44:27 +01:00
Denys Vlasenko cfcd2399b2 make xmalloc_open_zipped_read_close result NUL terminated
Compat with xmalloc_open_read_close

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-07 00:49:55 +01:00
Denys Vlasenko b4c11c1397 libarchive: add capability to unpack to mem.buffer
The performance and number of processes for a "depmod -a" with gzipped
modules was abysmal. This patch adds a code path without fork,
benefiting all users of xmalloc_open_zipped_read_close.

"modinfo radeon.ko.gz", a single-file reader, got 30% faster.
"depmod -a", which used to fork over 800 times, got 20% faster.

Heavily based on a patch by Lauri Kasanen <curaga@operamail.com>

function                                             old     new   delta
setup_transformer_on_fd                                -     159    +159
transformer_write                                      -     122    +122
fork_transformer                                       -     112    +112
xmalloc_open_zipped_read_close                        63     118     +55
read_bunzip                                         1866    1896     +30
xtransformer_write                                     -      19     +19
unzip_main                                          2449    2462     +13
bbunpack                                             755     766     +11
unpack_lzma_stream                                  2717    2723      +6
unpack_xz_stream                                    2393    2397      +4
unpack_Z_stream                                     1173    1175      +2
inflate_unzip                                        111     105      -6
check_signature16                                     70      63      -7
unpack_bz2_stream                                    359     349     -10
unpack_unxz                                           12       -     -12
unpack_unlzma                                         12       -     -12
unpack_uncompress                                     12       -     -12
unpack_gunzip                                         12       -     -12
unpack_bunzip2                                        12       -     -12
open_transformer                                     106      92     -14
inflate_unzip_internal                              1945    1916     -29
unpack_gz_stream                                     693     655     -38
open_zipped                                           89      47     -42
setup_unzip_on_fd                                    142      53     -89
------------------------------------------------------------------------------
(add/remove: 4/5 grow/shrink: 7/8 up/down: 533/-295)          Total: 238 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-07 00:44:00 +01:00
Denys Vlasenko e7800f351a Rename transformer_aux_data_t -> transformer_state_t
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-07 00:42:49 +01:00
Denys Vlasenko 476654cdbe man: do not mangle $MANPATH in memory
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-30 19:39:58 +01:00
Bartosz Golaszewski 8d75d794ea libbb: use sendfile() to copy data between file descriptors
Busybox already uses sendfile in httpd. This patch proposes to use it
globally to copy data between file descriptors.

It speeds up the copying on slow systems a lot - below are the times needed
to copy a 450Mb file with and without this option enabled on a BeagleBone
Black:

sendfile:
user    0m0.000s
sys     0m8.170s

read/write 4k:
user    0m0.470s
sys     0m16.300s

function                                             old     new   delta
bb_full_fd_action                                    394     474     +80

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-27 23:31:58 +01:00
Denys Vlasenko ee41094b80 man: accept a list of dirs in $MANPATH
function                                             old     new   delta
add_MANPATH                                            -     143    +143
man_main                                             852     731    -121
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 143/-121)           Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-27 00:40:08 +01:00
Denys Vlasenko 04c1417602 libbb: use ARG_MAX for bb_arg_max() only if it's 60k+
Sometimes ARG_MAX is small (like 32k) yet sysconf(_SC_ARG_MAX)
is big, and people prefer using the bigger value.

OTOH, with sufficiently large ARG_MAX, further wins from
sysconf(_SC_ARG_MAX) being bigger are exponentially smaller:
you can see 4 times fewer fork+execs when you run find, but
when each execed process already takes a thousand parameters
it's likely execution time is dominated by what that process
does with each parameter.

Thus, with this change ARG_MAX is used if it's sufficiently big,
otherwise sysconf(_SC_ARG_MAX) is used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-26 15:17:59 +01:00
Denys Vlasenko 2835a224cd bbunit: fix WANT_TIMING compilation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-26 14:04:51 +01:00
Bartosz Golaszewski eff58f15b0 gitignore: add testsuite/echo-ne
Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-26 13:28:54 +01:00
Denys Vlasenko 298fabaefc udhcpd: if a lease from lease file coincides with a static one, ignore it
function                                             old     new   delta
read_leases                                          269     328     +59

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-25 18:49:14 +01:00
Denys Vlasenko 2bba9ad67a init: do not run shutdown/reexec actions from signal handler
this is racy wrt various libc functions such as syslog()

function                                             old     new   delta
check_delayed_sigs                                   182     352    +170
init_main                                            772     728     -44
restart_handler                                       74       -     -74
halt_reboot_pwoff                                     79       -     -79
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/1 up/down: 170/-197)          Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-21 20:10:57 +01:00
Denys Vlasenko 4e314faa0a modprobe,rmmod: reject module names with slashes
function                                             old     new   delta
add_probe                                             86     113     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-20 18:24:33 +01:00
Denys Vlasenko f5add44981 typo fix in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-20 01:43:30 +01:00
Denys Vlasenko 8a475def9e ash,hush: do not segfault on $((2**63 / -1))
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-18 14:32:58 +01:00
Denys Vlasenko 08a5dab181 ash: fix handling of negative start value in ${v:start:len}
function                                             old     new   delta
subevalvar                                          1140    1168     +28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-17 20:27:18 +01:00
Michael Tokarev 1a1143907c iproute: support onelink route option and print route flags
function                                             old     new   delta
print_route                                         1797    1865     +68
do_iproute                                          2097    2112     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 83/0)               Total: 83 bytes

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-17 19:35:41 +01:00
Denys Vlasenko 628f134fe7 exit with 127 if appled name wasn't found - it's more POSIXy
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-17 17:03:47 +01:00
Michel Stam d3fabf89d7 zcip: Add environment variable for overriding log functionality
function                                             old     new   delta
bb_logenv_override                                     -      70     +70
packed_usage                                       29969   30033     +64
zcip_main                                           1426    1431      +5
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 139/0)             Total: 139 bytes

Signed-off-by: Michel Stam <m.stam@fugro.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-04 12:19:04 +01:00
Michel Stam fdd957bdc9 zcip: allow our own class B range to be used for ZeroConf
169.254 may already be used by a local network. This patch allows
specifying your own IP range.

Our particular use case is a mesh network, in which the nodes partaking
were using an IP range specifically assigned for the meshing purpose.
As the LAN side of the mesh node could use 169.254, this default range
was not an option.

function                                             old     new   delta
zcip_main                                           1342    1426     +84
pick_nip                                               -      40     +40
packed_usage                                       29974   29969      -5
pick                                                  34       -     -34
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/1 up/down: 124/-39)            Total: 85 bytes

Signed-off-by: Michel Stam <m.stam@fugro.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-10-30 13:43:09 +01:00
Michel Stam 9f41271f3c udhcpd: add option for tweaking arpping
Some clients have a very short timeout for sending the DHCP
DISCOVER, shorter than the arpping timeout of 2000 milliseconds
that udhcpd uses by default.

This patch allows tweaking the timeout, or disabling of arpping
altogether, at the risk of handing out addresses which are
already in use.

function                                             old     new   delta
udhcpd_main                                         1460    1501     +41
udhcpc_main                                         2814    2851     +37
packed_usage                                       29957   29974     +17
arpping                                              477     493     +16
find_free_or_expired_nip                             161     174     +13
send_offer                                           285     292      +7
nobody_responds_to_arp                                85      89      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 135/0)             Total: 135 bytes

Signed-off-by: Michel Stam <m.stam@fugro.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-10-30 11:59:04 +01:00
Miroslav Lichvar 760d035699 ntpd: calculate offset to jitter ratio before updating jitter
The offset to jitter ratio is now calculated before updating
jitter to make the test more sensitive.

function                                             old     new   delta
ntp_init                                             460     474     +14
update_local_clock                                   752     764     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 26/0)               Total: 26 bytes

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-10-05 03:11:53 +02:00
Denys Vlasenko cd73871178 sed: fix "sed CMD -i nonexistent_file". Closes 7484
function                                             old     new   delta
sed_main                                             643     676     +33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-10-05 02:44:34 +02:00
Miroslav Lichvar b434ce7069 ntpd: don't stay at short polling interval
To avoid polling servers frequently slowly increase the interval up
to BIGPOLL when
- no replies are received from a peer
- no source can be selected
- peer claims to be unsynchronized (e.g. we are polling it too
  frequently)

When recv() returns with an error, drop code to try to continue
on network errors: I'm not convinced those cases happen in real life.

function                                             old     new   delta
recv_and_process_peer_pkt                            919     838     -81

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-10-02 17:24:34 +02:00
Denys Vlasenko cf76b5ce12 getty: set tty attrs so that control chars are shown as ^c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-10-02 13:45:21 +02:00
Denys Vlasenko d3fe960271 ntpd: be less eager to use shorter poll intervals
* on step, poll interval drops to 8.5 mins instead of 32 seconds
* on total loss of all replies (no replies from any peer
  for last 8 requests), also drop poll interval to 8.5 mins
  instead of 32 seconds
* on send abd recv errors, RETRY_INTERVAL is now 32 seconds,
  not 5 seconds
* on timing out listening to reply, instead of unconditional
  shortening poll interval by x4, clamp it to NOREPLY_INTERVAL
  (512 seconds)
* if a largish offset is seen, clamp nexp poll interval
  to 128 seconds, not 64 seconds

function                                             old     new   delta
clamp_pollexp_and_set_MAXSTRAT                         -      37     +37
recv_and_process_peer_pkt                            861     869      +8
poll_interval                                         52      48      -4
update_local_clock                                   762     752     -10
ntpd_main                                           1063    1050     -13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/3 up/down: 45/-27)             Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-27 22:56:09 +02:00
Denys Vlasenko 186b98a86f ubiupdatevol: fix -t to not require an option. Closes 7466
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-25 22:10:32 +02:00
Denys Vlasenko 054f5a5b0d install: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-24 22:16:24 +02:00
Miroslav Lichvar 590a22cf8d ntpd: split out poll adjusting code
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-24 15:37:17 +02:00
Miroslav Lichvar fb143f783d ntpd: don't wait for good offset before disabling burst mode
The burst mode needs to be stopped even when no replies are received.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-24 15:21:18 +02:00
Aaro Koskinen 0f78d616cb install: implement -t DIR
Some packages want to install themselves using "-t" to specify
the directory (as supported by GNU coreutils). Add support for the option
for compatibility reasons.

function                                             old     new   delta
install_longopts                                      76      95     +19
install_main                                         769     777      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 27/0)               Total: 27 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-24 02:52:08 +02:00
Aaro Koskinen 307d26c0eb less: make -E work
function                                             old     new   delta
buffer_print                                          71     104     +33

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-23 22:58:18 +02:00
Denys Vlasenko 865814a617 less: trivial code shrink
function                                             old     new   delta
read_lines                                           715     695     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-22 21:17:24 +02:00
Denys Vlasenko d6e7672545 less: move "retry-on-EAGAIN" logic closer to read ops
This makes "G" (goto end of input) command work as well as
/search_for_nonexistent_string: both will read to EOF now
even from somewhat slow input (such as kernel's "git log").

function                                             old     new   delta
ndelay_on                                             35      43      +8
ndelay_off                                            35      43      +8
read_lines                                           695     691      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-4)              Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-22 21:14:02 +02:00
Denys Vlasenko 15943c886d less: disable "suppress empty wraparound" optimization
It is buggy wrt another use case...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-21 22:10:55 +02:00
Ari Sundholm fbdc167f27 df: fix -T option when ENABLE_FEATURE_HUMAN_READABLE=0
Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-20 18:55:17 +02:00
Denys Vlasenko cd7a38a87d false: make "false --help" exit with 1
function                                             old     new   delta
run_applet_no_and_exit                               447     445      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-18 00:47:05 +02:00
Ari Sundholm d0cdacafa9 df: implement -T option
function                                             old     new   delta
df_main                                              863     998    +135
packed_usage                                       29827   29861     +34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 169/0)             Total: 169 bytes

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-17 20:53:58 +02:00
Denys Vlasenko 9caea2448e sed: fix a buglet in s///NUM handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-16 01:11:13 +02:00
Denys Vlasenko 7666fa1d02 ftpd: make LIST command show dotfiles too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-15 23:35:58 +02:00
Denys Vlasenko 05399fc53d vi: fix incorrect memory access on brace matching. Closes 7256
While at it, fix brace matching to actually show the match
(missed fflush was causing cursor positioning to be buffered);
shorten brace matching code; remove unused macro indirection
in indicate_error().

Custom linker script 'busybox_ldscript' found, using it
function                                             old     new   delta
indicate_error                                         -      61     +61
mysleep                                               43      56     +13
char_insert                                          483     486      +3
find_pair                                            167     124     -43
Indicate_Error                                        61       -     -61
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/1 up/down: 77/-104)           Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-15 17:06:10 +02:00
Denys Vlasenko 26a8b9f196 mdev: treat zero-length /dev/mdev.seq the same as "\n" one. Closes 7334
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-08 18:19:15 +02:00
Denys Vlasenko 07f7ea70ed ash: fix off-by-one in "jobs %4" handling. closes 7310
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-08 17:21:52 +02:00
Denys Vlasenko 2ec34969e7 ash: factor out ASH_HELP config option
It used to be aliased to !FEATURE_SH_EXTRA_QUIET for ash,
while hush had it separate from FEATURE_SH_EXTRA_QUIET.

Bring ash in line with hush.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-08 16:52:39 +02:00
Denys Vlasenko 3e9b13e4c5 find: support -perm /BITS. Closes 7340
function                                             old     new   delta
parse_params                                        1487    1497     +10
func_perm                                             57      61      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 14/0)               Total: 14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-05 12:16:15 +02:00
Denys Vlasenko 4eb1e425fe tftpd: tweak HP PA-RISC firmware bug compatibility
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-04 12:24:03 +02:00
Denys Vlasenko 67e01fecce tftpd: support full 512-byte requests
Some HP PA-RISC firmware always sends fixed 512-byte requests,
with trailing garbage.

function                                             old     new   delta
tftpd_main                                           578     572      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-03 18:35:38 +02:00
Denys Vlasenko f02c52bcde taskset: fix logic error in "if it doesn't start with 0x..."
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-31 01:35:45 +02:00
Denys Vlasenko 34cc6c91a2 grep: fix "grep -r PATTRN SYMLINK_TO_DIR"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-28 15:50:09 +02:00
Florian Fainelli 6ff0551157 ping: add -p to specify data pattern
function                                             old     new   delta
common_ping_main                                    1788    1831     +43
sendping6                                             56      82     +26
sendping4                                             82     108     +26
packed_usage                                       29959   29938     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 95/-21)             Total: 74 bytes

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-27 16:01:25 +02:00
Denys Vlasenko 962c4e8220 taskset: support CPU masks for more than 64 CPUs
function                                             old     new   delta
taskset_main                                         522     631    +109

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-17 19:36:22 +02:00
Denys Vlasenko fb8d1ef2d0 addgroup: mention -S in the help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-15 14:29:43 +02:00
Denys Vlasenko e9ab07c211 ash: make ${#var} unicode-aware
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-13 18:00:08 +02:00
Denys Vlasenko 841f8331d7 ash,hush: run reinit_unicode() only if makes sense
With static Unicode support, no need to check $LANG et al.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-13 10:09:49 +02:00
Denys Vlasenko c538d5bcc3 hush: make ${#var} unicode-aware
This mimics bash

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-13 09:57:44 +02:00
Denys Vlasenko 45b4ecc868 init: if libc-based Unicode support is on, run setlocale(LC_ALL, "") at startup
It is not clear why we were excluding init from this.
The "getpid() != 1" clause was there from the beginning (2001)
but not explained.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-11 20:33:18 +02:00
Morten Kvistgaard feac9b607d ftpd: add optional support for authentication
function                                             old     new   delta
cmdio_get_cmd_and_arg                                  -     237    +237
get_passwd                                             -      97     +97
check_password                                         -      82     +82
ftpd_main                                           2297    2178    -119
ask_and_check_password_extended                      206      84    -122
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/2 up/down: 416/-241)          Total: 175 bytes

Signed-off-by: Morten Kvistgaard <MK@pch-engineering.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-05 21:57:18 +02:00
Denys Vlasenko 09a0e2223f sha3: tweak comments and indentation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-30 16:26:09 +02:00
Denys Vlasenko 4ff933c0e7 sha3: code shrink (and speedup for SHA3_SMALL=0)
function                                             old     new   delta
sha3_process_block72                                1454    1359     -95

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-30 14:18:57 +02:00
Denys Vlasenko 6c6d37ee45 top: fix memset length (sizeof(ptr) vs sizeof(array) problem)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-29 17:00:30 +02:00
Timo Teräs 7df1f1dda1 top: fix and merge code to parse /proc/meminfo
display_header() code to parse meminfo as is was buggy:
- uninitialized variables were used if meminfo was not as expected
- meminfo parsing failed on new kernels (3.14+) as new field 'MemAvailable'
  was introduced between MemFree and Buffers
- shared memory was handled only for ancient kernels (2.4.x and earlier)

as result Buffers and shared memory fields were shown with bogus values
on current kernels.

The new code does not try to parse the old style summary header, as the
separated fields are always present (it saves code size). Additionally,
both Shmem (2.6+) and MemShared (2.4 and earlier) fields are now parsed
and summed for shared memory usage; as only one of them exists depending
on kernel version.

display_topmem_header() parses also meminfo so this makes it use the
same code for code shrink.

function                                             old     new   delta
display_header                                         -     681    +681
display_topmem_process_list                          465     684    +219
parse_meminfo                                          -     189    +189
static.fields                                          -     106    +106
static.match                                         132       -    -132
.rodata                                           120254  120117    -137
display_topmem_header                                513       -    -513
display_process_list                                1705     667   -1038
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 1/2 up/down: 1195/-1820)       Total: -625 bytes

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-27 21:49:27 +02:00
Denys Vlasenko 2a563ea49a sha3: add 32-bit optimized bit-sliced implementation
It is an interesting trick, but so far I only managed to make it work
correctly, not to make it faster and/or smaller.
The code is ifdefed out for now.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-25 17:24:13 +02:00
Ken Sharp a4d564ad7c zcip: fix link-local IP conflict detection
During link-local IP resolution, if a regular ARP request is received
during the ARP probe period, it will incorrectly cause a target IP
conflict.  This then leads to a new IP being picked unnecessarily.

Per RFC 3927, section 2.2.1, we should flag a target IP conflict only if
the source IP is null, the target IP matches our IP, and the source
hw addr does not match our hw addr.

function                                             old     new   delta
zcip_main                                           1354    1322     -32

Signed-off-by: Ken Sharp <ken.sharp@ni.com>
Signed-off-by: Ben Shelton <ben.shelton@ni.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-20 14:01:49 +02:00
Jeremy Kerr b8ffd11e65 udhcp: add PXELINUX path prefix option (code 210) definition
Like d3092c99, this change adds support for the DHCP "path-prefix"
option, as defined in RFC 5071. We use the string identifer
"pxepathprefix".

Adding this option makes string parsing in the hook scripts simpler.

function                                             old     new   delta
dhcp_option_strings                                  255     269     +14
dhcp_optflags                                         72      74      +2

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-16 14:21:42 +02:00
Denys Vlasenko 278842dd72 ntpd: add support for -I IFACE
function                                             old     new   delta
packed_usage                                       29908   29947     +39
ntp_init                                             428     460     +32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 71/0)               Total: 71 bytes

Signed-off-by: Nikolaus Froehlich <nikolaus@mathematik.uni-marburg.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-15 15:06:54 +02:00
David Marchand 7d16964c3e modinfo: fix module parsing with kernel >= 2.6.37
display() function returns the length of the value we are displaying + 1.
As a consequence, if we have field=value\0field=value\0field=value in the
binary, then the second occurence will be skipped as ptr will miss the first
character of the following field.

Example trying to list aliases from ixgbe.ko on a 3.2 kernel.

- In the module we have:
alias=pci:v00008086d00001560sv*sd*bc*sc*i*\0
alias=pci:v00008086d0000154Asv*sd*bc*sc*i*\0
alias=pci:v00008086d00001557sv*sd*bc*sc*i*\0
alias=pci:v00008086d0000154Fsv*sd*bc*sc*i*\0
alias=pci:v00008086d0000154Dsv*sd*bc*sc*i*\0
...

- Using modinfo -F alias ixgbe returns:
alias:          pci:v00008086d00001560sv*sd*bc*sc*i*
alias:          pci:v00008086d00001557sv*sd*bc*sc*i*
alias:          pci:v00008086d0000154Dsv*sd*bc*sc*i*
...

This problem appeared with kernel commit "modules: no need to align .modinfo
strings" b6472776816af1ed52848c93d26e3edb3b17adab in 2.6.37.

Fix this by not trusting display() return value but increment ptr by strlen(ptr)
(the same way as depmod.c does).

Signed-off-by: David Marchand <david.marchand@6wind.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-04 16:39:28 +02:00
Denys Vlasenko 03e17bfa8d fatattr: use the standard type for 32-bit int
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-04 15:16:46 +02:00
Denys Vlasenko 6e17766c33 setlogcons: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-04 13:58:57 +02:00
Joshua Judson Rosen ae57fcad5d syslogd: make "reopen log file every second" logic work for multiple logs
Move last_log_time from a single global to *each logFile_t*
so that we can actually apply the logic to every log-file
in multi-file configurations, rather than working only
for the first file written in each 1-second interval
and then leaving the others connected to possibly wrong files.

Signed-off-by: Joshua Judson Rosen <jrosen@harvestai.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-03 14:51:47 +02:00
Joshua Judson Rosen e46047aa87 syslogd: syslogd: don't *decrement* log_file->size on write failures
Even if we fail to write to a log-file, and it's not growing,
it's not *shrinking* either....

Signed-off-by: Joshua Judson Rosen <jrosen@harvestai.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-02 19:41:41 +02:00
Denys Vlasenko a28c1b21e1 syslogd: make "-O -" log to stdout
function                                             old     new   delta
packed_usage                                       29871   29908     +37
log_locally                                          404     440     +36
syslogd_main                                        1966    1956     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 73/-10)             Total: 63 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-02 15:21:30 +02:00
Denys Vlasenko 98654b995b test: fix mishandling of "test '(' = '('" and similar
function                                             old     new   delta
test_main                                            246     350    +104

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-01 14:16:28 +02:00
Denys Vlasenko d32fc647d7 libbb: fix bb_ask() to flush input before prompt, not after. Closes 7190
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-07-01 13:20:22 +02:00
Denys Vlasenko 184b266917 cpio: reinstate "options:" line in help text
Otherwise, help text is confusing: where do operation modes end
and where options start?

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-30 17:19:17 +02:00
Bartosz Golaszewski bf0f2c7aa6 Rename INIT_LAST to INIT_FUNC to avoid confusion
We don't have an INIT_FIRST, so let's rename INIT_LAST to INIT_FUNC
to imply that the function is called at program start-up.

Also: the priority argument for __attribute__((constructor)) isn't
used, so let's remove it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-30 16:26:57 +02:00
Pascal Bellard d3633b7e9c fatattr: new applet
function                                             old     new   delta
fatattr_main                                           -     281    +281
packed_usage                                       29821   29871     +50
bit_to_char                                            -      10     +10
applet_names                                        2472    2480      +8
applet_main                                         1436    1440      +4
applet_nameofs                                       718     720      +2
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 4/0 up/down: 355/0)             Total: 355 bytes

Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-30 13:06:39 +02:00
Denys Vlasenko a9dc7c2f59 lzop: add overflow check
See CVE-2014-4607
http://www.openwall.com/lists/oss-security/2014/06/26/20

function                                             old     new   delta
lzo1x_decompress_safe                               1010    1031     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-30 10:14:34 +02:00
Michael Gernoth 1b487ea8a6 stat: fix printing selinux context and null-dereference
busybox stat tries to always print the selinux context, even if it
is not requested which leads to a segmentation fault due to
dereferencing a null-pointer.

This also changes the format-string used to print the context to
so it actually produces useful output.

Signed-off-by: Michael Gernoth <michael@gernoth.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-27 14:08:29 +02:00
Denys Vlasenko 9d7cbdeee3 ftpd: do not use root_fd if we are not in chroot
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-27 13:53:35 +02:00
Denys Vlasenko 27c290f7f2 ftpd: for LIST, open current directory *in the child*
Last change introduced an open fd leak. This is the fix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-27 12:37:00 +02:00
Denys Vlasenko a6ae999b3b ftpd: escape chroot prior to re-executing ls helper
When we merely chdir to saved "real" root fd,
exec("proc/self/exe") works for static executables but not
for dynamic ones (they can't find their interpreter).

With this patch, we also *chroot* to real root.
As a bonus, this gives us proper usernames, timezone conversion
etc.

function                                             old     new   delta
popen_ls                                             203     259     +56
ftpd_main                                           2362    2366      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-27 12:24:39 +02:00
Denys Vlasenko 5f8daefb83 awk: fix handling of "if ... break ; else ..." - closes 7226
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-26 16:40:28 +02:00
Denys Vlasenko 0b0ccd4570 ftpd: optimize writes of LIST results a bit
function                                             old     new   delta
handle_dir_common                                    201     207      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-26 12:07:48 +02:00
Richard Genoud 2a870d091e nanddump: change default to --bb=skipbad
since mtd-utils 1.4.7, the default behaviour of nanddump is skipbad
(commit 2521d4f1b6b9866a9c89f3c11a4f6a3d763ff1d7)

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-25 17:38:30 +02:00
Richard Genoud 8feb25956f nanddump: kill -b Omit bad block
since mtd-utils 1.4.7, the omit bad block method has been removed.
(cf commit d8b8f780ec3c916f3990e9227d6bfbb22bf42ef8)

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-25 17:37:01 +02:00
Richard Genoud f17fbe1d36 nanddump: add options --bb=skipbad and padbad
In mtd-utils, the bad block options changed in favor of
--bb=[skipbad|padbad|dumpbad] and omitbad has been removed.

This patch add the --bb=skipbad and padbad methods to busybox' nanddump.
padbad is the current default behaviour.
The difference between skipbad and omitbad is this one:
On a 16K block NAND, if the 1st block of mtd0 is bad, we'll have:
nanddump  -b -l 16384 /dev/mtd0 | wc -c
0
nanddump  --bb=skipbad -l 16384 /dev/mtd0 | wc -c
16384 <- data from 1st good block

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-25 17:37:01 +02:00
Richard Genoud cbf3bfa57a nanddump: correct rounding to next page (lead to infinite loop)
The rounding to next page formula was wrong:
ex: (len | ~(meminfo->writesize - 1)) + 1;
len=128K
writesize=4K
(len | ~(meminfo->writesize - 1)) + 1 => 4 294 963 201 ?!

correct rounding formula:
((len - 1) | (meminfo->writesize - 1)) + 1 => 128K
len = 130K
((len - 1) | (meminfo->writesize - 1)) + 1 => 132K

modprobe nandsim parts="20,20" badblocks="22,23"

without patch:
nanddump  /dev/mtd1 | wc -c
[...] infinite loop

with the patch:
nanddump /dev/mtd1 | wc -c
327680

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-25 16:37:37 +02:00
Denys Vlasenko de3cae1348 ftpd: support deprecated XPWD command
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-25 16:23:59 +02:00
Denys Vlasenko 5aeae36e2b libbb: fix compile failure if both ARG_MAX and _SC_ARG_MAX are defined
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-25 15:39:27 +02:00
Isaac Dunham ea23c25e96 unlink: new applet
function                                             old     new   delta
unlink_main                                            -      45     +45
packed_usage                                       29667   29686     +19

Signed-off-by: Isaac Dunham <ibid.ag@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-22 20:44:25 +02:00
Bartosz Golaszewski 3ed81cf052 unit-tests: implement the unit-testing framework
This set of patches adds a simple unit-testing framework to Busybox

unit-tests: add some helper macros for unit-test framework implementation
unit-tests: implement the unit-testing framework
unit-tests: add basic documentation on writing the unit test cases
unit-tests: modify the Makefile 'test' target to run unit-tests too
unit-tests: add two example test cases
unit-tests: modify the existing strrstr test code to use the unit-test framework

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-22 16:30:41 +02:00
Bartosz Golaszewski 5d2e409ef8 libbb: use a wrapper around sysconf(_SC_CLK_TCK) to save a few bytes
function                                             old     new   delta
bb_sc_clk_tck                                          -      10     +10
timescmd                                             118     113      -5
print_route                                         1763    1758      -5
mpstat_main                                         1288    1283      -5
iostat_main                                         1947    1942      -5
INET_setroute                                        879     871      -8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/5 up/down: 10/-28)            Total: -18 bytes
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-22 14:01:13 +02:00
Denys Vlasenko f92f1d0181 find: use sysconf(_SC_ARG_MAX) to determine the command-line size limit
The find utility uses a hardcoded value of 32 * 1024 as the limit of
the command-line length when calling 'find -exec ... {} +'. This results
in over 4 times more execve() calls than in coreutils' find.

This patch uses the limit defined in system headers.

Based on the patch by  Bartosz Golaszewski <bartekgola@gmail.com>.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-22 13:54:40 +02:00
Denys Vlasenko 6be3a5242c find: exit code fixes for find -exec
function                                             old     new   delta
func_exec                                            127     100     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-19 11:32:11 +02:00
Bartosz Golaszewski 14158b4127 find: add optional support for '-exec ... {} +'
function                                             old     new   delta
do_exec                                                -     309    +309
parse_params                                        1416    1487     +71
find_main                                            342     406     +64
packed_usage                                       29958   30014     +56
func_exec                                            138     127     -11
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 500/-11)           Total: 489 bytes

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-17 17:09:41 +02:00
Denys Vlasenko 85090c162b udhcpc: make hostname sanitization optional. Closes 3979
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-16 00:17:00 +02:00
Joshua Judson Rosen 9aa6ffb22b syslogd: Unify unlink/truncate + unlock log-rotation logic
Always unlink + reopen, rather than sometimes using ftruncate();
using a single code-path reduces the opportunity for either
mistakes or duplicate code.

Signed-off-by: Joshua Judson Rosen <jrosen@harvestai.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-02 03:11:40 +02:00
Joshua Judson Rosen b905d6c2ea syslogd: remember to un-writelock log-files even when called with "-b 0"
Signed-off-by: Joshua Judson Rosen <jrosen@harvestai.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-02 03:11:39 +02:00
Joshua Judson Rosen 1b90e031c3 syslogd: avoid spurious ftrunctate() calls for "-b 0"
Forgetting to re-set log_file->size after truncating to zero
discards log-data for the next 1 second following an oversize-induced purge,
when we shouldn't necessarily throw that data away.

Signed-off-by: Joshua Judson Rosen <jrosen@harvestai.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-02 03:11:38 +02:00
Denys Vlasenko fd0640e5a1 modprobe-small: fix safe_strncpy truncating last char of module name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-26 15:01:13 +02:00
Denys Vlasenko 17f8418ea7 Add conditional support for -v / --verbose
With FEATURE_VERBOSE off, practically no size change.
With it on:

function                                             old     new   delta
remove_file                                          493     556     +63
install_main                                         719     765     +46
bb_make_directory                                    383     419     +36
rmdir_main                                           162     191     +29
copy_file                                           1516    1544     +28
mv_main                                              502     525     +23
cmp_main                                             677     693     +16
bbconfig_config_bz2                                 5264    5279     +15
mkdir_main                                           158     168     +10
install_longopts                                      66      76     +10
rm_main                                              167     175      +8
nexpr                                                840     846      +6
scan_tree                                            275     280      +5
fsck_main                                           1807    1811      +4
ed_main                                             2541    2545      +4
expand_one_var                                      1574    1575      +1
swap_on_off_main                                     420     418      -2
parse_command                                       1443    1440      -3
redirect                                            1279    1274      -5
do_load                                              946     918     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 16/4 up/down: 304/-38)          Total: 266 bytes

Based on the patch by Igor Živković.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-19 16:23:50 +02:00
Denys Vlasenko 539e2802eb getty: explain when setsid() fails. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-11 00:00:52 +02:00
Denys Vlasenko 62a40a0448 Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox 2014-05-11 00:00:51 +02:00
Denys Vlasenko d257608a84 trylink: emit names of linked executables
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-04 17:35:31 +02:00
Tito Ragusa a875d59d24 which: rewrite
function                                             old     new   delta
which_main                                           237     212     -25

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-04 17:35:31 +02:00
Denys Vlasenko e3366d696c trylink: emit names of linked executables
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-03 16:35:15 +02:00
Timo Teräs 1e3cce6814 which: rewrite
function                                             old     new   delta
which_main                                           237     212     -25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-03 16:34:36 +02:00
Denys Vlasenko e765b5ac34 libbb: rename execable -> executable. No code changes
English speakers complained that it sounded awfully broken.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02 17:15:58 +02:00
Denys Vlasenko 15a357e596 libbb: fix empty PATH components handling
function                                             old     new   delta
find_execable                                         81      86      +5
exists_execable                                       71      66      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02 17:08:29 +02:00
Denys Vlasenko a4476eb654 rtcwake: fix incorrect (reversed) rtc/sys adjuestment; code shrink
function                                             old     new   delta
rtcwake_main                                         482     462     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02 12:46:15 +02:00
Denys Vlasenko d8290c2ef0 libbb: fix thinko in rtc_xopen()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02 09:07:16 +02:00
Denys Vlasenko 528808fa7b libbb: make rtc_xopen try harder on EBUSY
function                                             old     new   delta
rtc_xopen                                             77     139     +62

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02 09:05:03 +02:00
Denys Vlasenko fe33683c8b Fix compile failures
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-05-02 07:18:55 +02:00
Denys Vlasenko 43b8a1cc38 crond: implement "SHELL=prog" in crontab. Export LOGNAME as POSIX wants
function                                             old     new   delta
fork_job                                             343     456    +113
load_crontab                                         688     777     +89
crond_main                                          1456    1434     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 202/-22)           Total: 180 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-30 17:38:27 +02:00
Denys Vlasenko d5929d602e crond: simplify logging code
Slight change in behavior: now -l 5 will enable the same messages
formerly only enabled for -d 5. (Old behavior was non-sensical).

function                                             old     new   delta
reopen_logfile_to_stderr                               -      34     +34
log8                                                   -      26     +26
log7                                                   -      26     +26
log5                                                   -      26     +26
load_crontab                                         706     688     -18
rescan_crontab_dir                                   157     137     -20
crond_main                                          1486    1456     -30
fork_job                                             389     343     -46
crondlog                                             108      38     -70
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 0/5 up/down: 112/-184)          Total: -72 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-30 14:49:52 +02:00
Denys Vlasenko 3dfe0ae5a8 libbb: make syslog level for bb_error_msg's configurable. use it in crond
function                                             old     new   delta
bb_verror_msg                                        380     386      +6
syslog_level                                           -       1      +1
crondlog                                             165     108     -57

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-30 14:48:28 +02:00
Denys Vlasenko 01a1a967c9 crond: tweak help text, make course less cryptic
function                                             old     new   delta
packed_usage                                       29736   29740      +4
crond_main                                          1485    1486      +1
load_crontab                                         712     706      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-30 14:47:28 +02:00
Denys Vlasenko 07e5555a8f modprobe-small: (un)load all modules which match the alias, not only first one
Closes 627 and 7034.

Commonly seen case is (un)loading of an alias
which matches ata_generic and a more specific ata module.

For example:

modprobe [-r] pci:v00008086d00007010sv00000000sd00000000bc01sc01i80
(ata_generic and pata_acpi)

modprobe [-r] pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a
(ata_generic and pata_via)

function                                             old     new   delta
process_module                                       615     728    +113
parse_module                                         309     395     +86
find_alias                                           621     653     +32
pathname_matches_modname                              78      79      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 232/0)             Total: 232 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-21 16:59:36 +02:00
Denys Vlasenko 5a21c8550e ntpd: fix wrong delay value in one of the printed messages
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-20 13:04:23 +02:00
Denys Vlasenko d531f93f64 ntpd: truly ignore high delay packet
Before this cahnge, sometimes they were used after the next packet
from another peer was received, because we did updare some peer stats
from high delay packet before dropping it.

function                                             old     new   delta
recv_and_process_peer_pkt                            922     966     +44

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-19 19:00:16 +02:00
Denys Vlasenko 6116cb23cc modprobe-small: remove redundant aliases from modules.dep.bb
function                                             old     new   delta
parse_module                                         309     395     +86

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-19 16:17:27 +02:00
Denys Vlasenko 5fd3ddfb24 modprobe-small: fix help messages for aliased module-related applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-19 15:04:39 +02:00
Denys Vlasenko e152cb8189 adjtimex: make its help text and printed data a bit less cryptic
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-17 11:29:34 +02:00
Denys Vlasenko eb9f485b07 libbb/obscure.c: code shrink. Suggested by Tito.
function                                             old     new   delta
string_checker                                        97      92      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-16 19:51:34 +02:00
Denys Vlasenko 3fa97af7cc ash,hush: set $HOSTNAME is bash compat. Closes 7028
function                                             old     new   delta
hush_main                                           1056    1128     +72
ash_main                                            1442    1487     +45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-15 11:43:29 +02:00
Bernhard Reutner-Fischer ad16741ccd libbb: provide usleep() fallback implementation
POSIX.1-2008 removed the usleep function, provide a fallback
implementaion using the recommended nanosleep().

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-13 16:37:57 +02:00
Denys Vlasenko 69b114fb8a less: fix bugs discovered with "git log -p | less -m" on kernel tree
function                                             old     new   delta
read_lines                                           685     733     +48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-13 16:02:59 +02:00
Denys Vlasenko 32afd3aa60 vi: some simplifications
function                                             old     new   delta
file_insert                                          301     315     +14
init_text_buffer                                     179     171      -8
colon                                               2889    2878     -11
file_size                                             37       -     -37
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 14/-56)            Total: -42 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-05 22:57:46 +02:00
Denys Vlasenko e7430867a8 vi: clear undo buffer when we change to another file
function                                             old     new   delta
init_text_buffer                                     156     190     +34
undo_push                                            360     382     +22
count_lines                                           74      72      -2
undo_pop                                             246     222     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 56/-26)             Total: 30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-03 12:47:48 +02:00
Denys Vlasenko 2c51202aec vi: undo code shrink
function                                             old     new   delta
undo_push                                            414     395     -19
do_cmd                                              4803    4761     -42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-03 01:45:05 +02:00
Jody Bruchon a8d6f9bee4 vi: undo support for vi with intermediate queuing
function                                             old     new   delta
undo_push                                              -     411    +411
undo_pop                                               -     288    +288
do_cmd                                              4160    4426    +266
char_insert                                          363     483    +120
undo_queue_commit                                      -      61     +61
text_hole_delete                                     108     163     +55
string_insert                                         94     127     +33
colon                                               2864    2882     +18
yank_delete                                           92     101      +9
vi_main                                              273     280      +7
dot_scroll                                            88      93      +5
dot_right                                             29      34      +5
dot_prev                                              20      25      +5
dot_next                                              20      25      +5
dot_left                                              24      29      +5
dot_end                                               20      25      +5
dot_begin                                             20      25      +5
init_text_buffer                                     154     156      +2
text_hole_make                                       145     142      -3
file_insert                                          333     318     -15
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 15/2 up/down: 1305/-18)        Total: 1287 bytes

(without queuing it's ~870 bytes)

Signed-off-by: Jody Bruchon <jody@jodybruchon.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-02 13:49:26 +02:00
Drew Moseley 7537406edd build system: specify '-nostldlib' when linking to .o files
For certain cross build scenarios the LD variable is overridden
to use the gcc executive to ensure all the target tuning parameters
are used.  In these cases, the executive errors out as shown below
but since this step is only linking to a .o file the standard libs
are not needed.

    $ make LD=gcc applets/built-in.o
      LD      applets/built-in.o
    /usr/bin/ld: cannot find -lgcc_s
    /usr/bin/ld: cannot find -lgcc_s
    collect2: ld returned 1 exit status
    make[1]: *** [applets/built-in.o] Error 1
    make: *** [applets_dir] Error 2

Signed-off-by: Drew Moseley <drew_moseley@mentor.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-02 12:12:46 +02:00
Tito Ragusa c9a67133d6 swapon/swapoff: -a returns 0 on ignored errors
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-04-01 09:51:27 +02:00
Tito Ragusa a3f326cd66 swapon/swapoff: size reduction, cleanup, fixes, improvements
1) real swapon/swapoff handles also devices on the commandline with -a;
2) xstat(device)  in  swap_enable_disable aborts on error when cycling through
   fstab so some devices  are not handled;
3) duplicated code for ENABLE_FEATURE_SWAPON_DISCARD and
   ENABLE_FEATURE_SWAPON_PRI was moved to functions.
4) silence some error messages with -a;
5) minor cleanups and code refactoring reduced the size as per bloat-check:
6) I also added support for /proc/swaps handling to swapoff:
"When the -a flag is given, swapping is disabled on all known  swap  devices
 and  files  (as  found  in  /proc/swaps  or /etc/fstab)."
So now swapoff first cycles through  /proc/swaps and then through fstab
to swapoff all devices.

function                                             old     new   delta
set_discard_flag                                       -     106    +106
swap_enable_disable                                  147     238     +91
set_priority_flag                                      -      79     +79
retrieve_file_data                                   470     467      -3
swap_on_off_main                                     638     418    -220
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 1/2 up/down: 276/-223)           Total: 53 bytes

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-31 16:39:26 +02:00
Denys Vlasenko faa9e94db6 wget: fix a case where progress bar isn't updated if writes are very slow
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-27 16:50:29 +01:00
Matt Whitlock 0a53b203f9 add discard option -d to swapon
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-23 18:36:23 +01:00
Matt Whitlock b9bbd4ddf6 fix interaction of -a and -p options in swapon
Swap entries in /etc/fstab inherit the priority specified on the command line unless they have 'pri' in their mount options.

Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-23 18:36:22 +01:00
Matt Whitlock c3a27b0bfd avoid calling bb_strtou twice in MIN macro expansion
Also, the maximum allowable value of swap priority is technically SWAP_FLAG_PRIO_MASK >> SWAP_FLAG_PRIO_SHIFT.

Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-23 18:36:22 +01:00
Denys Vlasenko 504fe45f35 ntpd: add optional support for /etc/ntp.conf
function                                             old     new   delta
add_peers                                              -      98     +98
packed_usage                                       29470   29511     +41
ntp_init                                             407     428     +21
pw_encrypt                                            14      27     +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 173/0)             Total: 173 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-23 18:34:51 +01:00
Denys Vlasenko f332617fbd docs/new-applet-HOWTO.txt: tweak a bit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-17 15:06:29 +01:00
Denys Vlasenko c50493854a libbb: fix a bad check for uclibc >= 0.9.31
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-16 20:53:40 +01:00
Bartosz Golaszewski 9dbe4d0547 docs: update new-applet-HOWTO.txt
This patch adds some information about the gen_build_files.sh script and how
it allows to keep the Kbuild, Config.in etc. declarations in .c files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-16 18:47:44 +01:00
Denys Vlasenko 109ee5d336 ash: make "locak VAR" unset VAR (bash does that)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-16 18:41:11 +01:00
Denys Vlasenko 438b4ac286 script: make it work even if fd 0 is closed
Testcase:
script -q -c "echo hey" /dev/null 0>&-

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-16 12:34:53 +01:00
Denys Vlasenko 29f3526048 build system: for "find", use POSIX not operator (!) instead of -not
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-16 12:05:58 +01:00
Romain Naour 0e3334c8d8 su: add a delay if the password is incorrect
Signed-off-by: Romain Naour <romain.naour@openwide.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-16 11:18:19 +01:00
Denys Vlasenko ac03a40cba ash,hush: fix a thinko about 2^64-1 factorization
function                                             old     new   delta
next_random                                          113     119      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-15 09:25:46 +01:00
Denys Vlasenko 2bba591991 hush: make "true" built-in
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-14 12:43:57 +01:00
Denys Vlasenko f93187512d random: cosmetic tweaks in debug code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-13 13:03:27 +01:00
Denys Vlasenko fb183076a3 ash,hush: improve randomness of $RANDOM, add easy-ish way to test it
function                                             old     new   delta
next_random                                           68     113     +45
change_random                                        103     121     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-13 12:52:43 +01:00
Denys Vlasenko 69f9567de2 shuf: trim help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-07 14:41:53 +01:00
Denys Vlasenko 102f0d0d07 shuf: do not use strings for -i RANGE case
function                                             old     new   delta
shuf_main                                            482     496     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-07 14:32:39 +01:00
Bartosz Golaszewski 190693ced1 shuf: improve help text
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-07 14:07:35 +01:00
Bartosz Golaszewski 58adbb5505 shuf: fix a segfault on 'shuf -e'
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-07 11:46:03 +01:00
Denys Vlasenko 0ed5f7aacd use [s]rand(), not [s]random()
rand() is the most standard C library function,
and on uclibc they are the same. I guess
they are the same in most todays' libc...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-05 18:58:15 +01:00
Denys Vlasenko 2cdcb1082c shuf: new applet
function                                             old     new   delta
shuf_main                                              -     478    +478
packed_usage                                       29571   29719    +148
applet_names                                        2460    2465      +5
applet_main                                         1428    1432      +4
applet_nameofs                                       714     716      +2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/0 up/down: 637/0)             Total: 637 bytes

Based on the code by Bartosz Golaszewski <bartekgola@gmail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-05 18:56:20 +01:00
Denys Vlasenko 30f17e9556 man: default to ascii
Default to ascii instead of latin1. Otherwise man pages can be displayed
incorrectly. E.g. bullets show as "<B7>".

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-03 15:14:26 +01:00
Denys Vlasenko ecd8c3affc ip link: add support for "address ETHADDR". Closes 4862
function                                             old     new   delta
do_iplink                                           2175    2289    +114

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-03-01 17:38:41 +01:00
Denys Vlasenko 81071e6872 unlzma: add comments about possible bug from BZ 2689
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-28 15:42:10 +01:00
Denys Vlasenko 2108a6f0b5 unlzma: move some variables in "more local" scope
No code changes as verified by objdump

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-28 15:05:43 +01:00
Denys Vlasenko e2318bbad7 udhcpc: ignore NAKs from "wrong" servers. Closes 4267
function                                             old     new   delta
udhcpc_main                                         2716    2814     +98

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-27 18:15:50 +01:00
Denys Vlasenko fca0ee5959 ls: make "ls -s DIR" show total too. Clases 4946
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-27 15:40:26 +01:00
Denys Vlasenko 3795266841 xargs: fix compilation breakage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-27 15:02:36 +01:00
Denys Vlasenko 83e49ade57 grep: fix -w match if first match isn't a word, but second is. Closes 4520
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-27 14:56:12 +01:00
Denys Vlasenko 6f068904dc xargs: add support for -I and -i. Closes 493
function                                             old     new   delta
process_stdin_with_replace                             -     195    +195
xmalloc_substitute_string                              -     145    +145
xargs_main                                           808     884     +76
count_strstr                                           -      45     +45
packed_usage                                       29580   29571      -9
parse_params                                        1445    1416     -29
func_exec                                            285     138    -147
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 1/3 up/down: 461/-185)          Total: 276 bytes
   text	   data	    bss	    dec	    hex	filename
 922156	    932	  17692	 940780	  e5aec	busybox_old
 922440	    932	  17692	 941064	  e5c08	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-27 11:17:06 +01:00
Denys Vlasenko 6885e49ba5 find: code shrink
function                                             old     new   delta
func_exec                                            306     285     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-26 15:27:10 +01:00
Denys Vlasenko c472898eaa nc: fix option bit positions. Closes 6926
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-26 13:58:59 +01:00
Denys Vlasenko 589051b565 hwclock: fix setting of tz_minuteswest. Closes 5414
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-25 17:52:10 +01:00
Denys Vlasenko 18b699c30f build system: remove a dead link from Config help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-25 17:31:22 +01:00
Denys Vlasenko 83bc4332e7 du, copy_file: fix file matching on cramfs. Closes 5456
function                                             old     new   delta
is_in_ino_dev_hashtable                               88     108     +20
add_to_ino_dev_hashtable                             150     142      -8
reset_ino_dev_hashtable                               84      75      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 20/-17)              Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-25 15:27:58 +01:00
Denys Vlasenko 12916b9220 libbb: trivial code shrink
function                                             old     new   delta
reset_ino_dev_hashtable                               84      74     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-25 15:09:01 +01:00
Denys Vlasenko 6554d03735 sysctl: do not error out showing write-only data. Closes 6386
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-24 17:28:43 +01:00
Denys Vlasenko a2796223cb wget: fix comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-24 17:20:40 +01:00
Denys Vlasenko 53315570bb wget: add commented-out code to use ssl_helper instead of openssl
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-23 23:39:47 +01:00
Denys Vlasenko d82046f59f networking/ssl_helper: experimental matrixssl-based ssl helper
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-23 23:31:13 +01:00
Denys Vlasenko 8b7e8ae224 wget: add support for https using "openssl s_client" as a helper
www.kernel.org started redirecting http:// to https://
making https support mandatory for any auto build scripts.

function                                             old     new   delta
wget_main                                           2631    2971    +340
parse_url                                            409     471     +62
.rodata                                           115607  115626     +19
P_HTTPS                                                -       6      +6
P_HTTP                                                 -       5      +5
P_FTP                                                  -       4      +4
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 3/0 up/down: 436/0)             Total: 436 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-22 14:12:29 +01:00
Denys Vlasenko 192c14bd87 Improve examples/var_service READMEs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-21 12:55:43 +01:00
Bartosz Golaszewski 265a74b983 Kbuild: move CONFIG_PAM to general configuration
Currently CONFIG_PAM depends on CONFIG_LOGIN, but is used by the httpd applet too.

This patch moves said option to general configuration, thus allowing to
compile httpd with PAM support independently from login.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-19 18:53:25 +01:00
Denys Vlasenko ffc3a93d0d udhcpc: fix BPF filter. Hopefully fixes the root cause of 4598 and 6746
Use a *signed* large positive value in BPF filter to indicate success.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-19 14:17:11 +01:00
Denys Vlasenko 50e4cc29f5 ifplugd: code shrink
function                                             old     new   delta
ifplugd_main                                        1161    1144     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-10 09:51:03 +01:00
Denys Vlasenko 3e78f6f955 htpd: trivial simplification in random interval selection
function                                             old     new   delta
poll_interval                                         57      52      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-09 15:35:04 +01:00
Denys Vlasenko 8ed9672660 libbb: don't die if crypt() returns NULL
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-09 14:38:03 +01:00
Kaarle Ritvanen 4e03d41342 sendmail: use FQDN in default envelope sender
RFC 5321 requires the return path to be supplied with a proper domain
name.

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-09 09:49:36 +01:00
Denys Vlasenko 744ee5db1c udhcpc: in comments, explain the kind of raw socket we create
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-07 17:38:52 +01:00
Bartosz Golaszewski 3ba2df874c grep: properly handle grep -w "^str" in !EXTRA_COMPAT case too
function                                             old     new   delta
grep_file                                           1267    1288     +21

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-07 17:15:56 +01:00
Denys Vlasenko 07f417b6ab sendmail: make -f optional, document its default value
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-05 15:01:39 +01:00
Denys Vlasenko e4785ca653 udhcpc: don't use BPF filter, users report problems (bugs 4598, 6746)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-03 18:03:42 +01:00
Kaarle Ritvanen fe8390e0fe ifupdown: support 'link' address family
Does not configure anything. L2 configuration hook scripts should do
their job on receiving ADDRFAM=link. Configuration will be done only
once, irrespective of L3 protocols used.

Using the 'link' family in the interfaces file conforms to the Debian
implementation:

http://sources.debian.net/src/ifupdown/0.7.47.1/link.defn

function                                             old     new   delta
link_methods                                           -      12     +12
addr_link                                              -      12     +12
link_up_down                                           -       6      +6
static.addr_fams                                      12      16      +4
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 1/0 up/down: 34/0)               Total: 34 bytes

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-03 15:56:20 +01:00
Denys Vlasenko d353bfff46 wget: fix use-after-free of ->user. Closes 6836
function                                             old     new   delta
wget_main                                           2207    2223     +16
parse_url                                            339     353     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-03 14:09:42 +01:00
Denys Vlasenko 69a12fa790 catv: suppress compiler warning
The warning was:
warning: typedef 'BUG_const_mismatch' locally defined but not used [-Wunused-local-typedefs]

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-03 03:27:53 +01:00
Denys Vlasenko 640ce3de07 zcat: complain if input is not compressed
function                                             old     new   delta
buffer_fill_and_print                                178     191     +13
varvalue                                             735     743      +8
bbunpack                                             747     755      +8
open_zipped                                           85      89      +4
xmalloc_open_zipped_read_close                        61      63      +2
get_addr_1                                           240     242      +2
fbsplash_main                                       1228    1230      +2
pstree_main                                          322     321      -1
builtin_type                                         121     119      -2
do_load                                              954     926     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/3 up/down: 39/-31)              Total: 8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-02-02 02:06:38 +01:00
Mike Frysinger f1999b5a9d appletlib: fix set-but-unused warning
When you build with FEATURE_INSTALLER disabled, you get a build
warning like so:

libbb/appletlib.c: In function 'busybox_main':
libbb/appletlib.c:691:7: warning: variable 'use_symbolic_links' set but
                                  not used [-Wunused-but-set-variable]
   int use_symbolic_links;
       ^

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2014-01-31 00:29:47 -05:00
Mike Frysinger 29ed580668 uname: fix up usage documentation
The -i/-o options were missing, and the -r/-s/-v options were
incorrectly labeled as "OS" instead of "kernel".

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2014-01-31 00:28:42 -05:00
Michael Tokarev 922fdf6527 init: do not fail build if SIGPWR is not defined
Apparently, some *BSD variants (and maybe some other OSes) does not define
SIGPWR signal.  So since commit 760fc6debc, busybox fails to build on
such platforms.  Fix this.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-30 13:22:04 +01:00
Denys Vlasenko b664f740d9 libbb: open_zipped() should not fail on non-compressed files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-27 13:02:18 +01:00
Michael Tokarev bf2f2229bb testsuite: fix last "which" change
In commit afa63b2dcd I replaced `type -p' with
`command -pv'.  But actually it is wrong, the right
substitution is `command -v'.  We need to find our
busybox which is in the first directory in $PATH, so
`command -p' should not be used because it uses
default PATH, not current value of PATH where our
busybox binary resides.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-23 14:41:53 +01:00
Denys Vlasenko 821e64316a less: accept and ignore -s
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-22 16:36:22 +01:00
John Spencer ff65061311 man: parse "DEFINE pager" in config
function                                             old     new   delta
man_main                                             789     844     +55

Signed-off-by: John Spencer <maillist-busybox@barfooze.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-22 15:31:10 +01:00
Eugene Rudoy 731f596175 iplink: fix build with kernel versions prior to 2.6.23
Signed-off-by: Eugene Rudoy <gene.devel@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-22 11:49:46 +01:00
Denys Vlasenko fa6ab56353 libbb: if opening /dev/loopN returns ENXIO, don't try N++.
function                                             old     new   delta
set_loop                                             639     635      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-21 13:44:21 +01:00
Denys Vlasenko 3b394781b5 libbb: fix parsing of "10101010" date/time form
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-21 07:58:18 +01:00
Bartosz Golaszewski 2de232da53 top.c: fix compilation warnings
pfd[1] is unused

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-20 03:26:34 +01:00
Denys Vlasenko c009d35f00 ntpd: remove now unnecessary check for IP_PKTINFO definition
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-20 03:24:51 +01:00
Bartosz Golaszewski 76ad7481b1 ntpd: fix compilation warnings
GCC complained about since_last_update being set but not used.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-20 03:21:08 +01:00
Bartosz Golaszewski 5c13ab41bb sort: check global flags on fallback sort
Sort now performs global reverse on fallback sort if -r is set. Before
only key local flags were checked.

function                                             old     new   delta
compare_keys                                         712     738     +26

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-19 09:10:14 +01:00
Bartosz Golaszewski 1a4d9f6521 sort.c: remove a magic number from compare_keys()
Use bitwise OR of proper flags instead.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-19 06:47:06 +01:00
Bartosz Golaszewski 49111cdc4f gitignore: ignore files generated by 'make test'
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-19 04:29:59 +01:00
Tito Ragusa 891b98c9bc adduser,addgroup: introduce and use CONFIG_LAST_ID
Changes adduser.c, addgroup.c and Config.src to set and use CONFIG_LAST_ID.

function                                             old     new   delta
adduser_main                                         841     865     +24
addgroup_main                                        407     425     +18

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-17 09:17:55 +01:00
Denys Vlasenko 2e66daca65 examples/udhcp: do not rewrite resolv.conf if no DNS servers. Closes 6788
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-13 13:38:53 +01:00
Denys Vlasenko d74f8435ea docs: tweak keep_data_small.txt
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-13 11:45:34 +01:00
Denys Vlasenko 0f592d7fb9 tar: tighten up pax header validity check
function                                             old     new   delta
get_header_tar                                      1785    1795     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10 18:02:38 +01:00
Denys Vlasenko 604b7b6cc0 fakeidentd: simplify ndelay manipulations
function                                             old     new   delta
new_peer                                              91      79     -12
do_rd                                                197     152     -45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10 17:12:54 +01:00
Cristian Ionescu-Idbohrn 1bdbf26454 tail: adjust help/usage texts
Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10 16:26:15 +01:00
Denys Vlasenko 79df481dc4 lineedit: fix trivial build failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10 14:38:26 +01:00
Denys Vlasenko 7c47b560a8 libarchive: open_zipped() does not need to check extensions for e.g. gzip
We only need to check for signature-less extensions,
currently only .lzma. The rest can be happily autodetected.

This fixes "zcat FILE_WITHOUT_GZ_EXT" case, among others.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10 14:12:11 +01:00
Matthias Andree 9b76f895bc build system: fix non-portable sed constructs.
This includes proper line breaks for labels and closing braces,
and removing non-portable \n and \t in s/// functions.

Signed-off-by: Matthias Andree <matthias.andree@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10 11:54:37 +01:00
Denys Vlasenko 3deabea893 fixlet for the previous commit #2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 20:09:43 +01:00
Denys Vlasenko abaf9109bd fixlet for the previous commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 20:05:47 +01:00
Denys Vlasenko 3ea93e853e networking: explain isrv_run() API
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 19:58:19 +01:00
Ryan Mallon 89deb22f97 fakeidentd: fix use-after-free
function                                             old     new   delta
do_rd                                                199     197      -2

Signed-off-by: Ryan Mallon <rmallon@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 19:15:16 +01:00
Denys Vlasenko 16ca379b55 chown: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 17:52:13 +01:00
Denys Vlasenko 6eb0cbe07e find: fix a regression introduced with -HLP support
function                                             old     new   delta
find_main                                            294     342     +48

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 16:08:09 +01:00
Denys Vlasenko f0058b1b1f ping: revert "try SOCK_DGRAM if no root privileges"
It wasn't working, and fixes on top of it would make ping
noticeably larger.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 11:53:26 +01:00
Denys Vlasenko e4569be244 build system: "make hosttools" doesn't exist, remove it from "make help"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 11:03:46 +01:00
Denys Vlasenko f2743a5b00 build system: stop including alloca.h, stdlib.h provides it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-09 11:02:46 +01:00
Denys Vlasenko cb7611385c ntpd: adjust last packet's recv time after a step
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-08 17:17:52 +01:00
Denys Vlasenko 96f92a1afa libbb: FreeBSD fix for B<num> baud rate constants not fitting into a short.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-08 15:25:20 +01:00
Denys Vlasenko 8e0ad2647a Another FreeBSD fix from Matthias Andree
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-08 15:10:54 +01:00
Denys Vlasenko 5680e98451 ash: in bash compat mode, always export $SHLVL
function                                             old     new   delta
ash_main                                            1437    1442      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-07 16:12:48 +01:00
Denys Vlasenko cd55f2d933 grep: fix two bugs with -w
Unfortunately, with !EXTRA_COMPAT, "grep -w ^str" still erroneously matches "strstr".

function                                             old     new   delta
grep_file                                           1499    1510     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-07 14:59:30 +01:00
Denys Vlasenko 432fbd7a1a platform.h: undef HAVE_STRCHRNUL only on correct versions of FreeBSD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-07 14:09:47 +01:00
Denys Vlasenko 57434022ce Start 1.23.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-01 00:44:30 +01:00
195 changed files with 6435 additions and 2335 deletions

No files matched your search

+7
View File
@@ -35,3 +35,10 @@ Config.in
core
.gdb_history
.gdbinit
#
# testing output
#
/busybox.links
/runtest-tempdir-links
/testsuite/echo-ne
+29 -4
View File
@@ -257,6 +257,26 @@ config UNICODE_PRESERVE_BROKEN
at shell prompt will list file named 0xff (single char name
with char value 255), not file named '?'.
config PAM
bool "Support for PAM (Pluggable Authentication Modules)"
default n
help
Use PAM in some busybox applets (currently login and httpd) instead
of direct access to password database.
config FEATURE_USE_SENDFILE
bool "Use sendfile system call"
default y
select PLATFORM_LINUX
help
When enabled, busybox will use the kernel sendfile() function
instead of read/write loops to copy data between file descriptors
(for example, cp command does this a lot).
If sendfile() doesn't work, copying code falls back to read/write
loop. sendfile() was originally implemented for faster I/O
from files to sockets, but since Linux 2.6.33 it was extended
to work for many more file types.
config LONG_OPTS
bool "Support for --long-options"
default y
@@ -416,10 +436,7 @@ config SELINUX
the option of compiling in SELinux applets.
If you do not have a complete SELinux userland installed, this stuff
will not compile. Go visit
http://www.nsa.gov/selinux/index.html
to download the necessary stuff to allow busybox to compile with
this option enabled. Specifially, libselinux 1.28 or better is
will not compile. Specifially, libselinux 1.28 or better is
directly required by busybox. If the installation is located in a
non-standard directory, provide it by invoking make as follows:
CFLAGS=-I<libselinux-include-path> \
@@ -671,6 +688,14 @@ config DEBUG_PESSIMIZE
in a much bigger executable that more closely matches the source
code.
config UNIT_TEST
bool "Build unit tests"
default n
help
Say Y here if you want to build unit tests (both the framework and
test cases) as a Busybox applet. This results in bigger code, so you
probably don't want this option in production builds.
config WERROR
bool "Abort compilation on any warning"
default n
+2 -2
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 22
SUBLEVEL = 0
PATCHLEVEL = 23
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
+4
View File
@@ -55,7 +55,11 @@ endif
# (cp -pPR is POSIX-compliant (cp -dpR or cp -a would not be))
.PHONY: check
.PHONY: test
ifeq ($(CONFIG_UNIT_TEST),y)
UNIT_CMD = ./busybox unit
endif
check test: busybox busybox.links
$(UNIT_CMD)
test -d $(objtree)/testsuite || cp -pPR $(srctree)/testsuite $(objtree)
bindir=$(objtree) srcdir=$(srctree)/testsuite \
$(SHELL) -c "cd $(objtree)/testsuite && $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)"
-4
View File
@@ -21,10 +21,6 @@ help:
@echo ' defconfig - set .config to largest generic configuration'
@echo ' menuconfig - interactive curses-based configurator'
@echo ' oldconfig - resolve any unresolved symbols in .config'
@echo ' hosttools - build sed for the host.'
@echo ' You can use these commands if the commands on the host'
@echo ' is unusable. Afterwards use it like:'
@echo ' make SED="$(objtree)/sed"'
@$(if $(boards), \
$(foreach b, $(boards), \
printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
+17
View File
@@ -14,6 +14,7 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#undef ARRAY_SIZE
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
@@ -49,6 +50,16 @@ static int cmp_name(const void *a, const void *b)
return strcmp(aa->name, bb->name);
}
static int str_isalnum_(const char *s)
{
while (*s) {
if (!isalnum(*s) && *s != '_')
return 0;
s++;
}
return 1;
}
int main(int argc, char **argv)
{
int i;
@@ -94,6 +105,12 @@ int main(int argc, char **argv)
}
printf(";\n\n");
for (i = 0; i < NUM_APPLETS; i++) {
if (str_isalnum_(applets[i].name))
printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
}
printf("\n");
printf("#ifndef SKIP_applet_main\n");
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
for (i = 0; i < NUM_APPLETS; i++) {
+17 -39
View File
@@ -39,7 +39,7 @@ char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
}
int FAST_FUNC bbunpack(char **argv,
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
const char *expected_ext
)
@@ -48,7 +48,7 @@ int FAST_FUNC bbunpack(char **argv,
IF_DESKTOP(long long) int status = 0;
char *filename, *new_name;
smallint exitcode = 0;
transformer_aux_data_t aux;
transformer_state_t xstate;
do {
/* NB: new_name is *maybe* malloc'ed! */
@@ -72,7 +72,8 @@ int FAST_FUNC bbunpack(char **argv,
goto err;
} else {
/* "clever zcat" with FILE */
int fd = open_zipped(filename);
/* fail_if_not_compressed because zcat refuses uncompressed input */
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
if (fd < 0)
goto err_name;
xmove_fd(fd, STDIN_FILENO);
@@ -80,7 +81,7 @@ int FAST_FUNC bbunpack(char **argv,
} else
if (option_mask32 & SEAMLESS_MAGIC) {
/* "clever zcat" on stdin */
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0))
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
goto err;
}
@@ -119,9 +120,11 @@ int FAST_FUNC bbunpack(char **argv,
}
if (!(option_mask32 & SEAMLESS_MAGIC)) {
init_transformer_aux_data(&aux);
aux.check_signature = 1;
status = unpacker(&aux);
init_transformer_state(&xstate);
xstate.check_signature = 1;
/*xstate.src_fd = STDIN_FILENO; - already is */
xstate.dst_fd = STDOUT_FILENO;
status = unpacker(&xstate);
if (status < 0)
exitcode = 1;
} else {
@@ -140,10 +143,10 @@ int FAST_FUNC bbunpack(char **argv,
unsigned new_name_len;
/* TODO: restore other things? */
if (aux.mtime != 0) {
if (xstate.mtime != 0) {
struct timeval times[2];
times[1].tv_sec = times[0].tv_sec = aux.mtime;
times[1].tv_sec = times[0].tv_sec = xstate.mtime;
times[1].tv_usec = times[0].tv_usec = 0;
/* Note: we closed it first.
* On some systems calling utimes
@@ -225,18 +228,13 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
#if ENABLE_UNCOMPRESS
static
IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
{
return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
}
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uncompress_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, "cf");
argv += optind;
return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
}
#endif
@@ -323,11 +321,6 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
}
return filename;
}
static
IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
{
return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
}
/*
* Linux kernel build uses gzip -d -n. We accept and ignore it.
* Man page says:
@@ -354,7 +347,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
if (applet_name[1] == 'c')
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
}
#endif
@@ -394,11 +387,6 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
#if ENABLE_BUNZIP2
static
IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
{
return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
}
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
{
@@ -407,7 +395,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
if (applet_name[2] == 'c') /* bzcat */
option_mask32 |= OPT_STDOUT;
return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
}
#endif
@@ -493,11 +481,6 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
#if ENABLE_UNLZMA
static
IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
{
return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
}
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlzma_main(int argc UNUSED_PARAM, char **argv)
{
@@ -512,7 +495,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
option_mask32 |= OPT_STDOUT;
argv += optind;
return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
}
#endif
@@ -536,11 +519,6 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
#if ENABLE_UNXZ
static
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
{
return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
}
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unxz_main(int argc UNUSED_PARAM, char **argv)
{
@@ -555,6 +533,6 @@ int unxz_main(int argc UNUSED_PARAM, char **argv)
option_mask32 |= OPT_STDOUT;
argv += optind;
return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
}
#endif
+1 -1
View File
@@ -127,7 +127,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
}
static
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_aux_data_t *aux UNUSED_PARAM)
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
{
IF_DESKTOP(long long) int total;
ssize_t count;
+1
View File
@@ -65,6 +65,7 @@
//usage: IF_FEATURE_CPIO_P(
//usage: "\n -p DIR Copy files to DIR"
//usage: )
//usage: "\nOptions:"
//usage: "\n -d Make leading directories"
//usage: "\n -m Preserve mtime"
//usage: "\n -v Verbose"
+1 -1
View File
@@ -2042,7 +2042,7 @@ static void zip(ulg time_stamp)
/* ======================================================================== */
static
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
{
struct stat s;
+5 -6
View File
@@ -731,7 +731,7 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
IF_DESKTOP(long long) int FAST_FUNC
unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
unpack_bz2_stream(transformer_state_t *xstate)
{
IF_DESKTOP(long long total_written = 0;)
bunzip_data *bd;
@@ -739,14 +739,14 @@ unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
int i;
unsigned len;
if (check_signature16(aux, src_fd, BZIP2_MAGIC))
if (check_signature16(xstate, BZIP2_MAGIC))
return -1;
outbuf = xmalloc(IOBUF_SIZE);
len = 0;
while (1) { /* "Process one BZ... stream" loop */
i = start_bunzip(&bd, src_fd, outbuf + 2, len);
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
if (i == 0) {
while (1) { /* "Produce some output bytes" loop */
@@ -756,8 +756,7 @@ unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
i = IOBUF_SIZE - i; /* number of bytes produced */
if (i == 0) /* EOF? */
break;
if (i != full_write(dst_fd, outbuf, i)) {
bb_error_msg("short write");
if (i != transformer_write(xstate, outbuf, i)) {
i = RETVAL_SHORT_WRITE;
goto release_mem;
}
@@ -790,7 +789,7 @@ unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
len = bd->inbufCount - bd->inbufPos;
memcpy(outbuf, &bd->inbuf[bd->inbufPos], len);
if (len < 2) {
if (safe_read(src_fd, outbuf + len, 2 - len) != 2 - len)
if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len)
break;
len = 2;
}
+20 -22
View File
@@ -971,7 +971,7 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
/* Called from unpack_gz_stream() and inflate_unzip() */
static IF_DESKTOP(long long) int
inflate_unzip_internal(STATE_PARAM int in, int out)
inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
{
IF_DESKTOP(long long) int n = 0;
ssize_t nwrote;
@@ -980,7 +980,7 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
gunzip_window = xmalloc(GUNZIP_WSIZE);
gunzip_outbuf_count = 0;
gunzip_bytes_out = 0;
gunzip_src_fd = in;
gunzip_src_fd = xstate->src_fd;
/* (re) initialize state */
method = -1;
@@ -1002,9 +1002,8 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
while (1) {
int r = inflate_get_next_window(PASS_STATE_ONLY);
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
if (nwrote != (ssize_t)gunzip_outbuf_count) {
bb_perror_msg("write");
nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count);
if (nwrote == (ssize_t)-1) {
n = -1;
goto ret;
}
@@ -1034,22 +1033,22 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
/* For unzip */
IF_DESKTOP(long long) int FAST_FUNC
inflate_unzip(transformer_aux_data_t *aux, int in, int out)
inflate_unzip(transformer_state_t *xstate)
{
IF_DESKTOP(long long) int n;
DECLARE_STATE;
ALLOC_STATE;
to_read = aux->bytes_in;
to_read = xstate->bytes_in;
// bytebuffer_max = 0x8000;
bytebuffer_offset = 4;
bytebuffer = xmalloc(bytebuffer_max);
n = inflate_unzip_internal(PASS_STATE in, out);
n = inflate_unzip_internal(PASS_STATE xstate);
free(bytebuffer);
aux->crc32 = gunzip_crc;
aux->bytes_out = gunzip_bytes_out;
xstate->crc32 = gunzip_crc;
xstate->bytes_out = gunzip_bytes_out;
DEALLOC_STATE;
return n;
}
@@ -1107,7 +1106,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
return res;
}
static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
{
union {
unsigned char raw[8];
@@ -1169,8 +1168,7 @@ static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
}
}
if (aux)
aux->mtime = SWAP_LE32(header.formatted.mtime);
xstate->mtime = SWAP_LE32(header.formatted.mtime);
/* Read the header checksum */
if (header.formatted.flags & 0x02) {
@@ -1182,27 +1180,27 @@ static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
}
IF_DESKTOP(long long) int FAST_FUNC
unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
unpack_gz_stream(transformer_state_t *xstate)
{
uint32_t v32;
IF_DESKTOP(long long) int total, n;
DECLARE_STATE;
#if !ENABLE_FEATURE_SEAMLESS_Z
if (check_signature16(aux, src_fd, GZIP_MAGIC))
if (check_signature16(xstate, GZIP_MAGIC))
return -1;
#else
if (aux && aux->check_signature) {
if (xstate->check_signature) {
uint16_t magic2;
if (full_read(src_fd, &magic2, 2) != 2) {
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
bad_magic:
bb_error_msg("invalid magic");
return -1;
}
if (magic2 == COMPRESS_MAGIC) {
aux->check_signature = 0;
return unpack_Z_stream(aux, src_fd, dst_fd);
xstate->check_signature = 0;
return unpack_Z_stream(xstate);
}
if (magic2 != GZIP_MAGIC)
goto bad_magic;
@@ -1215,16 +1213,16 @@ unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
to_read = -1;
// bytebuffer_max = 0x8000;
bytebuffer = xmalloc(bytebuffer_max);
gunzip_src_fd = src_fd;
gunzip_src_fd = xstate->src_fd;
again:
if (!check_header_gzip(PASS_STATE aux)) {
if (!check_header_gzip(PASS_STATE xstate)) {
bb_error_msg("corrupted data");
total = -1;
goto ret;
}
n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);
n = inflate_unzip_internal(PASS_STATE xstate);
if (n < 0) {
total = -1;
goto ret;
+6 -6
View File
@@ -73,7 +73,7 @@
*/
IF_DESKTOP(long long) int FAST_FUNC
unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
unpack_Z_stream(transformer_state_t *xstate)
{
IF_DESKTOP(long long total_written = 0;)
IF_DESKTOP(long long) int retval = -1;
@@ -102,7 +102,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
/* block compress mode -C compatible with 2.0 */
int block_mode; /* = BLOCK_MODE; */
if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
if (check_signature16(xstate, COMPRESS_MAGIC))
return -1;
inbuf = xzalloc(IBUFSIZ + 64);
@@ -114,7 +114,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
/* xread isn't good here, we have to return - caller may want
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
if (full_read(src_fd, inbuf, 1) != 1) {
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
bb_error_msg("short read");
goto err;
}
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
}
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
if (rsize < 0)
bb_error_msg_and_die(bb_msg_read_error);
insize += rsize;
@@ -274,7 +274,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
}
if (outpos >= OBUFSIZ) {
xwrite(dst_fd, outbuf, outpos);
xtransformer_write(xstate, outbuf, outpos);
IF_DESKTOP(total_written += outpos;)
outpos = 0;
}
@@ -301,7 +301,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
} while (rsize > 0);
if (outpos > 0) {
xwrite(dst_fd, outbuf, outpos);
xtransformer_write(xstate, outbuf, outpos);
IF_DESKTOP(total_written += outpos;)
}
+22 -13
View File
@@ -206,7 +206,7 @@ enum {
IF_DESKTOP(long long) int FAST_FUNC
unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
unpack_lzma_stream(transformer_state_t *xstate)
{
IF_DESKTOP(long long total_written = 0;)
lzma_header_t header;
@@ -214,8 +214,6 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
uint32_t pos_state_mask;
uint32_t literal_pos_mask;
uint16_t *p;
int num_bits;
int num_probs;
rc_t *rc;
int i;
uint8_t *buffer;
@@ -225,7 +223,7 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
int state = 0;
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|| header.pos >= (9 * 5 * 5)
) {
bb_error_msg("bad lzma header");
@@ -239,6 +237,9 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
pos_state_mask = (1 << pb) - 1;
literal_pos_mask = (1 << lp) - 1;
/* Example values from linux-3.3.4.tar.lzma:
* dict_size: 64M, dst_size: 2^64-1
*/
header.dict_size = SWAP_LE32(header.dict_size);
header.dst_size = SWAP_LE64(header.dst_size);
@@ -247,13 +248,17 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
p = xmalloc(num_probs * sizeof(*p));
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
for (i = 0; i < num_probs; i++)
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
{
int num_probs;
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
p = xmalloc(num_probs * sizeof(*p));
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
for (i = 0; i < num_probs; i++)
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
}
rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */
while (global_pos + buffer_pos < header.dst_size) {
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
@@ -301,7 +306,7 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
goto bad;
IF_DESKTOP(total_written += header.dict_size;)
}
@@ -310,6 +315,7 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
goto one_byte2;
#endif
} else {
int num_bits;
int offset;
uint16_t *prob2;
#define prob_len prob2
@@ -434,19 +440,22 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
goto bad;
IF_DESKTOP(total_written += header.dict_size;)
}
len--;
} while (len != 0 && buffer_pos < header.dst_size);
/* FIXME: ...........^^^^^
* shouldn't it be "global_pos + buffer_pos < header.dst_size"?
*/
}
}
{
IF_NOT_DESKTOP(int total_written = 0; /* success */)
IF_DESKTOP(total_written += buffer_pos;)
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
bad:
total_written = -1; /* failure */
}
+4 -4
View File
@@ -38,7 +38,7 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
#include "unxz/xz_dec_stream.c"
IF_DESKTOP(long long) int FAST_FUNC
unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
unpack_xz_stream(transformer_state_t *xstate)
{
enum xz_ret xz_result;
struct xz_buf iobuf;
@@ -55,7 +55,7 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
iobuf.out = membuf + BUFSIZ;
iobuf.out_size = BUFSIZ;
if (!aux || aux->check_signature == 0) {
if (!xstate || xstate->check_signature == 0) {
/* Preload XZ file signature */
strcpy((char*)membuf, HEADER_MAGIC);
iobuf.in_size = HEADER_MAGIC_SIZE;
@@ -67,7 +67,7 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
xz_result = X_OK;
while (1) {
if (iobuf.in_pos == iobuf.in_size) {
int rd = safe_read(src_fd, membuf, BUFSIZ);
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
if (rd < 0) {
bb_error_msg(bb_msg_read_error);
total = -1;
@@ -104,7 +104,7 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
if (iobuf.out_pos) {
xwrite(dst_fd, iobuf.out, iobuf.out_pos);
xtransformer_write(xstate, iobuf.out, iobuf.out_pos);
IF_DESKTOP(total += iobuf.out_pos;)
iobuf.out_pos = 0;
}
+4 -2
View File
@@ -115,7 +115,9 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
*/
p += len;
sz -= len;
if ((int)sz < 0
if (
/** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
(int)(sz|len) < 0 /* this works */
|| len == 0
|| errno != EINVAL
|| *end != ' '
@@ -241,7 +243,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* or not first block (false positive, it's not .gz/.bz2!) */
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
goto err;
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
err:
bb_error_msg_and_die("invalid tar magic");
archive_handle->offset = 0;
+1 -1
View File
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+1 -1
View File
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+1 -1
View File
@@ -14,7 +14,7 @@ char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+2
View File
@@ -76,11 +76,13 @@
# define TEST_IP (ip < ip_end)
# define NEED_IP(x) \
if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun
# define TEST_IV(x) if ((x) > (unsigned)0 - (511)) goto input_overrun
# undef TEST_OP /* don't need both of the tests here */
# define TEST_OP 1
# define NEED_OP(x) \
if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun
# define TEST_OV(x) if ((x) > (unsigned)0 - (511)) goto output_overrun
#define HAVE_ANY_OP 1
+3
View File
@@ -92,6 +92,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
ip++;
NEED_IP(1);
}
TEST_IV(t);
t += 15 + *ip++;
}
/* copy literals */
@@ -224,6 +225,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
ip++;
NEED_IP(1);
}
TEST_IV(t);
t += 31 + *ip++;
}
#if defined(COPY_DICT)
@@ -265,6 +267,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
ip++;
NEED_IP(1);
}
TEST_IV(t);
t += 7 + *ip++;
}
#if defined(COPY_DICT)
+177 -52
View File
@@ -6,19 +6,19 @@
#include "libbb.h"
#include "bb_archive.h"
void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
{
memset(aux, 0, sizeof(*aux));
memset(xstate, 0, sizeof(*xstate));
}
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
{
if (aux && aux->check_signature) {
if (xstate->check_signature) {
uint16_t magic2;
if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
bb_error_msg("invalid magic");
#if 0 /* possible future extension */
if (aux->check_signature > 1)
if (xstate->check_signature > 1)
xfunc_die();
#endif
return -1;
@@ -27,6 +27,47 @@ int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigne
return 0;
}
ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
{
ssize_t nwrote;
if (xstate->mem_output_size_max != 0) {
size_t pos = xstate->mem_output_size;
size_t size;
size = (xstate->mem_output_size += bufsize);
if (size > xstate->mem_output_size_max) {
free(xstate->mem_output_buf);
xstate->mem_output_buf = NULL;
bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max);
nwrote = -1;
goto ret;
}
xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1);
memcpy(xstate->mem_output_buf + pos, buf, bufsize);
xstate->mem_output_buf[size] = '\0';
nwrote = bufsize;
} else {
nwrote = full_write(xstate->dst_fd, buf, bufsize);
if (nwrote != (ssize_t)bufsize) {
bb_perror_msg("write");
nwrote = -1;
goto ret;
}
}
ret:
return nwrote;
}
ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
{
ssize_t nwrote = transformer_write(xstate, buf, bufsize);
if (nwrote != (ssize_t)bufsize) {
xfunc_die();
}
return nwrote;
}
void check_errors_in_children(int signo)
{
int status;
@@ -60,12 +101,12 @@ void check_errors_in_children(int signo)
/* transformer(), more than meets the eye */
#if BB_MMU
void FAST_FUNC open_transformer(int fd,
void FAST_FUNC fork_transformer(int fd,
int check_signature,
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
)
#else
void FAST_FUNC open_transformer(int fd, const char *transform_prog)
void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
#endif
{
struct fd_pair fd_pipe;
@@ -80,10 +121,12 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
#if BB_MMU
{
IF_DESKTOP(long long) int r;
transformer_aux_data_t aux;
init_transformer_aux_data(&aux);
aux.check_signature = check_signature;
r = transformer(&aux, fd, fd_pipe.wr);
transformer_state_t xstate;
init_transformer_state(&xstate);
xstate.check_signature = check_signature;
xstate.src_fd = fd;
xstate.dst_fd = fd_pipe.wr;
r = transformer(&xstate);
if (ENABLE_FEATURE_CLEAN_UP) {
close(fd_pipe.wr); /* send EOF */
close(fd);
@@ -118,16 +161,19 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
/* Used by e.g. rpm which gives us a fd without filename,
* thus we can't guess the format from filename's extension.
*/
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
{
union {
uint8_t b[4];
uint16_t b16[2];
uint32_t b32[1];
} magic;
int offset = -2;
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
USE_FOR_NOMMU(const char *xformer_prog;)
int offset;
transformer_state_t *xstate;
offset = -2;
xstate = xzalloc(sizeof(*xstate));
xstate->src_fd = fd;
/* .gz and .bz2 both have 2-byte signature, and their
* unpack_XXX_stream wants this header skipped. */
@@ -135,15 +181,15 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
if (ENABLE_FEATURE_SEAMLESS_GZ
&& magic.b16[0] == GZIP_MAGIC
) {
USE_FOR_MMU(xformer = unpack_gz_stream;)
USE_FOR_NOMMU(xformer_prog = "gunzip";)
xstate->xformer = unpack_gz_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
goto found_magic;
}
if (ENABLE_FEATURE_SEAMLESS_BZ2
&& magic.b16[0] == BZIP2_MAGIC
) {
USE_FOR_MMU(xformer = unpack_bz2_stream;)
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
xstate->xformer = unpack_bz2_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
goto found_magic;
}
if (ENABLE_FEATURE_SEAMLESS_XZ
@@ -152,69 +198,146 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
offset = -6;
xread(fd, magic.b32, sizeof(magic.b32[0]));
if (magic.b32[0] == XZ_MAGIC2) {
USE_FOR_MMU(xformer = unpack_xz_stream;)
USE_FOR_NOMMU(xformer_prog = "unxz";)
xstate->xformer = unpack_xz_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
goto found_magic;
}
}
/* No known magic seen */
if (fail_if_not_detected)
if (fail_if_not_compressed)
bb_error_msg_and_die("no gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
IF_FEATURE_SEAMLESS_XZ("/xz")
" magic");
xlseek(fd, offset, SEEK_CUR);
return 1;
found_magic:
# if BB_MMU
open_transformer_with_no_sig(fd, xformer);
# else
/* NOMMU version of open_transformer execs
/* Some callers expect this function to "consume" fd
* even if data is not compressed. In this case,
* we return a state with trivial transformer.
*/
// USE_FOR_MMU(xstate->xformer = copy_stream;)
// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
/* fall through to seeking bck over bytes we read earlier */
USE_FOR_NOMMU(found_magic:)
/* NOMMU version of fork_transformer execs
* an external unzipper that wants
* file position at the start of the file */
* file position at the start of the file.
*/
xlseek(fd, offset, SEEK_CUR);
open_transformer_with_sig(fd, xformer, xformer_prog);
USE_FOR_MMU(found_magic:)
/* In MMU case, if magic was found, seeking back is not necessary */
return xstate;
}
/* Used by e.g. rpm which gives us a fd without filename,
* thus we can't guess the format from filename's extension.
*/
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
{
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
if (!xstate || !xstate->xformer) {
free(xstate);
return 1;
}
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
free(xstate);
return 0;
}
int FAST_FUNC open_zipped(const char *fname)
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
{
char *sfx;
transformer_state_t *xstate;
int fd;
fd = open(fname, O_RDONLY);
if (fd < 0)
return fd;
return NULL;
sfx = strrchr(fname, '.');
if (sfx) {
sfx++;
if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0)
/* .lzma has no header/signature, just trust it */
open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
else
if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
|| (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
|| (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
) {
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
/* .lzma has no header/signature, can only detect it by extension */
char *sfx = strrchr(fname, '.');
if (sfx && strcmp(sfx+1, "lzma") == 0) {
xstate = xzalloc(sizeof(*xstate));
xstate->src_fd = fd;
xstate->xformer = unpack_lzma_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
return xstate;
}
}
xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
return xstate;
}
int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
{
int fd;
transformer_state_t *xstate;
xstate = open_transformer(fname, fail_if_not_compressed);
if (!xstate)
return -1;
fd = xstate->src_fd;
if (xstate->xformer) {
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
}
/* else: the file is not compressed */
free(xstate);
return fd;
}
#endif /* SEAMLESS_COMPRESSION */
void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
{
# if 1
transformer_state_t *xstate;
char *image;
xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
if (!xstate) /* file open error */
return NULL;
image = NULL;
if (xstate->xformer) {
/* In-memory decompression */
xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095);
xstate->xformer(xstate);
if (xstate->mem_output_buf) {
image = xstate->mem_output_buf;
if (maxsz_p)
*maxsz_p = xstate->mem_output_size;
}
} else {
/* File is not compressed */
image = xmalloc_read(xstate->src_fd, maxsz_p);
}
if (!image)
bb_perror_msg("read error from '%s'", fname);
close(xstate->src_fd);
free(xstate);
return image;
# else
/* This version forks a subprocess - much more expensive */
int fd;
char *image;
fd = open_zipped(fname);
fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
if (fd < 0)
return NULL;
@@ -222,6 +345,8 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
if (!image)
bb_perror_msg("read error from '%s'", fname);
close(fd);
return image;
# endif
}
#endif /* SEAMLESS_COMPRESSION */
+1 -1
View File
@@ -1099,7 +1099,7 @@ static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_e
return xasprintf("%s.lzo", filename);
}
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate UNUSED_PARAM)
{
if (option_mask32 & OPT_DECOMPRESS)
return do_lzo_decompress();
+1 -1
View File
@@ -122,7 +122,7 @@ static void extract_cpio(int fd, const char *source_rpm)
archive_handle->src_fd = fd;
/*archive_handle->offset = 0; - init_handle() did it */
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
}
+1 -1
View File
@@ -80,7 +80,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
// signal(SIGCHLD, check_errors_in_children);
/* This works, but doesn't report uncompress errors (they happen in child) */
setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
bb_error_msg_and_die("error unpacking");
+33 -45
View File
@@ -160,13 +160,6 @@
#define block_buf bb_common_bufsiz1
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
/* Do not pass gzip flag to writeTarFile() */
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
#endif
#if ENABLE_FEATURE_TAR_CREATE
/*
@@ -621,21 +614,12 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
return TRUE;
}
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
# endif
#if SEAMLESS_COMPRESSION
/* Don't inline: vfork scares gcc and pessimizes code */
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
{
pid_t gzipPid;
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
# elif ENABLE_FEATURE_SEAMLESS_GZ
const char *zip_exec = "gzip";
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
const char *zip_exec = "bzip2";
# endif
// On Linux, vfork never unpauses parent early, although standard
// allows for that. Do we want to waste bytes checking for it?
# define WAIT_FOR_CHILD 0
@@ -649,11 +633,6 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
# if defined(__GNUC__) && __GNUC__
/* Avoid vfork clobbering */
(void) &zip_exec;
# endif
gzipPid = xvfork();
if (gzipPid == 0) {
@@ -669,7 +648,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
xmove_fd(gzipDataPipe.rd, 0);
xmove_fd(tar_fd, 1);
/* exec gzip/bzip2 program/applet */
BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0);
BB_EXECLP(gzip, gzip, "-f", (char *)0);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
}
@@ -692,16 +671,21 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
# endif
if (vfork_exec_errno) {
errno = vfork_exec_errno;
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
bb_perror_msg_and_die("can't execute '%s'", gzip);
}
}
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
#endif /* SEAMLESS_COMPRESSION */
#if !SEAMLESS_COMPRESSION
/* Do not pass gzip flag to writeTarFile() */
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
#endif
/* gcc 4.2.1 inlines it, making code bigger */
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
int recurseFlags, const llist_t *include,
const llist_t *exclude, int gzip)
const llist_t *exclude, const char *gzip)
{
int errorFlag = FALSE;
struct TarBallInfo tbInfo;
@@ -714,7 +698,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
* can avoid including the tarball into itself.... */
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
#if SEAMLESS_COMPRESSION
if (gzip)
vfork_compressor(tbInfo.tarFd, gzip);
#endif
@@ -749,7 +733,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
if (errorFlag)
bb_error_msg("error exit delayed from previous errors");
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
#if SEAMLESS_COMPRESSION
if (gzip) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
@@ -761,11 +745,9 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
#endif
return errorFlag;
}
#else
int writeTarFile(int tar_fd, int verboseFlag,
int recurseFlags, const llist_t *include,
const llist_t *exclude, int gzip);
#endif /* FEATURE_TAR_CREATE */
#else /* !FEATURE_TAR_CREATE */
# define writeTarFile(...) 0
#endif
#if ENABLE_FEATURE_TAR_FROM
static llist_t *append_file_list_to_list(llist_t *list)
@@ -1137,7 +1119,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
&& flags == O_RDONLY
&& !(opt & OPT_ANY_COMPRESS)
) {
tar_handle->src_fd = open_zipped(tar_filename);
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
if (tar_handle->src_fd < 0)
bb_perror_msg_and_die("can't open '%s'", tar_filename);
} else {
@@ -1149,18 +1131,24 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (base_dir)
xchdir(base_dir);
//if (SEAMLESS_COMPRESSION || OPT_COMPRESS)
//if (SEAMLESS_COMPRESSION)
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
// signal(SIGCHLD, check_errors_in_children);
/* Create an archive */
if (opt & OPT_CREATE) {
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
int zipMode = 0;
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
zipMode = 1;
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
zipMode = 2;
#if SEAMLESS_COMPRESSION
const char *zipMode = NULL;
if (opt & OPT_COMPRESS)
zipMode = "compress";
if (opt & OPT_GZIP)
zipMode = "gzip";
if (opt & OPT_BZIP2)
zipMode = "bzip2";
if (opt & OPT_LZMA)
zipMode = "lzma";
if (opt & OPT_XZ)
zipMode = "xz";
#endif
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag,
@@ -1171,7 +1159,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
}
if (opt & OPT_ANY_COMPRESS) {
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
USE_FOR_NOMMU(const char *xformer_prog;)
if (opt & OPT_COMPRESS)
@@ -1190,7 +1178,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
USE_FOR_MMU(xformer = unpack_xz_stream;)
USE_FOR_NOMMU(xformer_prog = "unxz";)
open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
/* Can't lseek over pipes */
tar_handle->seek = seek_by_read;
/*tar_handle->offset = 0; - already is */
+8 -6
View File
@@ -280,17 +280,19 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
bb_copyfd_exact_size(zip_fd, dst_fd, size);
} else {
/* Method 8 - inflate */
transformer_aux_data_t aux;
init_transformer_aux_data(&aux);
aux.bytes_in = zip_header->formatted.cmpsize;
if (inflate_unzip(&aux, zip_fd, dst_fd) < 0)
transformer_state_t xstate;
init_transformer_state(&xstate);
xstate.bytes_in = zip_header->formatted.cmpsize;
xstate.src_fd = zip_fd;
xstate.dst_fd = dst_fd;
if (inflate_unzip(&xstate) < 0)
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
bb_error_msg_and_die("crc error");
}
/* Validate decompression - size */
if (zip_header->formatted.ucmpsize != aux.bytes_out) {
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_error_msg("bad length");
+2 -2
View File
@@ -10,9 +10,9 @@
*/
//usage:#define setlogcons_trivial_usage
//usage: "N"
//usage: "[N]"
//usage:#define setlogcons_full_usage "\n\n"
//usage: "Redirect the kernel output to console N (0 for current)"
//usage: "Redirect the kernel output to console N. Default:0 (current console)"
#include "libbb.h"
+12 -1
View File
@@ -633,12 +633,13 @@ config FEATURE_FANCY_TAIL
default y
depends on TAIL
help
The options (-q, -s, and -v) are provided by GNU tail, but
The options (-q, -s, -v and -F) are provided by GNU tail, but
are not specific in the SUSv3 standard.
-q Never output headers giving file names
-s SEC Wait SEC seconds between reads with -f
-v Always output headers giving file names
-F Same as -f, but keep retrying
config TEE
bool "tee"
@@ -738,6 +739,16 @@ config YES
yes is used to repeatedly output a specific string, or
the default string `y'.
comment "Common options"
config FEATURE_VERBOSE
bool "Support verbose options (usually -v) for various applets"
default y
help
Enable cp -v, rm -v and similar messages.
Also enables long option (--verbose) if it exists.
Without this option, -v is accepted but ignored.
comment "Common options for cp and mv"
depends on CP || MV
+10 -8
View File
@@ -20,20 +20,22 @@
#include "libbb.h"
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
struct BUG_const_mismatch {
char BUG_const_mismatch[
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
? 1 : -1
];
};
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int catv_main(int argc UNUSED_PARAM, char **argv)
{
int retval = EXIT_SUCCESS;
int fd;
unsigned opts;
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
typedef char BUG_const_mismatch[
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
? 1 : -1
];
opts = getopt32(argv, "etv");
argv += optind;
#if 0 /* These consts match, we can just pass "opts" to visible() */
+1 -1
View File
@@ -16,10 +16,10 @@
//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
//usage: "\n -R Recurse"
//usage: "\n -h Affect symlinks instead of symlink targets"
//usage: IF_DESKTOP(
//usage: "\n -L Traverse all symlinks to directories"
//usage: "\n -H Traverse symlinks on command line only"
//usage: "\n -P Don't traverse symlinks (default)"
//usage: IF_DESKTOP(
//usage: "\n -c List changed files"
//usage: "\n -v List all files"
//usage: "\n -f Hide errors"
-1
View File
@@ -79,7 +79,6 @@ int cp_main(int argc, char **argv)
"parents\0" No_argument "\xff"
;
#endif
// -v (--verbose) is ignored
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
+28 -8
View File
@@ -25,6 +25,7 @@
//usage:#define df_trivial_usage
//usage: "[-Pk"
//usage: IF_FEATURE_HUMAN_READABLE("mh")
//usage: "T"
//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE")
//usage: "] [FILESYSTEM]..."
//usage:#define df_full_usage "\n\n"
@@ -35,6 +36,7 @@
//usage: "\n -m 1M-byte blocks"
//usage: "\n -h Human readable (e.g. 1K 243M 2G)"
//usage: )
//usage: "\n -T Print filesystem type"
//usage: IF_FEATURE_DF_FANCY(
//usage: "\n -a Show all filesystems"
//usage: "\n -i Inodes"
@@ -83,11 +85,12 @@ int df_main(int argc UNUSED_PARAM, char **argv)
enum {
OPT_KILO = (1 << 0),
OPT_POSIX = (1 << 1),
OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY,
OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_FSTYPE = (1 << 2),
OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
};
const char *disp_units_hdr = NULL;
char *chp;
@@ -99,7 +102,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
#elif ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "k-m:m-k";
#endif
opt = getopt32(argv, "kP"
opt = getopt32(argv, "kPT"
IF_FEATURE_DF_FANCY("aiB:")
IF_FEATURE_HUMAN_READABLE("hm")
IF_FEATURE_DF_FANCY(, &chp));
@@ -134,8 +137,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
#endif
}
printf("Filesystem %-15sUsed Available %s Mounted on\n",
disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%");
printf("Filesystem %s%-15sUsed Available %s Mounted on\n",
(opt & OPT_FSTYPE) ? "Type " : "",
disp_units_hdr,
(opt & OPT_POSIX) ? "Capacity" : "Use%");
mount_table = NULL;
argv += optind;
@@ -148,6 +154,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
while (1) {
const char *device;
const char *mount_point;
const char *fs_type;
if (mount_table) {
mount_entry = getmntent(mount_table);
@@ -170,6 +177,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
device = mount_entry->mnt_fsname;
mount_point = mount_entry->mnt_dir;
fs_type = mount_entry->mnt_type;
if (statfs(mount_point, &s) != 0) {
bb_simple_perror_msg(mount_point);
@@ -218,10 +226,22 @@ int df_main(int argc UNUSED_PARAM, char **argv)
printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
}
free(uni_dev);
if (opt & OPT_FSTYPE) {
char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type);
if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX))
printf(" %s\n%31s", uni_type, "");
else
printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, "");
free(uni_type);
}
}
#else
if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
printf("\n%-20s", "");
if (opt & OPT_FSTYPE) {
if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX))
printf("\n%-30s", "");
}
#endif
#if ENABLE_FEATURE_HUMAN_READABLE
+33 -18
View File
@@ -8,7 +8,7 @@
/* -v, -b, -c are ignored */
//usage:#define install_trivial_usage
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST"
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST"
//usage:#define install_full_usage "\n\n"
//usage: "Copy files and set attributes\n"
//usage: "\n -c Just copy (default)"
@@ -19,6 +19,7 @@
//usage: "\n -o USER Set ownership"
//usage: "\n -g GRP Set group ownership"
//usage: "\n -m MODE Set permissions"
//usage: "\n -t DIR Install to DIR"
//usage: IF_SELINUX(
//usage: "\n -Z Set security context"
//usage: )
@@ -28,12 +29,16 @@
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
static const char install_longopts[] ALIGN1 =
IF_FEATURE_VERBOSE(
"verbose\0" No_argument "v"
)
"directory\0" No_argument "d"
"preserve-timestamps\0" No_argument "p"
"strip\0" No_argument "s"
"group\0" Required_argument "g"
"mode\0" Required_argument "m"
"owner\0" Required_argument "o"
"target-directory\0" Required_argument "t"
/* autofs build insists of using -b --suffix=.orig */
/* TODO? (short option for --suffix is -S) */
#if ENABLE_SELINUX
@@ -89,11 +94,11 @@ int install_main(int argc, char **argv)
const char *gid_str;
const char *uid_str;
const char *mode_str;
int mkdir_flags = FILEUTILS_RECUR;
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
int opts;
int min_args = 1;
int ret = EXIT_SUCCESS;
int isdir = 0;
int isdir;
#if ENABLE_SELINUX
security_context_t scontext;
bool use_default_selinux_context = 1;
@@ -109,21 +114,22 @@ int install_main(int argc, char **argv)
OPT_GROUP = 1 << 7,
OPT_MODE = 1 << 8,
OPT_OWNER = 1 << 9,
OPT_TARGET = 1 << 10,
#if ENABLE_SELINUX
OPT_SET_SECURITY_CONTEXT = 1 << 10,
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
OPT_SET_SECURITY_CONTEXT = 1 << 11,
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
#endif
};
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
applet_long_options = install_longopts;
#endif
opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
/* -c exists for backwards compatibility, it's needed */
/* -v is ignored ("print name of each created directory") */
/* -b is ignored ("make a backup of each existing destination file") */
opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
&gid_str, &mode_str, &uid_str, &last
IF_SELINUX(, &scontext));
argc -= optind;
argv += optind;
@@ -141,6 +147,11 @@ int install_main(int argc, char **argv)
}
#endif
if ((opts & OPT_v) && FILEUTILS_VERBOSE) {
mkdir_flags |= FILEUTILS_VERBOSE;
copy_flags |= FILEUTILS_VERBOSE;
}
/* preserve access and modification time, this is GNU behaviour,
* BSD only preserves modification time */
if (opts & OPT_PRESERVE_TIME) {
@@ -152,33 +163,37 @@ int install_main(int argc, char **argv)
uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
last = argv[argc - 1];
if (!(opts & OPT_DIRECTORY)) {
argv[argc - 1] = NULL;
min_args++;
/* If -t DIR is in use, then isdir=true, last="DIR" */
isdir = (opts & OPT_TARGET);
if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) {
/* Neither -t DIR nor -d is in use */
argc--;
last = argv[argc];
argv[argc] = NULL;
/* coreutils install resolves link in this case, don't use lstat */
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
}
if (argc < min_args)
if (argc < 1)
bb_show_usage();
while ((arg = *argv++) != NULL) {
char *dest = last;
char *dest;
if (opts & OPT_DIRECTORY) {
dest = arg;
/* GNU coreutils 6.9 does not set uid:gid
* on intermediate created directories
* (only on last one) */
if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
if (bb_make_directory(dest, 0755, mkdir_flags)) {
ret = EXIT_FAILURE;
goto next;
}
} else {
dest = last;
if (opts & OPT_MKDIR_LEADING) {
char *ddir = xstrdup(dest);
bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
/* errors are not checked. copy_file
* will fail if dir is not created. */
free(ddir);
+1 -1
View File
@@ -1032,7 +1032,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
}
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
#if ENABLE_DESKTOP
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG)
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS))
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
#endif
if (nfiles > 0) {
+6 -2
View File
@@ -48,7 +48,9 @@ static const char mkdir_longopts[] ALIGN1 =
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
#if ENABLE_FEATURE_VERBOSE
"verbose\0" No_argument "v"
#endif
;
#endif
@@ -67,7 +69,7 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
applet_long_options = mkdir_longopts;
#endif
opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));
opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
if (opt & 1) {
mode_t mmode = 0777;
if (!bb_parse_mode(smode, &mmode)) {
@@ -77,8 +79,10 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
}
if (opt & 2)
flags |= FILEUTILS_RECUR;
if ((opt & 4) && FILEUTILS_VERBOSE)
flags |= FILEUTILS_VERBOSE;
#if ENABLE_SELINUX
if (opt & 4) {
if (opt & 8) {
selinux_or_die();
setfscreatecon_or_die(scontext);
}
+7 -1
View File
@@ -33,13 +33,17 @@ static const char mv_longopts[] ALIGN1 =
"interactive\0" No_argument "i"
"force\0" No_argument "f"
"no-clobber\0" No_argument "n"
IF_FEATURE_VERBOSE(
"verbose\0" No_argument "v"
)
;
#endif
#define OPT_FORCE (1 << 0)
#define OPT_INTERACTIVE (1 << 1)
#define OPT_NOCLOBBER (1 << 2)
#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mv_main(int argc, char **argv)
@@ -58,7 +62,6 @@ int mv_main(int argc, char **argv)
/* Need at least two arguments.
* If more than one of -f, -i, -n is specified , only the final one
* takes effect (it unsets previous options).
* -v is accepted but ignored.
*/
opt_complementary = "-2:f-in:i-fn:n-fi";
flags = getopt32(argv, "finv");
@@ -148,6 +151,9 @@ int mv_main(int argc, char **argv)
status = 1;
}
RET_0:
if (flags & OPT_VERBOSE) {
printf("'%s' -> '%s'\n", *argv, dest);
}
if (dest != last) {
free((void *) dest);
}
+2 -1
View File
@@ -38,7 +38,6 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
unsigned opt;
opt_complementary = "f-i:i-f";
/* -v (verbose) is ignored */
opt = getopt32(argv, "fiRrv");
argv += optind;
if (opt & 1)
@@ -47,6 +46,8 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
flags |= FILEUTILS_INTERACTIVE;
if (opt & (8|4))
flags |= FILEUTILS_RECUR;
if ((opt & 16) && FILEUTILS_VERBOSE)
flags |= FILEUTILS_VERBOSE;
if (*argv != NULL) {
do {
+8 -2
View File
@@ -31,7 +31,7 @@
#define PARENTS (1 << 0)
//efine VERBOSE (1 << 1) //accepted but ignored
#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
#define IGNORE_NON_EMPTY (1 << 2)
int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -44,10 +44,12 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
static const char rmdir_longopts[] ALIGN1 =
"parents\0" No_argument "p"
"verbose\0" No_argument "v"
/* Debian etch: many packages fail to be purged or installed
* because they desperately want this option: */
"ignore-fail-on-non-empty\0" No_argument "\xff"
IF_FEATURE_VERBOSE(
"verbose\0" No_argument "v"
)
;
applet_long_options = rmdir_longopts;
#endif
@@ -62,6 +64,10 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
path = *argv;
while (1) {
if (flags & VERBOSE) {
printf("rmdir: removing directory, '%s'\n", path);
}
if (rmdir(path) < 0) {
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
+153
View File
@@ -0,0 +1,153 @@
/* vi: set sw=4 ts=4: */
/*
* shuf: Write a random permutation of the input lines to standard output.
*
* Copyright (C) 2014 by Bartosz Golaszewski <bartekgola@gmail.com>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SHUF
//config: bool "shuf"
//config: default y
//config: help
//config: Generate random permutations
//kbuild:lib-$(CONFIG_SHUF) += shuf.o
//applet:IF_SHUF(APPLET_NOEXEC(shuf, shuf, BB_DIR_USR_BIN, BB_SUID_DROP, shuf))
//usage:#define shuf_trivial_usage
//usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]"
//usage:#define shuf_full_usage "\n\n"
//usage: "Randomly permute lines\n"
//usage: "\n -e Treat ARGs as lines"
//usage: "\n -i L-H Treat numbers L-H as lines"
//usage: "\n -n NUM Output at most NUM lines"
//usage: "\n -o FILE Write to FILE, not standard output"
//usage: "\n -z End lines with zero byte, not newline"
#include "libbb.h"
/* This is a NOEXEC applet. Be very careful! */
#define OPT_e (1 << 0)
#define OPT_i (1 << 1)
#define OPT_n (1 << 2)
#define OPT_o (1 << 3)
#define OPT_z (1 << 4)
#define OPT_STR "ei:n:o:z"
/*
* Use the Fisher-Yates shuffle algorithm on an array of lines.
*/
static void shuffle_lines(char **lines, unsigned numlines)
{
unsigned i;
unsigned r;
char *tmp;
srand(monotonic_us());
for (i = numlines-1; i > 0; i--) {
r = rand();
/* RAND_MAX can be as small as 32767 */
if (i > RAND_MAX)
r ^= rand() << 15;
r %= i;
tmp = lines[i];
lines[i] = lines[r];
lines[r] = tmp;
}
}
int shuf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int shuf_main(int argc, char **argv)
{
unsigned opts;
char *opt_i_str, *opt_n_str, *opt_o_str;
unsigned i;
char **lines;
unsigned numlines;
char eol;
opt_complementary = "e--i:i--e"; /* mutually exclusive */
opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str);
argc -= optind;
argv += optind;
/* Prepare lines for shuffling - either: */
if (opts & OPT_e) {
/* make lines from command-line arguments */
numlines = argc;
lines = argv;
} else
if (opts & OPT_i) {
/* create a range of numbers */
char *dash;
unsigned lo, hi;
dash = strchr(opt_i_str, '-');
if (!dash) {
bb_error_msg_and_die("bad range '%s'", opt_i_str);
}
*dash = '\0';
lo = xatou(opt_i_str);
hi = xatou(dash + 1);
*dash = '-';
if (hi < lo) {
bb_error_msg_and_die("bad range '%s'", opt_i_str);
}
numlines = (hi+1) - lo;
lines = xmalloc(numlines * sizeof(lines[0]));
for (i = 0; i < numlines; i++) {
lines[i] = (char*)(uintptr_t)lo;
lo++;
}
} else {
/* default - read lines from stdin or the input file */
FILE *fp;
if (argc > 1)
bb_show_usage();
fp = xfopen_stdin(argv[0] ? argv[0] : "-");
lines = NULL;
numlines = 0;
for (;;) {
char *line = xmalloc_fgetline(fp);
if (!line)
break;
lines = xrealloc_vector(lines, 6, numlines);
lines[numlines++] = line;
}
fclose_if_not_stdin(fp);
}
if (numlines != 0)
shuffle_lines(lines, numlines);
if (opts & OPT_o)
xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
if (opts & OPT_n) {
unsigned maxlines;
maxlines = xatou(opt_n_str);
if (numlines > maxlines)
numlines = maxlines;
}
eol = '\n';
if (opts & OPT_z)
eol = '\0';
for (i = 0; i < numlines; i++) {
if (opts & OPT_i)
printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
else
printf("%s%c", lines[i], eol);
}
fflush_stdout_and_exit(EXIT_SUCCESS);
}
+7 -3
View File
@@ -225,7 +225,7 @@ static int compare_keys(const void *xarg, const void *yarg)
y = *(char **)yarg;
#endif
/* Perform actual comparison */
switch (flags & 7) {
switch (flags & (FLAG_n | FLAG_M | FLAG_g)) {
default:
bb_error_msg_and_die("unknown sort type");
break;
@@ -302,10 +302,14 @@ static int compare_keys(const void *xarg, const void *yarg)
} /* for */
/* Perform fallback sort if necessary */
if (!retval && !(option_mask32 & FLAG_s))
if (!retval && !(option_mask32 & FLAG_s)) {
retval = strcmp(*(char **)xarg, *(char **)yarg);
flags = option_mask32;
}
if (flags & FLAG_r)
return -retval;
if (flags & FLAG_r) return -retval;
return retval;
}
+3 -2
View File
@@ -655,7 +655,7 @@ static bool do_stat(const char *filename, const char *format)
);
# if ENABLE_SELINUX
if (option_mask32 & OPT_SELINUX)
printf(" %lc\n", *scontext);
printf(" %s\n", scontext);
else
bb_putchar('\n');
# endif
@@ -700,7 +700,8 @@ static bool do_stat(const char *filename, const char *format)
(unsigned long) statbuf.st_gid,
(gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
# if ENABLE_SELINUX
printf(" S_Context: %lc\n", *scontext);
if (option_mask32 & OPT_SELINUX)
printf(" S_Context: %s\n", scontext);
# endif
printf("Access: %s\n", human_time(statbuf.st_atime));
printf("Modify: %s\n", human_time(statbuf.st_mtime));
+3 -4
View File
@@ -32,15 +32,14 @@
//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n"
//usage: "With more than one FILE, precede each with a filename header.\n"
//usage: "\n -f Print data as file grows"
//usage: IF_FEATURE_FANCY_TAIL(
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
//usage: )
//usage: "\n -c [+]N[kbm] Print last N bytes"
//usage: "\n -n N[kbm] Print last N lines"
//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
//usage: IF_FEATURE_FANCY_TAIL(
//usage: "\n -c [+]N[kbm] Print last N bytes"
//usage: "\n -q Never print headers"
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
//usage: "\n -v Always print headers"
//usage: "\n -F Same as -f, but keep retrying"
//usage: "\n"
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
//usage: )
+35 -34
View File
@@ -826,7 +826,6 @@ int test_main(int argc, char **argv)
{
int res;
const char *arg0;
// bool negate = 0;
arg0 = bb_basename(argv[0]);
if (arg0[0] == '[') {
@@ -844,6 +843,7 @@ int test_main(int argc, char **argv)
}
argv[argc] = NULL;
}
/* argc is unused after this point */
/* We must do DEINIT_S() prior to returning */
INIT_S();
@@ -862,43 +862,45 @@ int test_main(int argc, char **argv)
*/
/*ngroups = 0; - done by INIT_S() */
//argc--;
argv++;
args = argv;
/* Implement special cases from POSIX.2, section 4.62.4 */
if (!argv[0]) { /* "test" */
res = 1;
goto ret;
}
#if 0
// Now it's fixed in the parser and should not be needed
if (LONE_CHAR(argv[0], '!') && argv[1]) {
negate = 1;
//argc--;
argv++;
}
if (!argv[1]) { /* "test [!] arg" */
res = (*argv[0] == '\0');
goto ret;
}
if (argv[2] && !argv[3]) {
check_operator(argv[1]);
if (last_operator->op_type == BINOP) {
/* "test [!] arg1 <binary_op> arg2" */
args = argv;
res = (binop() == 0);
goto ret;
/* Implement special cases from POSIX.2, section 4.62.4.
* Testcase: "test '(' = '('"
* The general parser would misinterpret '(' as group start.
*/
if (1) {
int negate = 0;
again:
if (!argv[0]) {
/* "test" */
res = 1;
goto ret_special;
}
if (!argv[1]) {
/* "test [!] arg" */
res = (argv[0][0] == '\0');
goto ret_special;
}
if (argv[2] && !argv[3]) {
check_operator(argv[1]);
if (last_operator->op_type == BINOP) {
/* "test [!] arg1 <binary_op> arg2" */
args = argv;
res = (binop() == 0);
ret_special:
/* If there was leading "!" op... */
res ^= negate;
goto ret;
}
}
if (LONE_CHAR(argv[0], '!')) {
argv++;
negate ^= 1;
goto again;
}
}
/* Some complex expression. Undo '!' removal */
if (negate) {
negate = 0;
//argc++;
argv--;
}
#endif
args = argv;
res = !oexpr(check_operator(*args));
if (*args != NULL && *++args != NULL) {
@@ -911,6 +913,5 @@ int test_main(int argc, char **argv)
}
ret:
DEINIT_S();
// return negate ? !res : res;
return res;
}
+6 -4
View File
@@ -49,16 +49,18 @@
*/
//usage:#define uname_trivial_usage
//usage: "[-amnrspv]"
//usage: "[-amnrspvio]"
//usage:#define uname_full_usage "\n\n"
//usage: "Print system information\n"
//usage: "\n -a Print all"
//usage: "\n -m The machine (hardware) type"
//usage: "\n -n Hostname"
//usage: "\n -r OS release"
//usage: "\n -s OS name (default)"
//usage: "\n -r Kernel release"
//usage: "\n -s Kernel name (default)"
//usage: "\n -p Processor type"
//usage: "\n -v OS version"
//usage: "\n -v Kernel version"
//usage: "\n -i The hardware platform"
//usage: "\n -o OS name"
//usage:
//usage:#define uname_example_usage
//usage: "$ uname -a\n"
+34
View File
@@ -0,0 +1,34 @@
/* vi: set sw=4 ts=4: */
/* unlink for busybox
*
* Copyright (C) 2014 Isaac Dunham <ibid.ag@gmail.com>
*
* Licensed under GPLv2, see LICENSE in this source tree
*/
//config:config UNLINK
//config: bool "unlink"
//config: default y
//config: help
//config: unlink deletes a file by calling unlink()
//kbuild:lib-$(CONFIG_UNLINK) += unlink.o
//applet:IF_UNLINK(APPLET(unlink, BB_DIR_USR_BIN, BB_SUID_DROP))
//usage:#define unlink_trivial_usage
//usage: "FILE"
//usage:#define unlink_full_usage "\n\n"
//usage: "Delete FILE by calling unlink()"
#include "libbb.h"
int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlink_main(int argc UNUSED_PARAM, char **argv)
{
opt_complementary = "=1"; /* must have exactly 1 param */
getopt32(argv, "");
argv += optind;
xunlink(argv[0]);
return 0;
}
+24 -61
View File
@@ -1,13 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Which implementation for busybox
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
* Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*
* Based on which from debianutils
*/
//usage:#define which_trivial_usage
@@ -24,76 +20,43 @@
int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int which_main(int argc UNUSED_PARAM, char **argv)
{
IF_DESKTOP(int opt;)
int status = EXIT_SUCCESS;
char *path;
char *p;
const char *env_path;
int status = 0;
env_path = getenv("PATH");
if (!env_path)
env_path = bb_default_root_path;
opt_complementary = "-1"; /* at least one argument */
IF_DESKTOP(opt =) getopt32(argv, "a");
getopt32(argv, "a");
argv += optind;
/* This matches what is seen on e.g. ubuntu.
* "which" there is a shell script. */
path = getenv("PATH");
if (!path) {
path = (char*)bb_PATH_root_path;
putenv(path);
path += 5; /* skip "PATH=" */
}
do {
#if ENABLE_DESKTOP
/* Much bloat just to support -a */
if (strchr(*argv, '/')) {
if (execable_file(*argv)) {
puts(*argv);
continue;
}
status = EXIT_FAILURE;
} else {
char *path2 = xstrdup(path);
char *tmp = path2;
int missing = 1;
p = find_execable(*argv, &tmp);
if (!p)
status = EXIT_FAILURE;
else {
print:
puts(p);
free(p);
if (opt) {
/* -a: show matches in all PATH components */
if (tmp) {
p = find_execable(*argv, &tmp);
if (p)
goto print;
}
}
}
free(path2);
}
#else
/* Just ignoring -a */
/* If file contains a slash don't use PATH */
if (strchr(*argv, '/')) {
if (execable_file(*argv)) {
if (file_is_executable(*argv)) {
missing = 0;
puts(*argv);
continue;
}
} else {
char *path2 = xstrdup(path);
char *tmp = path2;
p = find_execable(*argv, &tmp);
free(path2);
if (p) {
char *path;
char *tmp;
char *p;
path = tmp = xstrdup(env_path);
while ((p = find_executable(*argv, &tmp)) != NULL) {
missing = 0;
puts(p);
free(p);
continue;
if (!option_mask32) /* -a not set */
break;
}
free(path);
}
status = EXIT_FAILURE;
#endif
} while (*(++argv) != NULL);
status |= missing;
} while (*++argv);
fflush_stdout_and_exit(status);
return status;
}
+1 -1
View File
@@ -21,7 +21,7 @@ static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
int i ;
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
if (exists_execable(ext_dhcp_clients[i].name))
if (executable_exists(ext_dhcp_clients[i].name))
return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
}
bb_error_msg("no dhcp clients found, using static interface shutdown");
+9 -1
View File
@@ -103,7 +103,15 @@ smaller code. In order to assign it, use SET_PTR_TO_GLOBALS macro:
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
Typically it is done in <applet>_main().
Typically it is done in <applet>_main(). Another variation is
to use stack:
int <applet>_main(...)
{
#undef G
struct globals G;
memset(&G, 0, sizeof(G));
SET_PTR_TO_GLOBALS(&G);
Now you can reference "globals" by G.a, G.buf and so on, in any function.
+2
View File
@@ -45,6 +45,8 @@ udhcpc - auto-backgrounds unless -f after lease is obtained,
udhcpd - auto-backgrounds and do not log to stderr unless -f,
otherwise logs to stderr, but option -S makes it log *also* to syslog
zcip - auto-backgrounds and logs *also* to syslog unless -f
behaviour can be overridden with experimental LOGGING env.var
(can be set to either "none" or "syslog")
Total: 13 applets (+1 obsolete),
4 log to syslog by default (crond fakeidentd inetd zcip),
+64 -40
View File
@@ -6,7 +6,7 @@ This document details the steps you must take to add a new applet to BusyBox.
Credits:
Matt Kraai - initial writeup
Mark Whitley - the remix
Thomas Lundquist - Trying to keep it updated.
Thomas Lundquist - trying to keep it updated
When doing this you should consider using the latest git HEAD.
This is a good thing if you plan to getting it committed into mainline.
@@ -16,14 +16,14 @@ Initial Write
First, write your applet. Be sure to include copyright information at the top,
such as who you stole the code from and so forth. Also include the mini-GPL
boilerplate. Be sure to name the main function <applet>_main instead of main.
And be sure to put it in <applet>.c. Usage does not have to be taken care of by
your applet.
Make sure to #include "libbb.h" as the first include file in your applet.
boilerplate and Config.in/Kbuild/usage/applet.h snippets (more on that below
in this document). Be sure to name the main function <applet>_main instead
of main. And be sure to put it in <applet>.c. Make sure to #include "libbb.h"
as the first include file in your applet.
For a new applet mu, here is the code that would go in mu.c:
(busybox.h already includes most usual header files. You do not need
(libbb.h already includes most usual header files. You do not need
#include <stdio.h> etc...)
@@ -41,6 +41,22 @@ For a new applet mu, here is the code that would go in mu.c:
#include "libbb.h"
#include "other.h"
//config:config MU
//config: bool "MU"
//config: default y
//config: help
//config: Returns an indeterminate value.
//kbuild:lib-$(CONFIG_MU) += mu.o
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
//usage:#define mu_trivial_usage
//usage: "[-abcde] FILE..."
//usage:#define mu_full_usage
//usage: "Returns an indeterminate value\n"
//usage: "\n -a First function"
//usage: "\n -b Second function"
int mu_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mu_main(int argc, char **argv)
{
@@ -90,6 +106,8 @@ Make a new file named <function_name>.c
#include "libbb.h"
#include "other.h"
//kbuild:lib-y += function.o
int function(char *a)
{
return *a;
@@ -97,9 +115,7 @@ int function(char *a)
----end example code------
Add <function_name>.o in the right alphabetically sorted place
in libbb/Kbuild.src. You should look at the conditional part of
libbb/Kbuild.src as well.
Remember about the kbuild snippet.
You should also try to find a suitable place in include/libbb.h for
the function declaration. If not, add it somewhere anyway, with or without
@@ -109,60 +125,68 @@ You can look at libbb/Config.src and try to find out if the function is
tunable and add it there if it is.
Kbuild/Config.in/usage/applets.h snippets in .c files
-----------------------------------------------------
The old way of adding new applets was to put all the information needed by the
configuration and build system into appropriate files (namely: Kbuild.src and
Config.src in new applet's directory) and to add the applet declaration and
usage info text to include/applets.src.h and include/usage.src.h respectively.
Since the scripts/gen_build_files.sh script had been introduced, the preferred
way is to have all these declarations contained within the applet .c files.
Every line intended to be processed by gen_build_files.sh should start as a
comment without any preceding whitespaces and be followed by an appropriate
keyword - kbuild, config, usage or applet - and a colon, just like shown in the
first example above.
Placement / Directory
---------------------
Find the appropriate directory for your new applet.
Make sure you find the appropriate places in the files, the applets are
sorted alphabetically.
Add the kbuild snippet to the .c file:
Add the applet to Kbuild.src in the chosen directory:
//kbuild:lib-$(CONFIG_MU) += mu.o
lib-$(CONFIG_MU) += mu.o
Add the config snippet to the .c file:
Add the applet to Config.src in the chosen directory:
config MU
bool "MU"
default n
help
Returns an indeterminate value.
//config:config MU
//config: bool "MU"
//config: default y
//config: help
//config: Returns an indeterminate value.
Usage String(s)
---------------
Next, add usage information for you applet to include/usage.src.h.
Next, add usage information for your applet to the .c file.
This should look like the following:
#define mu_trivial_usage \
"-[abcde] FILES"
#define mu_full_usage \
"Returns an indeterminate value.\n\n" \
"Options:\n" \
"\t-a\t\tfirst function\n" \
"\t-b\t\tsecond function\n" \
...
//usage:#define mu_trivial_usage
//usage: "[-abcde] FILE..."
//usage:#define mu_full_usage
//usage: "Returns an indeterminate value\n"
//usage: "\n -a First function"
//usage: "\n -b Second function"
//usage: ...
If your program supports flags, the flags should be mentioned on the first
line (-[abcde]) and a detailed description of each flag should go in the
mu_full_usage section, one flag per line. (Numerous examples of this
currently exist in usage.src.h.)
line ([-abcde]) and a detailed description of each flag should go in the
mu_full_usage section, one flag per line.
Header Files
------------
Next, add an entry to include/applets.src.h. Be *sure* to keep the list
in alphabetical order, or else it will break the binary-search lookup
algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
Finally add the applet declaration snippet. Be sure to read the top of
applets.src.h before adding your applet - it contains important info
on applet macros and conventions.
Be sure to read the top of applets.src.h before adding your applet.
/* all programs above here are alphabetically "less than" 'mu' */
IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
/* all programs below here are alphabetically "greater than" 'mu' */
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
The Grand Announcement
+50
View File
@@ -0,0 +1,50 @@
Busybox unit test framework
===========================
This document describes what you need to do to write test cases using the
Busybox unit test framework.
Building unit tests
-------------------
The framework and all tests are built as a regular Busybox applet if option
CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set.
Writing test cases
------------------
Unit testing interface can be found in include/bbunit.h.
Tests can be placed in any .c file in Busybox tree - preferably right next to
the functions they test. Test cases should be enclosed within an #if, and
should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within
the test curly brackets. If an assertion fails the test ends immediately, ie.
the following assertions will not be reached. Any code placed after
BBUNIT_ENDTEST is executed regardless of the test result. Here's an example:
#if ENABLE_UNIT_TEST
BBUNIT_DEFINE_TEST(test_name)
{
int *i;
i = malloc(sizeof(int));
BBUNIT_ASSERT_NOTNULL(i);
*i = 2;
BBUNIT_ASSERT_EQ((*i)*(*i), 4);
BBUNIT_ENDTEST;
free(i);
}
#endif /* ENABLE_UNIT_TEST */
Running the unit test suite
---------------------------
To run the tests you can either directly run 'busybox unit' or use 'make test'
to run both the unit tests (if compiled) and regular test suite.
+2
View File
@@ -1540,12 +1540,14 @@ static void chain_group(void)
debug_printf_parse("%s: OC_BREAK\n", __func__);
n = chain_node(OC_EXEC);
n->a.n = break_ptr;
chain_expr(t_info);
break;
case OC_CONTINUE:
debug_printf_parse("%s: OC_CONTINUE\n", __func__);
n = chain_node(OC_EXEC);
n->a.n = continue_ptr;
chain_expr(t_info);
break;
/* delete, next, nextfile, return, exit */
+10 -3
View File
@@ -395,7 +395,9 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
/* process the flags */
sed_cmd->which_match = 1;
dbg("s flags:'%s'", substr + idx + 1);
while (substr[++idx]) {
dbg("s flag:'%c'", substr[idx]);
/* Parse match number */
if (isdigit(substr[idx])) {
if (match[0] != '^') {
@@ -403,7 +405,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
const char *pos = substr + idx;
/* FIXME: error check? */
sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10);
idx = pos - substr;
idx = pos - substr - 1;
}
continue;
}
@@ -443,6 +445,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
case '}':
goto out;
default:
dbg("s bad flags:'%s'", substr + idx);
bb_error_msg_and_die("bad option in substitution expression");
}
}
@@ -1519,12 +1522,16 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
/* -i: process each FILE separately: */
if (stat(*argv, &statbuf) != 0) {
bb_simple_perror_msg(*argv);
G.exitcode = EXIT_FAILURE;
G.current_input_file++;
continue;
}
G.outname = xasprintf("%sXXXXXX", *argv);
nonstdoutfd = xmkstemp(G.outname);
G.nonstdout = xfdopen_for_write(nonstdoutfd);
/* Set permissions/owner of output file */
stat(*argv, &statbuf);
/* chmod'ing AFTER chown would preserve suid/sgid bits,
* but GNU sed 4.2.1 does not preserve them either */
fchmod(nonstdoutfd, statbuf.st_mode);
+645 -237
View File
File diff suppressed because it is too large. Load diff
+11 -7
View File
@@ -22,10 +22,14 @@ then
done
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
for i in $dns
do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
# Only replace resolv.conf is we have at least one DNS server
if [ -n "$dns" ]
then
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
for i in $dns
do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
fi
+11 -7
View File
@@ -22,10 +22,14 @@ then
done
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
for i in $dns
do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
# Only replace resolv.conf is we have at least one DNS server
if [ -n "$dns" ]
then
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
for i in $dns
do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
fi
+11 -2
View File
@@ -9,6 +9,15 @@ env - PATH=... <other vars=...> runsvdir /var/service &
from one of system startup scripts. (Google "man runsvdir" and "man runsv"
for more info about these tools).
You can try or debug an individual service by running its SERVICE_DIR/run script.
In this case, its stdout and stderr go to your terminal.
You can also run "runsv SERVICE_DIR", which runs both the service
and its logger service (SERVICE_DIR/log/run) if logger service exists.
If logger service exists, the output will go to it instead of the terminal.
"runsvdir DIR" merely runs "runsv SERVICE_DIR" for every subdirectory in DIR.
Some existing examples:
var_service/dhcp_if -
@@ -47,8 +56,8 @@ This even works while fw service runs: if dhcp signals fw to (re)start
while fw runs, fw will not stop after its execution, but will re-execute once,
picking up dhcp's new configuration.
This is achieved very simply by having
# Make ourself one-shot
sv o .
# Make ourself one-shot
sv o .
at the very beginning of fw/run script, not at the end.
Therefore, any "sv u /var/run/service/fw" command by any other
script "undoes" o(ne-shot) command if fw still runs, thus
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+5
View File
@@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.
+169 -51
View File
@@ -137,6 +137,16 @@
//config: Support the 'find -exec' option for executing commands based upon
//config: the files matched.
//config:
//config:config FEATURE_FIND_EXEC_PLUS
//config: bool "Enable -exec ... {} +"
//config: default y
//config: depends on FEATURE_FIND_EXEC
//config: help
//config: Support the 'find -exec ... {} +' option for executing commands
//config: for all matched files at once.
//config: Without this option, -exec + is a synonym for -exec ;
//config: (IOW: it works correctly, but without expected speedup)
//config:
//config:config FEATURE_FIND_USER
//config: bool "Enable -user: username/uid matching"
//config: default y
@@ -319,6 +329,9 @@
//usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by"
//usage: "\n file name. Fails if CMD exits with nonzero"
//usage: )
//usage: IF_FEATURE_FIND_EXEC_PLUS(
//usage: "\n -exec CMD ARG + Run CMD with {} replaced by list of file names"
//usage: )
//usage: IF_FEATURE_FIND_DELETE(
//usage: "\n -delete Delete current file/directory. Turns on -depth option"
//usage: )
@@ -337,8 +350,12 @@
# define FNM_CASEFOLD 0
#endif
#define dbg(...) ((void)0)
/* #define dbg(...) bb_error_msg(__VA_ARGS__) */
#if 1
# define dbg(...) ((void)0)
#else
# define dbg(...) bb_error_msg(__VA_ARGS__)
#endif
/* This is a NOEXEC applet. Be very careful! */
@@ -375,7 +392,20 @@ IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;))
IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
IF_FEATURE_FIND_PRUNE( ACTS(prune))
IF_FEATURE_FIND_DELETE( ACTS(delete))
IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
IF_FEATURE_FIND_EXEC( ACTS(exec,
char **exec_argv; /* -exec ARGS */
unsigned *subst_count;
int exec_argc; /* count of ARGS */
IF_FEATURE_FIND_EXEC_PLUS(
/*
* filelist is NULL if "exec ;"
* non-NULL if "exec +"
*/
char **filelist;
int filelist_idx;
int file_len;
)
))
IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;))
@@ -389,6 +419,7 @@ struct globals {
smallint need_print;
smallint xdev_on;
recurse_flags_t recurse_flags;
IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;)
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { \
@@ -398,40 +429,11 @@ struct globals {
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
IF_FEATURE_FIND_MAXDEPTH(G.minmaxdepth[1] = INT_MAX;) \
IF_FEATURE_FIND_EXEC_PLUS(G.max_argv_len = bb_arg_max() - 2048;) \
G.need_print = 1; \
G.recurse_flags = ACTION_RECURSE; \
} while (0)
#if ENABLE_FEATURE_FIND_EXEC
static unsigned count_subst(const char *str)
{
unsigned count = 0;
while ((str = strstr(str, "{}")) != NULL) {
count++;
str++;
}
return count;
}
static char* subst(const char *src, unsigned count, const char* filename)
{
char *buf, *dst, *end;
size_t flen = strlen(filename);
/* we replace each '{}' with filename: growth by strlen-2 */
buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
while ((end = strstr(src, "{}"))) {
memcpy(dst, src, end - src);
dst += end - src;
src = end + 2;
memcpy(dst, filename, flen);
dst += flen;
}
strcpy(dst, src);
return buf;
}
#endif
/* Return values of ACTFs ('action functions') are a bit mask:
* bit 1=1: prune (use SKIP constant for setting it)
* bit 0=1: matched successfully (TRUE)
@@ -482,7 +484,6 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat
return rc ^ TRUE; /* restore TRUE bit */
}
#if !FNM_CASEFOLD
static char *strcpy_upcase(char *dst, const char *src)
{
@@ -557,8 +558,8 @@ ACTF(type)
#if ENABLE_FEATURE_FIND_PERM
ACTF(perm)
{
/* -perm +mode: at least one of perm_mask bits are set */
if (ap->perm_char == '+')
/* -perm [+/]mode: at least one of perm_mask bits are set */
if (ap->perm_char == '+' || ap->perm_char == '/')
return (statbuf->st_mode & ap->perm_mask) != 0;
/* -perm -mode: all of perm_mask are set */
if (ap->perm_char == '-')
@@ -606,17 +607,57 @@ ACTF(inum)
}
#endif
#if ENABLE_FEATURE_FIND_EXEC
ACTF(exec)
static int do_exec(action_exec *ap, const char *fileName)
{
int i, rc;
#if ENABLE_USE_PORTABLE_CODE
char **argv = alloca(sizeof(char*) * (ap->exec_argc + 1));
#else /* gcc 4.3.1 generates smaller code: */
char *argv[ap->exec_argc + 1];
#endif
for (i = 0; i < ap->exec_argc; i++)
argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName);
argv[i] = NULL; /* terminate the list */
# if ENABLE_FEATURE_FIND_EXEC_PLUS
int size = ap->exec_argc + ap->filelist_idx + 1;
# else
int size = ap->exec_argc + 1;
# endif
# if ENABLE_USE_PORTABLE_CODE
char **argv = alloca(sizeof(char*) * size);
# else /* gcc 4.3.1 generates smaller code: */
char *argv[size];
# endif
char **pp = argv;
for (i = 0; i < ap->exec_argc; i++) {
const char *arg = ap->exec_argv[i];
# if ENABLE_FEATURE_FIND_EXEC_PLUS
if (ap->filelist) {
/* Handling "-exec +"
* Only one exec_argv[i] has substitution in it.
* Expand that one exec_argv[i] into file list.
*/
if (ap->subst_count[i] == 0) {
*pp++ = xstrdup(arg);
} else {
int j = 0;
while (ap->filelist[j]) {
/* 2nd arg here should be ap->subst_count[i], but it is always 1: */
*pp++ = xmalloc_substitute_string(arg, 1, "{}", ap->filelist[j]);
free(ap->filelist[j]);
j++;
}
}
} else
# endif
{
/* Handling "-exec ;" */
*pp++ = xmalloc_substitute_string(arg, ap->subst_count[i], "{}", fileName);
}
}
*pp = NULL; /* terminate the list */
# if ENABLE_FEATURE_FIND_EXEC_PLUS
if (ap->filelist) {
ap->filelist[0] = NULL;
ap->filelist_idx = 0;
ap->file_len = 0;
}
# endif
rc = spawn_and_wait(argv);
if (rc < 0)
@@ -627,6 +668,48 @@ ACTF(exec)
free(argv[i++]);
return rc == 0; /* return 1 if exitcode 0 */
}
ACTF(exec)
{
# if ENABLE_FEATURE_FIND_EXEC_PLUS
if (ap->filelist) {
int rc;
ap->filelist = xrealloc_vector(ap->filelist, 8, ap->filelist_idx);
ap->filelist[ap->filelist_idx++] = xstrdup(fileName);
ap->file_len += strlen(fileName) + sizeof(char*) + 1;
/* If we have lots of files already, exec the command */
rc = 1;
if (ap->file_len >= G.max_argv_len)
rc = do_exec(ap, NULL);
return rc;
}
# endif
return do_exec(ap, fileName);
}
# if ENABLE_FEATURE_FIND_EXEC_PLUS
static int flush_exec_plus(void)
{
action *ap;
action **app;
action ***appp = G.actions;
while ((app = *appp++) != NULL) {
while ((ap = *app++) != NULL) {
if (ap->f == (action_fp)func_exec) {
action_exec *ae = (void*)ap;
if (ae->filelist_idx != 0) {
int rc = do_exec(ae, NULL);
# if ENABLE_FEATURE_FIND_NOT
if (ap->invert) rc = !rc;
# endif
if (rc == 0)
return 1;
}
}
}
}
return 0;
}
# endif
#endif
#if ENABLE_FEATURE_FIND_USER
ACTF(user)
@@ -1067,6 +1150,7 @@ static action*** parse_params(char **argv)
else if (parm == PARM_exec) {
int i;
action_exec *ap;
IF_FEATURE_FIND_EXEC_PLUS(int all_subst = 0;)
dbg("%d", __LINE__);
G.need_print = 0;
ap = ALLOC_ACTION(exec);
@@ -1079,10 +1163,13 @@ static action*** parse_params(char **argv)
// executes "echo Foo >FILENAME<",
// find -exec echo Foo ">{}<" "+"
// executes "echo Foo FILENAME1 FILENAME2 FILENAME3...".
// TODO (so far we treat "+" just like ";")
if ((argv[0][0] == ';' || argv[0][0] == '+')
&& argv[0][1] == '\0'
) {
# if ENABLE_FEATURE_FIND_EXEC_PLUS
if (argv[0][0] == '+')
ap->filelist = xzalloc(sizeof(ap->filelist[0]));
# endif
break;
}
argv++;
@@ -1092,8 +1179,17 @@ static action*** parse_params(char **argv)
bb_error_msg_and_die(bb_msg_requires_arg, arg);
ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
i = ap->exec_argc;
while (i--)
ap->subst_count[i] = count_subst(ap->exec_argv[i]);
while (i--) {
ap->subst_count[i] = count_strstr(ap->exec_argv[i], "{}");
IF_FEATURE_FIND_EXEC_PLUS(all_subst += ap->subst_count[i];)
}
# if ENABLE_FEATURE_FIND_EXEC_PLUS
/*
* coreutils expects {} to appear only once in "-exec +"
*/
if (all_subst != 1 && ap->filelist)
bb_error_msg_and_die("only one '{}' allowed for -exec +");
# endif
}
#endif
#if ENABLE_FEATURE_FIND_PAREN
@@ -1156,14 +1252,14 @@ static action*** parse_params(char **argv)
/* -perm BITS File's mode bits are exactly BITS (octal or symbolic).
* Symbolic modes use mode 0 as a point of departure.
* -perm -BITS All of the BITS are set in file's mode.
* -perm +BITS At least one of the BITS is set in file's mode.
* -perm [+/]BITS At least one of the BITS is set in file's mode.
*/
else if (parm == PARM_perm) {
action_perm *ap;
dbg("%d", __LINE__);
ap = ALLOC_ACTION(perm);
ap->perm_char = arg1[0];
arg1 = plus_minus_num(arg1);
arg1 = (arg1[0] == '/' ? arg1+1 : plus_minus_num(arg1));
/*ap->perm_mask = 0; - ALLOC_ACTION did it */
if (!bb_parse_mode(arg1, &ap->perm_mask))
bb_error_msg_and_die("invalid mode '%s'", arg1);
@@ -1291,9 +1387,27 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int find_main(int argc UNUSED_PARAM, char **argv)
{
int i, firstopt, status = EXIT_SUCCESS;
char **past_HLP, *saved;
INIT_G();
/* "find -type f" + getopt("+HLP") => disaster.
* Need to avoid getopt running into a non-HLP option.
* Do this by temporarily storing NULL there:
*/
past_HLP = argv;
for (;;) {
saved = *++past_HLP;
if (!saved)
break;
if (saved[0] != '-')
break;
if (!saved[1])
break; /* it is "-" */
if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
break;
}
*past_HLP = NULL;
/* "+": stop on first non-option */
i = getopt32(argv, "+HLP");
if (i & (1<<0))
@@ -1301,7 +1415,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
if (i & (1<<1))
G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
/* -P is default and is ignored */
argv += optind;
argv = past_HLP; /* same result as "argv += optind;" */
*past_HLP = saved;
for (firstopt = 0; argv[firstopt]; firstopt++) {
if (argv[firstopt][0] == '-')
@@ -1346,8 +1461,11 @@ int find_main(int argc UNUSED_PARAM, char **argv)
0) /* depth */
) {
status = EXIT_FAILURE;
goto out;
}
}
IF_FEATURE_FIND_EXEC_PLUS(status = flush_exec_plus();)
out:
return status;
}
+34 -7
View File
@@ -373,6 +373,11 @@ static int grep_file(FILE *file)
opt_f_not_found: ;
}
} else {
#if ENABLE_EXTRA_COMPAT
unsigned start_pos;
#else
int match_flg;
#endif
char *match_at;
if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
@@ -389,15 +394,19 @@ static int grep_file(FILE *file)
#if !ENABLE_EXTRA_COMPAT
gl->matched_range.rm_so = 0;
gl->matched_range.rm_eo = 0;
match_flg = 0;
#else
start_pos = 0;
#endif
match_at = line;
opt_w_again:
//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
if (
#if !ENABLE_EXTRA_COMPAT
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, match_flg) == 0
#else
re_search(&gl->compiled_regex, match_at, line_len,
/*start:*/ 0, /*range:*/ line_len,
start_pos, /*range:*/ line_len,
&gl->matched_range) >= 0
#endif
) {
@@ -409,16 +418,34 @@ static int grep_file(FILE *file)
found = 1;
} else {
char c = ' ';
if (gl->matched_range.rm_so)
if (match_at > line || gl->matched_range.rm_so != 0) {
c = match_at[gl->matched_range.rm_so - 1];
}
if (!isalnum(c) && c != '_') {
c = match_at[gl->matched_range.rm_eo];
if (!c || (!isalnum(c) && c != '_')) {
found = 1;
} else {
}
if (!isalnum(c) && c != '_') {
found = 1;
} else {
/*
* Why check gl->matched_range.rm_eo?
* Zero-length match makes -w skip the line:
* "echo foo | grep ^" prints "foo",
* "echo foo | grep -w ^" prints nothing.
* Without such check, we can loop forever.
*/
#if !ENABLE_EXTRA_COMPAT
if (gl->matched_range.rm_eo != 0) {
match_at += gl->matched_range.rm_eo;
match_flg |= REG_NOTBOL;
goto opt_w_again;
}
#else
if (gl->matched_range.rm_eo > start_pos) {
start_pos = gl->matched_range.rm_eo;
goto opt_w_again;
}
#endif
}
}
}
@@ -641,7 +668,7 @@ static int grep_dir(const char *dir)
int matched = 0;
recursive_action(dir,
/* recurse=yes */ ACTION_RECURSE |
/* followLinks=no */
/* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
/* depthFirst=yes */ ACTION_DEPTHFIRST,
/* fileAction= */ file_action_grep,
/* dirAction= */ NULL,
+137 -42
View File
@@ -53,6 +53,13 @@
//config: Support -0: input items are terminated by a NUL character
//config: instead of whitespace, and the quotes and backslash
//config: are not special.
//config:
//config:config FEATURE_XARGS_SUPPORT_REPL_STR
//config: bool "Enable -I STR: string to replace"
//config: default y
//config: depends on XARGS
//config: help
//config: Support -I STR and -i[STR] options.
//applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs))
@@ -85,19 +92,22 @@
struct globals {
char **args;
#if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
char **argv;
const char *repl_str;
char eol_ch;
#endif
const char *eof_str;
int idx;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { \
G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \
} while (0)
/*
* This function has special algorithm.
* Don't use fork and include to main!
*/
static int xargs_exec(void)
{
int status;
@@ -301,7 +311,7 @@ static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
c = '\0';
}
*p++ = c;
if (c == '\0') { /* word's delimiter or EOF detected */
if (c == '\0') { /* NUL or EOF detected */
/* A full word is loaded */
store_param(s);
dbg_msg("args[]:'%s'", s);
@@ -323,10 +333,71 @@ static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
}
#endif /* FEATURE_XARGS_SUPPORT_ZERO_TERM */
#if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
/*
* Used if -I<repl> was specified.
* In this mode, words aren't appended to PROG ARGS.
* Instead, entire input line is read, then <repl> string
* in every PROG and ARG is replaced with the line:
* echo -e "ho ho\nhi" | xargs -I_ cmd __ _
* results in "cmd 'ho hoho ho' 'ho ho'"; "cmd 'hihi' 'hi'".
* -n MAX_ARGS seems to be ignored.
* Tested with GNU findutils 4.5.10.
*/
//FIXME: n_max_chars is not handled the same way as in GNU findutils.
//FIXME: quoting is not implemented.
static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg UNUSED_PARAM, char *buf)
{
int i;
char *end, *p;
/* Free strings from last invocation, if any */
for (i = 0; G.args && G.args[i]; i++)
if (G.args[i] != G.argv[i])
free(G.args[i]);
end = buf + n_max_chars;
p = buf;
while (1) {
int c = getchar();
if (c == EOF || c == G.eol_ch) {
if (p == buf)
goto ret; /* empty line */
c = '\0';
}
*p++ = c;
if (c == '\0') { /* EOL or EOF detected */
i = 0;
while (G.argv[i]) {
char *arg = G.argv[i];
int count = count_strstr(arg, G.repl_str);
if (count != 0)
arg = xmalloc_substitute_string(arg, count, G.repl_str, buf);
store_param(arg);
dbg_msg("args[]:'%s'", arg);
i++;
}
p = buf;
goto ret;
}
if (p == end) {
goto ret;
}
}
ret:
*p = '\0';
/* store_param(NULL) - caller will do it */
dbg_msg("return:'%s'", buf);
return buf;
}
#endif
#if ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION
/* Prompt the user for a response, and
if the user responds affirmatively, return true;
otherwise, return false. Uses "/dev/tty", not stdin. */
* if user responds affirmatively, return true;
* otherwise, return false. Uses "/dev/tty", not stdin.
*/
static int xargs_ask_confirmation(void)
{
FILE *tty_stream;
@@ -360,6 +431,9 @@ static int xargs_ask_confirmation(void)
//usage: "\n -e[STR] STR stops input processing"
//usage: "\n -n N Pass no more than N args to PROG"
//usage: "\n -s N Pass command line of no more than N bytes"
//usage: IF_FEATURE_XARGS_SUPPORT_REPL_STR(
//usage: "\n -I STR Replace STR within PROG ARGS with input line"
//usage: )
//usage: IF_FEATURE_XARGS_SUPPORT_TERMOPT(
//usage: "\n -x Exit if size is exceeded"
//usage: )
@@ -378,6 +452,8 @@ enum {
IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,)
IF_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,)
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,)
IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR ,)
IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR1 ,)
OPT_VERBOSE = 1 << OPTBIT_VERBOSE ,
OPT_NO_EMPTY = 1 << OPTBIT_NO_EMPTY ,
@@ -388,11 +464,14 @@ enum {
OPT_INTERACTIVE = IF_FEATURE_XARGS_SUPPORT_CONFIRMATION((1 << OPTBIT_INTERACTIVE)) + 0,
OPT_TERMINATE = IF_FEATURE_XARGS_SUPPORT_TERMOPT( (1 << OPTBIT_TERMINATE )) + 0,
OPT_ZEROTERM = IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1 << OPTBIT_ZEROTERM )) + 0,
OPT_REPLSTR = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR )) + 0,
OPT_REPLSTR1 = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR1 )) + 0,
};
#define OPTION_STR "+trn:s:e::E:" \
IF_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \
IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0")
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \
IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::")
int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int xargs_main(int argc, char **argv)
@@ -405,7 +484,8 @@ int xargs_main(int argc, char **argv)
unsigned opt;
int n_max_chars;
int n_max_arg;
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM \
|| ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
char* FAST_FUNC (*read_args)(int, int, char*) = process_stdin;
#else
#define read_args process_stdin
@@ -419,7 +499,10 @@ int xargs_main(int argc, char **argv)
"no-run-if-empty\0" No_argument "r"
;
#endif
opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &G.eof_str, &G.eof_str);
opt = getopt32(argv, OPTION_STR,
&max_args, &max_chars, &G.eof_str, &G.eof_str
IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str)
);
/* -E ""? You may wonder why not just omit -E?
* This is used for portability:
@@ -427,8 +510,10 @@ int xargs_main(int argc, char **argv)
if ((opt & OPT_EOF_STRING1) && G.eof_str[0] == '\0')
G.eof_str = NULL;
if (opt & OPT_ZEROTERM)
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin);
if (opt & OPT_ZEROTERM) {
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin;)
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\0';)
}
argv += optind;
argc -= optind;
@@ -438,12 +523,7 @@ int xargs_main(int argc, char **argv)
argc++;
}
/* -s NUM default. fileutils-4.4.2 uses 128k, but I heasitate
* to use such a big value - first need to change code to use
* growable buffer instead of fixed one.
*/
n_max_chars = 32 * 1024;
/* Make smaller if system does not allow our default value.
/*
* The Open Group Base Specifications Issue 6:
* "The xargs utility shall limit the command line length such that
* when the command line is invoked, the combined argument
@@ -451,16 +531,15 @@ int xargs_main(int argc, char **argv)
* in the System Interfaces volume of IEEE Std 1003.1-2001)
* shall not exceed {ARG_MAX}-2048 bytes".
*/
{
long arg_max = 0;
#if defined _SC_ARG_MAX
arg_max = sysconf(_SC_ARG_MAX) - 2048;
#elif defined ARG_MAX
arg_max = ARG_MAX - 2048;
#endif
if (arg_max > 0 && n_max_chars > arg_max)
n_max_chars = arg_max;
}
n_max_chars = bb_arg_max();
if (n_max_chars > 32 * 1024)
n_max_chars = 32 * 1024;
/*
* POSIX suggests substracting 2048 bytes from sysconf(_SC_ARG_MAX)
* so that the process may safely modify its environment.
*/
n_max_chars -= 2048;
if (opt & OPT_UPTO_SIZE) {
n_max_chars = xatou_range(max_chars, 1, INT_MAX);
}
@@ -486,20 +565,36 @@ int xargs_main(int argc, char **argv)
/* if (n_max_arg > n_max_chars) n_max_arg = n_max_chars */
}
/* Allocate pointers for execvp */
/* We can statically allocate (argc + n_max_arg + 1) elements
* and do not bother with resizing args[], but on 64-bit machines
* this results in args[] vector which is ~8 times bigger
* than n_max_chars! That is, with n_max_chars == 20k,
* args[] will take 160k (!), which will most likely be
* almost entirely unused.
*/
/* See store_param() for matching 256-step growth logic */
G.args = xmalloc(sizeof(G.args[0]) * ((argc + 0xff) & ~0xff));
/* Store the command to be executed, part 1 */
for (i = 0; argv[i]; i++)
G.args[i] = argv[i];
#if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
if (opt & (OPT_REPLSTR | OPT_REPLSTR1)) {
/*
* -I<str>:
* Unmodified args are kept in G.argv[i],
* G.args[i] receives malloced G.argv[i] with <str> replaced
* with input line. Setting this up:
*/
G.args = NULL;
G.argv = argv;
argc = 0;
read_args = process_stdin_with_replace;
} else
#endif
{
/* Allocate pointers for execvp.
* We can statically allocate (argc + n_max_arg + 1) elements
* and do not bother with resizing args[], but on 64-bit machines
* this results in args[] vector which is ~8 times bigger
* than n_max_chars! That is, with n_max_chars == 20k,
* args[] will take 160k (!), which will most likely be
* almost entirely unused.
*
* See store_param() for matching 256-step growth logic
*/
G.args = xmalloc(sizeof(G.args[0]) * ((argc + 0xff) & ~0xff));
/* Store the command to be executed, part 1 */
for (i = 0; argv[i]; i++)
G.args[i] = argv[i];
}
while (1) {
char *rem;
+25 -27
View File
@@ -8,7 +8,7 @@
/*
name - applet name as it is typed on command line
name2 - applet name, converted to C (ether-wake: name2 = ether_wake)
help - applet name, converted to C (ether-wake: help = ether_wake)
main - corresponding <applet>_main to call (bzcat: main = bunzip2)
l - location to install link to: [/usr]/[s]bin
s - suid type:
@@ -24,46 +24,46 @@ s - suid type:
#if defined(PROTOTYPES)
# define APPLET(name,l,s) int name##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
# define APPLET_ODDNAME(name,main,l,s,name2) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
# define APPLET_NOEXEC(name,main,l,s,name2) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
# define APPLET_NOFORK(name,main,l,s,name2) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
# define APPLET_ODDNAME(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
# define APPLET_NOEXEC(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
# define APPLET_NOFORK(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#elif defined(NAME_MAIN_CNAME)
# define APPLET(name,l,s) name name##_main name
# define APPLET_ODDNAME(name,main,l,s,name2) name main##_main name2
# define APPLET_NOEXEC(name,main,l,s,name2) name main##_main name2
# define APPLET_NOFORK(name,main,l,s,name2) name main##_main name2
#elif defined(NAME_MAIN)
# define APPLET(name,l,s) name name##_main
# define APPLET_ODDNAME(name,main,l,s,help) name main##_main
# define APPLET_NOEXEC(name,main,l,s,help) name main##_main
# define APPLET_NOFORK(name,main,l,s,help) name main##_main
#elif defined(MAKE_USAGE) && ENABLE_FEATURE_VERBOSE_USAGE
# define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage name##_full_usage)
# define APPLET_ODDNAME(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage)
# define APPLET_NOEXEC(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage)
# define APPLET_NOFORK(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage)
# define APPLET_ODDNAME(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
# define APPLET_NOEXEC(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
# define APPLET_NOFORK(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
#elif defined(MAKE_USAGE) && !ENABLE_FEATURE_VERBOSE_USAGE
# define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage)
# define APPLET_ODDNAME(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage)
# define APPLET_NOEXEC(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage)
# define APPLET_NOFORK(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage)
# define APPLET_ODDNAME(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
# define APPLET_NOEXEC(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
# define APPLET_NOFORK(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
#elif defined(MAKE_LINKS)
# define APPLET(name,l,c) LINK l name
# define APPLET_ODDNAME(name,main,l,s,name2) LINK l name
# define APPLET_NOEXEC(name,main,l,s,name2) LINK l name
# define APPLET_NOFORK(name,main,l,s,name2) LINK l name
# define APPLET_ODDNAME(name,main,l,s,help) LINK l name
# define APPLET_NOEXEC(name,main,l,s,help) LINK l name
# define APPLET_NOFORK(name,main,l,s,help) LINK l name
#elif defined(MAKE_SUID)
# define APPLET(name,l,s) SUID s l name
# define APPLET_ODDNAME(name,main,l,s,name2) SUID s l name
# define APPLET_NOEXEC(name,main,l,s,name2) SUID s l name
# define APPLET_NOFORK(name,main,l,s,name2) SUID s l name
# define APPLET_ODDNAME(name,main,l,s,help) SUID s l name
# define APPLET_NOEXEC(name,main,l,s,help) SUID s l name
# define APPLET_NOFORK(name,main,l,s,help) SUID s l name
#else
static struct bb_applet applets[] = { /* name, main, location, need_suid */
# define APPLET(name,l,s) { #name, #name, l, s },
# define APPLET_ODDNAME(name,main,l,s,name2) { #name, #main, l, s },
# define APPLET_NOEXEC(name,main,l,s,name2) { #name, #main, l, s, 1 },
# define APPLET_NOFORK(name,main,l,s,name2) { #name, #main, l, s, 1, 1 },
# define APPLET_ODDNAME(name,main,l,s,help) { #name, #main, l, s },
# define APPLET_NOEXEC(name,main,l,s,help) { #name, #main, l, s, 1 },
# define APPLET_NOFORK(name,main,l,s,help) { #name, #main, l, s, 1, 1 },
#endif
#if ENABLE_INSTALL_NO_USR
@@ -104,7 +104,6 @@ IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP))
IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP))
IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
IF_CROND(APPLET(crond, BB_DIR_USR_SBIN, BB_SUID_DROP))
/* Needs to be run by root or be suid root - needs to change /var/spool/cron* files: */
IF_CRONTAB(APPLET(crontab, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
IF_CRYPTPW(APPLET(cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP))
@@ -343,7 +342,6 @@ IF_BB_SYSCTL(APPLET(sysctl, BB_DIR_SBIN, BB_SUID_DROP))
IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP))
IF_TAC(APPLET_NOEXEC(tac, tac, BB_DIR_USR_BIN, BB_SUID_DROP, tac))
IF_TAIL(APPLET(tail, BB_DIR_USR_BIN, BB_SUID_DROP))
IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP))
/* IF_TC(APPLET(tc, BB_DIR_SBIN, BB_SUID_DROP)) */
IF_TCPSVD(APPLET_ODDNAME(tcpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, tcpsvd))
IF_TEE(APPLET(tee, BB_DIR_USR_BIN, BB_SUID_DROP))
@@ -391,7 +389,7 @@ IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami))
IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
IF_ZCIP(APPLET(zcip, BB_DIR_SBIN, BB_SUID_DROP))
#if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE) \
#if !defined(PROTOTYPES) && !defined(NAME_MAIN) && !defined(MAKE_USAGE) \
&& !defined(MAKE_LINKS) && !defined(MAKE_SUID)
};
#endif
+32 -18
View File
@@ -203,43 +203,57 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len) FAST_FUNC;
void dealloc_bunzip(bunzip_data *bd) FAST_FUNC;
/* Meaning and direction (input/output) of the fields are transformer-specific */
typedef struct transformer_aux_data_t {
typedef struct transformer_state_t {
smallint check_signature; /* most often referenced member */
IF_DESKTOP(long long) int FAST_FUNC (*xformer)(struct transformer_state_t *xstate);
USE_FOR_NOMMU(const char *xformer_prog;)
/* Source */
int src_fd;
/* Output */
int dst_fd;
size_t mem_output_size_max; /* if non-zero, decompress to RAM instead of fd */
size_t mem_output_size;
char *mem_output_buf;
off_t bytes_out;
off_t bytes_in; /* used in unzip code only: needs to know packed size */
uint32_t crc32;
time_t mtime; /* gunzip code may set this on exit */
} transformer_aux_data_t;
} transformer_state_t;
void init_transformer_aux_data(transformer_aux_data_t *aux) FAST_FUNC;
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16) FAST_FUNC;
void init_transformer_state(transformer_state_t *xstate) FAST_FUNC;
ssize_t transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) FAST_FUNC;
ssize_t xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) FAST_FUNC;
int check_signature16(transformer_state_t *xstate, unsigned magic16) FAST_FUNC;
IF_DESKTOP(long long) int inflate_unzip(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
IF_DESKTOP(long long) int unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
IF_DESKTOP(long long) int unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
IF_DESKTOP(long long) int unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
IF_DESKTOP(long long) int unpack_lzma_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
IF_DESKTOP(long long) int unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
IF_DESKTOP(long long) int inflate_unzip(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_Z_stream(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_gz_stream(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_bz2_stream(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_lzma_stream(transformer_state_t *xstate) FAST_FUNC;
IF_DESKTOP(long long) int unpack_xz_stream(transformer_state_t *xstate) FAST_FUNC;
char* append_ext(char *filename, const char *expected_ext) FAST_FUNC;
int bbunpack(char **argv,
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
const char *expected_ext
) FAST_FUNC;
void check_errors_in_children(int signo);
#if BB_MMU
void open_transformer(int fd,
void fork_transformer(int fd,
int check_signature,
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
) FAST_FUNC;
#define open_transformer_with_sig(fd, transformer, transform_prog) open_transformer((fd), 1, (transformer))
#define open_transformer_with_no_sig(fd, transformer) open_transformer((fd), 0, (transformer))
#define fork_transformer_with_sig(fd, transformer, transform_prog) fork_transformer((fd), 1, (transformer))
#define fork_transformer_with_no_sig(fd, transformer) fork_transformer((fd), 0, (transformer))
#else
void open_transformer(int fd, const char *transform_prog) FAST_FUNC;
#define open_transformer_with_sig(fd, transformer, transform_prog) open_transformer((fd), (transform_prog))
/* open_transformer_with_no_sig() does not exist on NOMMU */
void fork_transformer(int fd, const char *transform_prog) FAST_FUNC;
#define fork_transformer_with_sig(fd, transformer, transform_prog) fork_transformer((fd), (transform_prog))
/* fork_transformer_with_no_sig() does not exist on NOMMU */
#endif
+166 -9
View File
@@ -334,6 +334,8 @@ enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */
FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10,
#endif
FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
/* -v */
FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE,
};
#define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
extern int remove_file(const char *path, int flags) FAST_FUNC;
@@ -388,8 +390,8 @@ const char *bb_basename(const char *name) FAST_FUNC;
char *last_char_is(const char *s, int c) FAST_FUNC;
const char* endofname(const char *name) FAST_FUNC;
void ndelay_on(int fd) FAST_FUNC;
void ndelay_off(int fd) FAST_FUNC;
int ndelay_on(int fd) FAST_FUNC;
int ndelay_off(int fd) FAST_FUNC;
void close_on_exec_on(int fd) FAST_FUNC;
void xdup2(int, int) FAST_FUNC;
void xmove_fd(int, int) FAST_FUNC;
@@ -650,6 +652,8 @@ char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
unsigned count_strstr(const char *str, const char *sub) FAST_FUNC;
char *xmalloc_substitute_string(const char *src, int count, const char *sub, const char *repl) FAST_FUNC;
/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc.
* But potentially slow, don't use in one-billion-times loops */
int bb_putchar(int ch) FAST_FUNC;
@@ -727,6 +731,18 @@ extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST
/* Never returns NULL */
extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
#if defined(ARG_MAX) && (ARG_MAX >= 60*1024 || !defined(_SC_ARG_MAX))
/* Use _constant_ maximum if: defined && (big enough || no variable one exists) */
# define bb_arg_max() ((unsigned)ARG_MAX)
#elif defined(_SC_ARG_MAX)
/* Else use variable one (a bit more expensive) */
unsigned bb_arg_max(void) FAST_FUNC;
#else
/* If all else fails */
# define bb_arg_max() ((unsigned)(32 * 1024))
#endif
unsigned bb_clk_tck(void) FAST_FUNC;
#define SEAMLESS_COMPRESSION (0 \
|| ENABLE_FEATURE_SEAMLESS_XZ \
|| ENABLE_FEATURE_SEAMLESS_LZMA \
@@ -736,14 +752,15 @@ extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAS
#if SEAMLESS_COMPRESSION
/* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */
extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC;
extern int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC;
/* Autodetects .gz etc */
extern int open_zipped(const char *fname) FAST_FUNC;
extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC;
extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
#else
# define setup_unzip_on_fd(...) (0)
# define open_zipped(fname) open((fname), O_RDONLY);
# define open_zipped(fname, fail_if_not_compressed) open((fname), O_RDONLY);
# define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p))
#endif
extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC;
// NB: will return short write on error, not -1,
@@ -910,9 +927,9 @@ void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const
#endif
int execable_file(const char *name) FAST_FUNC;
char *find_execable(const char *filename, char **PATHp) FAST_FUNC;
int exists_execable(const char *filename) FAST_FUNC;
int file_is_executable(const char *name) FAST_FUNC;
char *find_executable(const char *filename, char **PATHp) FAST_FUNC;
int executable_exists(const char *filename) FAST_FUNC;
/* BB_EXECxx always execs (it's not doing NOFORK/NOEXEC stuff),
* but it may exec busybox and call applet instead of searching PATH.
@@ -1072,6 +1089,7 @@ enum {
LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
};
extern const char *msg_eol;
extern smallint syslog_level;
extern smallint logmode;
extern int die_sleep;
extern uint8_t xfunc_error_retval;
@@ -1090,6 +1108,7 @@ extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
extern void bb_perror_nomsg(void) FAST_FUNC;
extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
extern void bb_logenv_override(void) FAST_FUNC;
/* We need to export XXX_main from libbusybox
* only if we build "individual" binaries
@@ -1252,7 +1271,9 @@ char *bb_simplify_path(const char *path) FAST_FUNC;
/* Returns ptr to NUL */
char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
#ifndef LOGIN_FAIL_DELAY
#define LOGIN_FAIL_DELAY 3
#endif
extern void bb_do_delay(int seconds) FAST_FUNC;
extern void change_identity(const struct passwd *pw) FAST_FUNC;
extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) NORETURN FAST_FUNC;
@@ -1302,6 +1323,7 @@ int sd_listen_fds(void);
#define SETUP_ENV_NO_CHDIR (1 << 4)
void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
void nuke_str(char *str) FAST_FUNC;
int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC;
int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
/* Returns a malloced string */
@@ -1927,6 +1949,141 @@ static ALWAYS_INLINE unsigned char bb_ascii_tolower(unsigned char a)
#define isprint_asciionly(a) ((unsigned)((a) - 0x20) <= 0x7e - 0x20)
/* Simple unit-testing framework */
typedef void (*bbunit_testfunc)(void);
struct bbunit_listelem {
struct bbunit_listelem* next;
const char* name;
bbunit_testfunc testfunc;
};
void bbunit_registertest(struct bbunit_listelem* test);
void bbunit_settestfailed(void);
#define BBUNIT_DEFINE_TEST(NAME) \
static void bbunit_##NAME##_test(void); \
static struct bbunit_listelem bbunit_##NAME##_elem = { \
.name = #NAME, \
.testfunc = bbunit_##NAME##_test, \
}; \
static void INIT_FUNC bbunit_##NAME##_register(void) \
{ \
bbunit_registertest(&bbunit_##NAME##_elem); \
} \
static void bbunit_##NAME##_test(void)
/*
* Both 'goto bbunit_end' and 'break' are here only to get rid
* of compiler warnings.
*/
#define BBUNIT_ENDTEST \
do { \
goto bbunit_end; \
bbunit_end: \
break; \
} while (0)
#define BBUNIT_PRINTASSERTFAIL \
do { \
bb_error_msg( \
"[ERROR] Assertion failed in file %s, line %d", \
__FILE__, __LINE__); \
} while (0)
#define BBUNIT_ASSERTION_FAILED \
do { \
bbunit_settestfailed(); \
goto bbunit_end; \
} while (0)
/*
* Assertions.
* For now we only offer assertions which cause tests to fail
* immediately. In the future 'expects' might be added too -
* similar to those offered by the gtest framework.
*/
#define BBUNIT_ASSERT_EQ(EXPECTED, ACTUAL) \
do { \
if ((EXPECTED) != (ACTUAL)) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] '%s' isn't equal to '%s'", \
#EXPECTED, #ACTUAL); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
#define BBUNIT_ASSERT_NOTEQ(EXPECTED, ACTUAL) \
do { \
if ((EXPECTED) == (ACTUAL)) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] '%s' is equal to '%s'", \
#EXPECTED, #ACTUAL); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
#define BBUNIT_ASSERT_NOTNULL(PTR) \
do { \
if ((PTR) == NULL) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] '%s' is NULL!", #PTR); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
#define BBUNIT_ASSERT_NULL(PTR) \
do { \
if ((PTR) != NULL) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] '%s' is not NULL!", #PTR); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
#define BBUNIT_ASSERT_FALSE(STATEMENT) \
do { \
if ((STATEMENT)) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] Statement '%s' evaluated to true!", \
#STATEMENT); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
#define BBUNIT_ASSERT_TRUE(STATEMENT) \
do { \
if (!(STATEMENT)) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] Statement '%s' evaluated to false!", \
#STATEMENT); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
#define BBUNIT_ASSERT_STREQ(STR1, STR2) \
do { \
if (strcmp(STR1, STR2) != 0) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] Strings '%s' and '%s' " \
"are not the same", STR1, STR2); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
#define BBUNIT_ASSERT_STRNOTEQ(STR1, STR2) \
do { \
if (strcmp(STR1, STR2) == 0) { \
BBUNIT_PRINTASSERTFAIL; \
bb_error_msg("[ERROR] Strings '%s' and '%s' " \
"are the same, but were " \
"expected to differ", STR1, STR2); \
BBUNIT_ASSERTION_FAILED; \
} \
} while (0)
POP_SAVED_FUNCTION_VISIBILITY
#endif
+39 -8
View File
@@ -76,6 +76,9 @@
# define UNUSED_PARAM_RESULT
#endif
/* used by unit test machinery to run registration functions before calling main() */
#define INIT_FUNC __attribute__ ((constructor))
/* -fwhole-program makes all symbols local. The attribute externally_visible
* forces a symbol global. */
#if __GNUC_PREREQ(4,1)
@@ -373,6 +376,7 @@ typedef unsigned smalluint;
#define HAVE_STRSIGNAL 1
#define HAVE_STRVERSCMP 1
#define HAVE_VASPRINTF 1
#define HAVE_USLEEP 1
#define HAVE_UNLOCKED_STDIO 1
#define HAVE_UNLOCKED_LINE_OPS 1
#define HAVE_GETLINE 1
@@ -381,12 +385,15 @@ typedef unsigned smalluint;
#define HAVE_NET_ETHERNET_H 1
#define HAVE_SYS_STATFS_H 1
#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
# undef HAVE_STRVERSCMP
#endif
#if defined(__dietlibc__)
# undef HAVE_STRCHRNUL
#if defined(__UCLIBC__)
# if UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
# undef HAVE_STRVERSCMP
# endif
# if UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
# ifndef __UCLIBC_SUSV3_LEGACY__
# undef HAVE_USLEEP
# endif
# endif
#endif
#if defined(__WATCOMC__)
@@ -419,7 +426,7 @@ typedef unsigned smalluint;
/* These BSD-derived OSes share many similarities */
#if (defined __digital__ && defined __unix__) \
|| defined __APPLE__ \
|| defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
|| defined __OpenBSD__ || defined __NetBSD__
# undef HAVE_CLEARENV
# undef HAVE_FDATASYNC
# undef HAVE_GETLINE
@@ -434,10 +441,30 @@ typedef unsigned smalluint;
# undef HAVE_UNLOCKED_LINE_OPS
#endif
#if defined(__FreeBSD__) || defined(__APPLE__)
#if defined(__dietlibc__)
# undef HAVE_STRCHRNUL
#endif
#if defined(__APPLE__)
# undef HAVE_STRCHRNUL
#endif
#if defined(__FreeBSD__)
# undef HAVE_CLEARENV
# undef HAVE_FDATASYNC
# undef HAVE_MNTENT_H
# undef HAVE_PTSNAME_R
# undef HAVE_SYS_STATFS_H
# undef HAVE_SIGHANDLER_T
# undef HAVE_STRVERSCMP
# undef HAVE_XTABS
# undef HAVE_UNLOCKED_LINE_OPS
# include <osreldate.h>
# if __FreeBSD_version < 1000029
# undef HAVE_STRCHRNUL /* FreeBSD added strchrnul() between 1000028 and 1000029 */
# endif
#endif
#if defined(__NetBSD__)
# define HAVE_GETLINE 1 /* Recent NetBSD versions have getline() */
#endif
@@ -503,6 +530,10 @@ extern char *strsep(char **stringp, const char *delim) FAST_FUNC;
# define strsignal(sig) get_signame(sig)
#endif
#ifndef HAVE_USLEEP
extern int usleep(unsigned) FAST_FUNC;
#endif
#ifndef HAVE_VASPRINTF
extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
#endif
+30 -18
View File
@@ -822,7 +822,7 @@ static void halt_reboot_pwoff(int sig)
/* Handler for QUIT - exec "restart" action,
* else (no such action defined) do nothing */
static void restart_handler(int sig UNUSED_PARAM)
static void exec_restart_action(void)
{
struct init_action *a;
@@ -975,6 +975,20 @@ static int check_delayed_sigs(void)
#endif
if (sig == SIGINT)
run_actions(CTRLALTDEL);
if (sig == SIGQUIT) {
exec_restart_action();
/* returns only if no restart action defined */
}
if ((1 << sig) & (0
#ifdef SIGPWR
+ (1 << SIGPWR)
#endif
+ (1 << SIGUSR1)
+ (1 << SIGUSR2)
+ (1 << SIGTERM)
)) {
halt_reboot_pwoff(sig);
}
}
}
@@ -1070,7 +1084,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
#if 0
/* It's 2013, does anyone really still depend on this? */
/* If you do, consider adding swapon to sysinot actions then! */
/* If you do, consider adding swapon to sysinit actions then! */
/* struct sysinfo is linux-specific */
# ifdef __linux__
/* Make sure there is enough memory to do something useful. */
@@ -1134,14 +1148,6 @@ int init_main(int argc UNUSED_PARAM, char **argv)
if (!DEBUG_INIT) {
struct sigaction sa;
bb_signals(0
+ (1 << SIGPWR) /* halt */
+ (1 << SIGUSR1) /* halt */
+ (1 << SIGTERM) /* reboot */
+ (1 << SIGUSR2) /* poweroff */
, halt_reboot_pwoff);
signal(SIGQUIT, restart_handler); /* re-exec another init */
/* Stop handler must allow only SIGCONT inside itself */
memset(&sa, 0, sizeof(sa));
sigfillset(&sa.sa_mask);
@@ -1156,18 +1162,24 @@ int init_main(int argc UNUSED_PARAM, char **argv)
*/
sigaction_set(SIGSTOP, &sa); /* pause */
/* SIGINT (Ctrl-Alt-Del) must interrupt wait(),
/* These signals must interrupt wait(),
* setting handler without SA_RESTART flag.
*/
bb_signals_recursive_norestart((1 << SIGINT), record_signo);
bb_signals_recursive_norestart(0
+ (1 << SIGINT) /* Ctrl-Alt-Del */
+ (1 << SIGQUIT) /* re-exec another init */
#ifdef SIGPWR
+ (1 << SIGPWR) /* halt */
#endif
+ (1 << SIGUSR1) /* halt */
+ (1 << SIGTERM) /* reboot */
+ (1 << SIGUSR2) /* poweroff */
#if ENABLE_FEATURE_USE_INITTAB
+ (1 << SIGHUP) /* reread /etc/inittab */
#endif
, record_signo);
}
/* Set up "reread /etc/inittab" handler.
* Handler is set up without SA_RESTART, it will interrupt syscalls.
*/
if (!DEBUG_INIT && ENABLE_FEATURE_USE_INITTAB)
bb_signals_recursive_norestart((1 << SIGHUP), record_signo);
/* Now run everything that needs to be run */
/* First run the sysinit command */
run_actions(SYSINIT);
+7 -1
View File
@@ -30,7 +30,7 @@ lib-y += crc32.o
lib-y += default_error_retval.o
lib-y += device_open.o
lib-y += dump.o
lib-y += execable.o
lib-y += executable.o
lib-y += fclose_nonstdin.o
lib-y += fflush_stdout_and_exit.o
lib-y += fgets_str.o
@@ -92,6 +92,7 @@ lib-y += skip_whitespace.o
lib-y += speed_table.o
lib-y += str_tolower.o
lib-y += strrstr.o
lib-y += sysconf.o
lib-y += time.o
lib-y += trim.o
lib-y += u_signal_names.o
@@ -141,6 +142,7 @@ lib-$(CONFIG_ADDUSER) += update_passwd.o
lib-$(CONFIG_DELGROUP) += update_passwd.o
lib-$(CONFIG_DELUSER) += update_passwd.o
lib-$(CONFIG_FTPD) += correct_password.o
lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o obscure.o
lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o
lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
@@ -149,6 +151,7 @@ lib-$(CONFIG_VLOCK) += pw_encrypt.o correct_password.o
lib-$(CONFIG_SU) += pw_encrypt.o correct_password.o
lib-$(CONFIG_LOGIN) += pw_encrypt.o correct_password.o
lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
lib-$(CONFIG_FEATURE_FTP_AUTHENTICATION) += pw_encrypt.o
lib-$(CONFIG_DF) += find_mount_point.o
lib-$(CONFIG_MKFS_MINIX) += find_mount_point.o
@@ -185,3 +188,6 @@ lib-$(CONFIG_PGREP) += xregcomp.o
lib-$(CONFIG_PKILL) += xregcomp.o
lib-$(CONFIG_DEVFSD) += xregcomp.o
lib-$(CONFIG_FEATURE_FIND_REGEX) += xregcomp.o
# Add the experimental logging functionality, only used by zcip
lib-$(CONFIG_ZCIP) += logenv.o
+28 -13
View File
@@ -184,8 +184,7 @@ void lbb_prepare(const char *applet
#endif
applet_name = applet;
/* Set locale for everybody except 'init' */
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
if (ENABLE_LOCALE_SUPPORT)
setlocale(LC_ALL, "");
#if ENABLE_FEATURE_INDIVIDUAL
@@ -606,7 +605,11 @@ static void install_links(const char *busybox, int use_symbolic_links,
}
}
# else
# define install_links(x,y,z) ((void)0)
static void install_links(const char *busybox UNUSED_PARAM,
int use_symbolic_links UNUSED_PARAM,
char *custom_install_dir UNUSED_PARAM)
{
}
# endif
/* If we were called as "busybox..." */
@@ -730,7 +733,8 @@ static int busybox_main(char **argv)
/*bb_error_msg_and_die("applet not found"); - sucks in printf */
full_write2_str(applet_name);
full_write2_str(": applet not found\n");
xfunc_die();
/* POSIX: "If a command is not found, the exit status shall be 127" */
exit(127);
}
void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
@@ -742,15 +746,25 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
/* Reinit some shared global data */
xfunc_error_retval = EXIT_FAILURE;
applet_name = APPLET_NAME(applet_no);
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
/* Special case. POSIX says "test --help"
* should be no different from e.g. "test --foo". */
//TODO: just compare applet_no with APPLET_NO_test
if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) {
/* If you want "foo --help" to return 0: */
xfunc_error_retval = 0;
#if defined APPLET_NO_test
/* Special case. POSIX says "test --help"
* should be no different from e.g. "test --foo".
* Thus for "test", we skip --help check.
*/
if (applet_no != APPLET_NO_test)
#endif
{
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
#if defined APPLET_NO_false
/* Someone insisted that "false --help" must exit 1. Sigh */
if (applet_no != APPLET_NO_false)
#endif
{
/* Make "foo --help" exit with 0: */
xfunc_error_retval = 0;
}
bb_show_usage();
}
}
@@ -825,6 +839,7 @@ int main(int argc UNUSED_PARAM, char **argv)
/*bb_error_msg_and_die("applet not found"); - sucks in printf */
full_write2_str(applet_name);
full_write2_str(": applet not found\n");
xfunc_die();
/* POSIX: "If a command is not found, the exit status shall be 127" */
exit(127);
#endif
}
+4 -1
View File
@@ -30,9 +30,12 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
struct sigaction sa, oldsa;
struct termios tio, oldtio;
tcflush(fd, TCIFLUSH);
/* Was buggy: was printing prompt *before* flushing input,
* which was upsetting "expect" based scripts of some users.
*/
fputs(prompt, stdout);
fflush_all();
tcflush(fd, TCIFLUSH);
tcgetattr(fd, &oldtio);
tio = oldtio;
+90
View File
@@ -0,0 +1,90 @@
/* vi: set sw=4 ts=4: */
/*
* bbunit: Simple unit-testing framework for Busybox.
*
* Copyright (C) 2014 by Bartosz Golaszewski <bartekgola@gmail.com>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//kbuild:lib-$(CONFIG_UNIT_TEST) += bbunit.o
//applet:IF_UNIT_TEST(APPLET(unit, BB_DIR_USR_BIN, BB_SUID_DROP))
//usage:#define unit_trivial_usage
//usage: ""
//usage:#define unit_full_usage "\n\n"
//usage: "Run the unit-test suite"
#include "libbb.h"
#define WANT_TIMING 0
static llist_t *tests = NULL;
static unsigned tests_registered = 0;
static int test_retval;
void bbunit_registertest(struct bbunit_listelem *test)
{
llist_add_to_end(&tests, test);
tests_registered++;
}
void bbunit_settestfailed(void)
{
test_retval = -1;
}
#if WANT_TIMING
static void timeval_diff(struct timeval* res,
const struct timeval* x,
const struct timeval* y)
{
long udiff = x->tv_usec - y->tv_usec;
res->tv_sec = x->tv_sec - y->tv_sec - (udiff < 0);
res->tv_usec = (udiff >= 0 ? udiff : udiff + 1000000);
}
#endif
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE;
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
unsigned tests_run = 0;
unsigned tests_failed = 0;
#if WANT_TIMING
struct timeval begin;
struct timeval end;
struct timeval time_spent;
gettimeofday(&begin, NULL);
#endif
bb_error_msg("Running %d test(s)...", tests_registered);
for (;;) {
struct bbunit_listelem* el = llist_pop(&tests);
if (!el)
break;
bb_error_msg("Case: [%s]", el->name);
test_retval = 0;
el->testfunc();
if (test_retval < 0) {
bb_error_msg("[ERROR] [%s]: TEST FAILED", el->name);
tests_failed++;
}
tests_run++;
el = el->next;
}
#if WANT_TIMING
gettimeofday(&end, NULL);
timeval_diff(&time_spent, &end, &begin);
bb_error_msg("Elapsed time %u.%06u seconds",
(int)time_spent.tv_sec,
(int)time_spent.tv_usec);
#endif
if (tests_failed > 0) {
bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed);
return EXIT_FAILURE;
}
bb_error_msg("All tests passed");
return EXIT_SUCCESS;
}
+4
View File
@@ -389,5 +389,9 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
bb_perror_msg("can't preserve %s of '%s'", "permissions", dest);
}
if (flags & FILEUTILS_VERBOSE) {
printf("'%s' -> '%s'\n", source, dest);
}
return retval;
}
+56 -31
View File
@@ -8,6 +8,20 @@
*/
#include "libbb.h"
#if ENABLE_FEATURE_USE_SENDFILE
# include <sys/sendfile.h>
#else
# define sendfile(a,b,c,d) (-1)
#endif
/*
* We were using 0x7fff0000 as sendfile chunk size, but it
* was seen to cause largish delays when user tries to ^C a file copy.
* Let's use a saner size.
* Note: needs to be >= max(CONFIG_FEATURE_COPYBUF_KB),
* or else "copy to eof" code will use neddlesly short reads.
*/
#define SENDFILE_BIGBUF (16*1024*1024)
/* Used by NOFORK applets (e.g. cat) - must not use xmalloc.
* size < 0 means "ignore write errors", used by tar --to-command
@@ -18,12 +32,13 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
int status = -1;
off_t total = 0;
bool continue_on_write_error = 0;
#if CONFIG_FEATURE_COPYBUF_KB <= 4
ssize_t sendfile_sz;
#if CONFIG_FEATURE_COPYBUF_KB > 4
char *buffer = buffer; /* for compiler */
int buffer_size = 0;
#else
char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024];
enum { buffer_size = sizeof(buffer) };
#else
char *buffer;
int buffer_size;
#endif
if (size < 0) {
@@ -31,46 +46,58 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
continue_on_write_error = 1;
}
#if CONFIG_FEATURE_COPYBUF_KB > 4
if (size > 0 && size <= 4 * 1024)
goto use_small_buf;
/* We want page-aligned buffer, just in case kernel is clever
* and can do page-aligned io more efficiently */
buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
/* ignored: */ -1, 0);
buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
if (buffer == MAP_FAILED) {
use_small_buf:
buffer = alloca(4 * 1024);
buffer_size = 4 * 1024;
}
#endif
if (src_fd < 0)
goto out;
sendfile_sz = !ENABLE_FEATURE_USE_SENDFILE
? 0
: SENDFILE_BIGBUF;
if (!size) {
size = buffer_size;
size = SENDFILE_BIGBUF;
status = 1; /* copy until eof */
}
while (1) {
ssize_t rd;
rd = safe_read(src_fd, buffer, size > buffer_size ? buffer_size : size);
if (!rd) { /* eof - all done */
status = 0;
break;
if (sendfile_sz) {
rd = sendfile(dst_fd, src_fd, NULL,
size > sendfile_sz ? sendfile_sz : size);
if (rd >= 0)
goto read_ok;
sendfile_sz = 0; /* do not try sendfile anymore */
}
#if CONFIG_FEATURE_COPYBUF_KB > 4
if (buffer_size == 0) {
if (size > 0 && size <= 4 * 1024)
goto use_small_buf;
/* We want page-aligned buffer, just in case kernel is clever
* and can do page-aligned io more efficiently */
buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
/* ignored: */ -1, 0);
buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
if (buffer == MAP_FAILED) {
use_small_buf:
buffer = alloca(4 * 1024);
buffer_size = 4 * 1024;
}
}
#endif
rd = safe_read(src_fd, buffer,
size > buffer_size ? buffer_size : size);
if (rd < 0) {
bb_perror_msg(bb_msg_read_error);
break;
}
read_ok:
if (!rd) { /* eof - all done */
status = 0;
break;
}
/* dst_fd == -1 is a fake, else... */
if (dst_fd >= 0) {
if (dst_fd >= 0 && !sendfile_sz) {
ssize_t wr = full_write(dst_fd, buffer, rd);
if (wr < rd) {
if (!continue_on_write_error) {
@@ -92,10 +119,8 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
}
out:
#if CONFIG_FEATURE_COPYBUF_KB > 4
if (buffer_size != 4 * 1024)
if (buffer_size > 4 * 1024)
munmap(buffer, buffer_size);
#endif
return status ? -1 : total;
}
+67 -29
View File
@@ -30,6 +30,63 @@
#include "libbb.h"
#define SHADOW_BUFSIZE 256
/* Retrieve encrypted password string for pw.
* If pw == NULL, return a string which fails password check against any
* password.
*/
#if !ENABLE_FEATURE_SHADOWPASSWDS
#define get_passwd(pw, buffer) get_passwd(pw)
#endif
static const char *get_passwd(const struct passwd *pw, char buffer[SHADOW_BUFSIZE])
{
const char *pass;
if (!pw)
return "aa"; /* "aa" will never match */
pass = pw->pw_passwd;
#if ENABLE_FEATURE_SHADOWPASSWDS
/* Using _r function to avoid pulling in static buffers */
if ((pass[0] == 'x' || pass[0] == '*') && !pass[1]) {
struct spwd spw;
int r;
/* getspnam_r may return 0 yet set result to NULL.
* At least glibc 2.4 does this. Be extra paranoid here. */
struct spwd *result = NULL;
r = getspnam_r(pw->pw_name, &spw, buffer, SHADOW_BUFSIZE, &result);
pass = (r || !result) ? "aa" : result->sp_pwdp;
}
#endif
return pass;
}
/*
* Return 1 if PW has an empty password.
* Return 1 if the user gives the correct password for entry PW,
* 0 if not.
* NULL pw means "just fake it for login with bad username"
*/
int FAST_FUNC check_password(const struct passwd *pw, const char *plaintext)
{
IF_FEATURE_SHADOWPASSWDS(char buffer[SHADOW_BUFSIZE];)
char *encrypted;
const char *pw_pass;
int r;
pw_pass = get_passwd(pw, buffer);
if (!pw_pass[0]) { /* empty password field? */
return 1;
}
encrypted = pw_encrypt(plaintext, /*salt:*/ pw_pass, 1);
r = (strcmp(encrypted, pw_pass) == 0);
free(encrypted);
return r;
}
/* Ask the user for a password.
* Return 1 without asking if PW has an empty password.
* Return -1 on EOF, error while reading input, or timeout.
@@ -41,42 +98,23 @@
int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw,
int timeout, const char *prompt)
{
char *unencrypted, *encrypted;
const char *correct;
IF_FEATURE_SHADOWPASSWDS(char buffer[SHADOW_BUFSIZE];)
char *plaintext;
const char *pw_pass;
int r;
/* fake salt. crypt() can choke otherwise. */
correct = "aa";
if (!pw) {
/* "aa" will never match */
goto fake_it;
}
correct = pw->pw_passwd;
#if ENABLE_FEATURE_SHADOWPASSWDS
/* Using _r function to avoid pulling in static buffers */
if ((correct[0] == 'x' || correct[0] == '*') && !correct[1]) {
struct spwd spw;
char buffer[256];
/* getspnam_r may return 0 yet set result to NULL.
* At least glibc 2.4 does this. Be extra paranoid here. */
struct spwd *result = NULL;
r = getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result);
correct = (r || !result) ? "aa" : result->sp_pwdp;
}
#endif
if (!correct[0]) /* empty password field? */
pw_pass = get_passwd(pw, buffer);
if (!pw_pass[0]) /* empty password field? */
return 1;
fake_it:
unencrypted = bb_ask(STDIN_FILENO, timeout, prompt);
if (!unencrypted) {
plaintext = bb_ask(STDIN_FILENO, timeout, prompt);
if (!plaintext) {
/* EOF (such as ^D) or error (such as ^C) or timeout */
return -1;
}
encrypted = pw_encrypt(unencrypted, correct, 1);
r = (strcmp(encrypted, correct) == 0);
free(encrypted);
nuke_str(unencrypted);
r = check_password(pw, plaintext);
nuke_str(plaintext);
return r;
}
+23 -17
View File
@@ -13,7 +13,7 @@
* return 1 if found;
* return 0 otherwise;
*/
int FAST_FUNC execable_file(const char *name)
int FAST_FUNC file_is_executable(const char *name)
{
struct stat s;
return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode));
@@ -23,13 +23,21 @@ int FAST_FUNC execable_file(const char *name)
* return allocated string containing full path if found;
* PATHp points to the component after the one where it was found
* (or NULL),
* you may call find_execable again with this PATHp to continue
* you may call find_executable again with this PATHp to continue
* (if it's not NULL).
* return NULL otherwise; (PATHp is undefined)
* in all cases (*PATHp) contents will be trashed (s/:/NUL/).
*/
char* FAST_FUNC find_execable(const char *filename, char **PATHp)
char* FAST_FUNC find_executable(const char *filename, char **PATHp)
{
/* About empty components in $PATH:
* http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
* 8.3 Other Environment Variables - PATH
* A zero-length prefix is a legacy feature that indicates the current
* working directory. It appears as two adjacent colons ( "::" ), as an
* initial colon preceding the rest of the list, or as a trailing colon
* following the rest of the list.
*/
char *p, *n;
p = *PATHp;
@@ -37,14 +45,15 @@ char* FAST_FUNC find_execable(const char *filename, char **PATHp)
n = strchr(p, ':');
if (n)
*n++ = '\0';
if (*p != '\0') { /* it's not a PATH="foo::bar" situation */
p = concat_path_file(p, filename);
if (execable_file(p)) {
*PATHp = n;
return p;
}
free(p);
p = concat_path_file(
p[0] ? p : ".", /* handle "::" case */
filename
);
if (file_is_executable(p)) {
*PATHp = n;
return p;
}
free(p);
p = n;
} /* on loop exit p == NULL */
return p;
@@ -54,17 +63,14 @@ char* FAST_FUNC find_execable(const char *filename, char **PATHp)
* return 1 if found;
* return 0 otherwise;
*/
int FAST_FUNC exists_execable(const char *filename)
int FAST_FUNC executable_exists(const char *filename)
{
char *path = xstrdup(getenv("PATH"));
char *tmp = path;
char *ret = find_execable(filename, &tmp);
char *ret = find_executable(filename, &tmp);
free(path);
if (ret) {
free(ret);
return 1;
}
return 0;
free(ret);
return ret != NULL;
}
#if ENABLE_FEATURE_PREFER_APPLETS
+1 -1
View File
@@ -16,7 +16,7 @@ int FAST_FUNC xgetpty(char *line)
#if ENABLE_FEATURE_DEVPTS
p = open("/dev/ptmx", O_RDWR);
if (p > 0) {
if (p >= 0) {
grantpt(p); /* chmod+chown corresponding slave pty */
unlockpt(p); /* (what does this do?) */
# ifndef HAVE_PTSNAME_R
+298 -19
View File
@@ -926,10 +926,81 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
# define SHA3_SMALL CONFIG_SHA3_SMALL
#endif
#define OPTIMIZE_SHA3_FOR_32 0
/*
* SHA3 can be optimized for 32-bit CPUs with bit-slicing:
* every 64-bit word of state[] can be split into two 32-bit words
* by even/odd bits. In this form, all rotations of sha3 round
* are 32-bit - and there are lots of them.
* However, it requires either splitting/combining state words
* before/after sha3 round (code does this now)
* or shuffling bits before xor'ing them into state and in sha3_end.
* Without shuffling, bit-slicing results in -130 bytes of code
* and marginal speedup (but of course it gives wrong result).
* With shuffling it works, but +260 code bytes, and slower.
* Disabled for now:
*/
#if 0 /* LONG_MAX == 0x7fffffff */
# undef OPTIMIZE_SHA3_FOR_32
# define OPTIMIZE_SHA3_FOR_32 1
#endif
enum {
SHA3_IBLK_BYTES = 72, /* 576 bits / 8 */
};
#if OPTIMIZE_SHA3_FOR_32
/* This splits every 64-bit word into a pair of 32-bit words,
* even bits go into first word, odd bits go to second one.
* The conversion is done in-place.
*/
static void split_halves(uint64_t *state)
{
/* Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002 */
uint32_t *s32 = (uint32_t*)state;
uint32_t t, x0, x1;
int i;
for (i = 24; i >= 0; --i) {
x0 = s32[0];
t = (x0 ^ (x0 >> 1)) & 0x22222222; x0 = x0 ^ t ^ (t << 1);
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0C; x0 = x0 ^ t ^ (t << 2);
t = (x0 ^ (x0 >> 4)) & 0x00F000F0; x0 = x0 ^ t ^ (t << 4);
t = (x0 ^ (x0 >> 8)) & 0x0000FF00; x0 = x0 ^ t ^ (t << 8);
x1 = s32[1];
t = (x1 ^ (x1 >> 1)) & 0x22222222; x1 = x1 ^ t ^ (t << 1);
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0C; x1 = x1 ^ t ^ (t << 2);
t = (x1 ^ (x1 >> 4)) & 0x00F000F0; x1 = x1 ^ t ^ (t << 4);
t = (x1 ^ (x1 >> 8)) & 0x0000FF00; x1 = x1 ^ t ^ (t << 8);
*s32++ = (x0 & 0x0000FFFF) | (x1 << 16);
*s32++ = (x0 >> 16) | (x1 & 0xFFFF0000);
}
}
/* The reverse operation */
static void combine_halves(uint64_t *state)
{
uint32_t *s32 = (uint32_t*)state;
uint32_t t, x0, x1;
int i;
for (i = 24; i >= 0; --i) {
x0 = s32[0];
x1 = s32[1];
t = (x0 & 0x0000FFFF) | (x1 << 16);
x1 = (x0 >> 16) | (x1 & 0xFFFF0000);
x0 = t;
t = (x0 ^ (x0 >> 8)) & 0x0000FF00; x0 = x0 ^ t ^ (t << 8);
t = (x0 ^ (x0 >> 4)) & 0x00F000F0; x0 = x0 ^ t ^ (t << 4);
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0C; x0 = x0 ^ t ^ (t << 2);
t = (x0 ^ (x0 >> 1)) & 0x22222222; x0 = x0 ^ t ^ (t << 1);
*s32++ = x0;
t = (x1 ^ (x1 >> 8)) & 0x0000FF00; x1 = x1 ^ t ^ (t << 8);
t = (x1 ^ (x1 >> 4)) & 0x00F000F0; x1 = x1 ^ t ^ (t << 4);
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0C; x1 = x1 ^ t ^ (t << 2);
t = (x1 ^ (x1 >> 1)) & 0x22222222; x1 = x1 ^ t ^ (t << 1);
*s32++ = x1;
}
}
#endif
/*
* In the crypto literature this function is usually called Keccak-f().
*/
@@ -937,12 +1008,179 @@ static void sha3_process_block72(uint64_t *state)
{
enum { NROUNDS = 24 };
/* Elements should be 64-bit, but top half is always zero or 0x80000000.
* We encode 63rd bits in a separate word below.
* Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit.
* The speed penalty is lost in the noise.
*/
#if OPTIMIZE_SHA3_FOR_32
/*
static const uint32_t IOTA_CONST_0[NROUNDS] = {
0x00000001UL,
0x00000000UL,
0x00000000UL,
0x00000000UL,
0x00000001UL,
0x00000001UL,
0x00000001UL,
0x00000001UL,
0x00000000UL,
0x00000000UL,
0x00000001UL,
0x00000000UL,
0x00000001UL,
0x00000001UL,
0x00000001UL,
0x00000001UL,
0x00000000UL,
0x00000000UL,
0x00000000UL,
0x00000000UL,
0x00000001UL,
0x00000000UL,
0x00000001UL,
0x00000000UL,
};
** bits are in lsb: 0101 0000 1111 0100 1111 0001
*/
uint32_t IOTA_CONST_0bits = (uint32_t)(0x0050f4f1);
static const uint32_t IOTA_CONST_1[NROUNDS] = {
0x00000000UL,
0x00000089UL,
0x8000008bUL,
0x80008080UL,
0x0000008bUL,
0x00008000UL,
0x80008088UL,
0x80000082UL,
0x0000000bUL,
0x0000000aUL,
0x00008082UL,
0x00008003UL,
0x0000808bUL,
0x8000000bUL,
0x8000008aUL,
0x80000081UL,
0x80000081UL,
0x80000008UL,
0x00000083UL,
0x80008003UL,
0x80008088UL,
0x80000088UL,
0x00008000UL,
0x80008082UL,
};
uint32_t *const s32 = (uint32_t*)state;
unsigned round;
split_halves(state);
for (round = 0; round < NROUNDS; round++) {
unsigned x;
/* Theta */
{
uint32_t BC[20];
for (x = 0; x < 10; ++x) {
BC[x+10] = BC[x] = s32[x]^s32[x+10]^s32[x+20]^s32[x+30]^s32[x+40];
}
for (x = 0; x < 10; x += 2) {
uint32_t ta, tb;
ta = BC[x+8] ^ rotl32(BC[x+3], 1);
tb = BC[x+9] ^ BC[x+2];
s32[x+0] ^= ta;
s32[x+1] ^= tb;
s32[x+10] ^= ta;
s32[x+11] ^= tb;
s32[x+20] ^= ta;
s32[x+21] ^= tb;
s32[x+30] ^= ta;
s32[x+31] ^= tb;
s32[x+40] ^= ta;
s32[x+41] ^= tb;
}
}
/* RhoPi */
{
uint32_t t0a,t0b, t1a,t1b;
t1a = s32[1*2+0];
t1b = s32[1*2+1];
#define RhoPi(PI_LANE, ROT_CONST) \
t0a = s32[PI_LANE*2+0];\
t0b = s32[PI_LANE*2+1];\
if (ROT_CONST & 1) {\
s32[PI_LANE*2+0] = rotl32(t1b, ROT_CONST/2+1);\
s32[PI_LANE*2+1] = ROT_CONST == 1 ? t1a : rotl32(t1a, ROT_CONST/2+0);\
} else {\
s32[PI_LANE*2+0] = rotl32(t1a, ROT_CONST/2);\
s32[PI_LANE*2+1] = rotl32(t1b, ROT_CONST/2);\
}\
t1a = t0a; t1b = t0b;
RhoPi(10, 1)
RhoPi( 7, 3)
RhoPi(11, 6)
RhoPi(17,10)
RhoPi(18,15)
RhoPi( 3,21)
RhoPi( 5,28)
RhoPi(16,36)
RhoPi( 8,45)
RhoPi(21,55)
RhoPi(24, 2)
RhoPi( 4,14)
RhoPi(15,27)
RhoPi(23,41)
RhoPi(19,56)
RhoPi(13, 8)
RhoPi(12,25)
RhoPi( 2,43)
RhoPi(20,62)
RhoPi(14,18)
RhoPi(22,39)
RhoPi( 9,61)
RhoPi( 6,20)
RhoPi( 1,44)
#undef RhoPi
}
/* Chi */
for (x = 0; x <= 40;) {
uint32_t BC0, BC1, BC2, BC3, BC4;
BC0 = s32[x + 0*2];
BC1 = s32[x + 1*2];
BC2 = s32[x + 2*2];
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
BC3 = s32[x + 3*2];
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
BC4 = s32[x + 4*2];
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
x++;
BC0 = s32[x + 0*2];
BC1 = s32[x + 1*2];
BC2 = s32[x + 2*2];
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
BC3 = s32[x + 3*2];
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
BC4 = s32[x + 4*2];
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
x += 9;
}
/* Iota */
s32[0] ^= IOTA_CONST_0bits & 1;
IOTA_CONST_0bits >>= 1;
s32[1] ^= IOTA_CONST_1[round];
}
combine_halves(state);
#else
/* Native 64-bit algorithm */
static const uint16_t IOTA_CONST[NROUNDS] = {
/* Elements should be 64-bit, but top half is always zero
* or 0x80000000. We encode 63rd bits in a separate word below.
* Same is true for 31th bits, which lets us use 16-bit table
* instead of 64-bit. The speed penalty is lost in the noise.
*/
0x0001,
0x8082,
0x808a,
@@ -983,7 +1221,7 @@ static void sha3_process_block72(uint64_t *state)
};
/*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/
unsigned x, y;
unsigned x;
unsigned round;
if (BB_BIG_ENDIAN) {
@@ -1045,22 +1283,62 @@ static void sha3_process_block72(uint64_t *state)
RhoPi_twice(20); RhoPi_twice(22);
#undef RhoPi_twice
}
/* Chi */
for (y = 0; y <= 20; y += 5) {
# if LONG_MAX > 0x7fffffff
for (x = 0; x <= 20; x += 5) {
uint64_t BC0, BC1, BC2, BC3, BC4;
BC0 = state[y + 0];
BC1 = state[y + 1];
BC2 = state[y + 2];
state[y + 0] = BC0 ^ ((~BC1) & BC2);
BC3 = state[y + 3];
state[y + 1] = BC1 ^ ((~BC2) & BC3);
BC4 = state[y + 4];
state[y + 2] = BC2 ^ ((~BC3) & BC4);
state[y + 3] = BC3 ^ ((~BC4) & BC0);
state[y + 4] = BC4 ^ ((~BC0) & BC1);
BC0 = state[x + 0];
BC1 = state[x + 1];
BC2 = state[x + 2];
state[x + 0] = BC0 ^ ((~BC1) & BC2);
BC3 = state[x + 3];
state[x + 1] = BC1 ^ ((~BC2) & BC3);
BC4 = state[x + 4];
state[x + 2] = BC2 ^ ((~BC3) & BC4);
state[x + 3] = BC3 ^ ((~BC4) & BC0);
state[x + 4] = BC4 ^ ((~BC0) & BC1);
}
# else
/* Reduced register pressure version
* for register-starved 32-bit arches
* (i386: -95 bytes, and it is _faster_)
*/
for (x = 0; x <= 40;) {
uint32_t BC0, BC1, BC2, BC3, BC4;
uint32_t *const s32 = (uint32_t*)state;
# if SHA3_SMALL
do_half:
# endif
BC0 = s32[x + 0*2];
BC1 = s32[x + 1*2];
BC2 = s32[x + 2*2];
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
BC3 = s32[x + 3*2];
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
BC4 = s32[x + 4*2];
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
x++;
# if SHA3_SMALL
if (x & 1)
goto do_half;
x += 8;
# else
BC0 = s32[x + 0*2];
BC1 = s32[x + 1*2];
BC2 = s32[x + 2*2];
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
BC3 = s32[x + 3*2];
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
BC4 = s32[x + 4*2];
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
x += 9;
# endif
}
# endif /* long is 32-bit */
/* Iota */
state[0] ^= IOTA_CONST[round]
| (uint32_t)((IOTA_CONST_bit31 << round) & 0x80000000)
@@ -1072,6 +1350,7 @@ static void sha3_process_block72(uint64_t *state)
state[x] = SWAP_LE64(state[x]);
}
}
#endif
}
void FAST_FUNC sha3_begin(sha3_ctx_t *ctx)
+26 -10
View File
@@ -11,14 +11,23 @@
#include "libbb.h"
typedef struct ino_dev_hash_bucket_struct {
struct ino_dev_hash_bucket_struct *next;
ino_t ino;
dev_t dev;
/*
* Above fields can be 64-bit, while pointer may be 32-bit.
* Putting "next" field here may reduce size of this struct:
*/
struct ino_dev_hash_bucket_struct *next;
/*
* Reportedly, on cramfs a file and a dir can have same ino.
* Need to also remember "file/dir" bit:
*/
char isdir; /* bool */
char name[1];
} ino_dev_hashtable_bucket_t;
#define HASH_SIZE 311 /* Should be prime */
#define hash_inode(i) ((i) % HASH_SIZE)
#define HASH_SIZE 311u /* Should be prime */
#define hash_inode(i) ((unsigned)(i) % HASH_SIZE)
/* array of [HASH_SIZE] elements */
static ino_dev_hashtable_bucket_t **ino_dev_hashtable;
@@ -38,6 +47,7 @@ char* FAST_FUNC is_in_ino_dev_hashtable(const struct stat *statbuf)
while (bucket != NULL) {
if ((bucket->ino == statbuf->st_ino)
&& (bucket->dev == statbuf->st_dev)
&& (bucket->isdir == !!S_ISDIR(statbuf->st_mode))
) {
return bucket->name;
}
@@ -52,17 +62,18 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *
int i;
ino_dev_hashtable_bucket_t *bucket;
i = hash_inode(statbuf->st_ino);
if (!name)
name = "";
bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name));
bucket->ino = statbuf->st_ino;
bucket->dev = statbuf->st_dev;
bucket->isdir = !!S_ISDIR(statbuf->st_mode);
strcpy(bucket->name, name);
if (!ino_dev_hashtable)
ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable));
i = hash_inode(statbuf->st_ino);
bucket->next = ino_dev_hashtable[i];
ino_dev_hashtable[i] = bucket;
}
@@ -72,13 +83,18 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *
void FAST_FUNC reset_ino_dev_hashtable(void)
{
int i;
ino_dev_hashtable_bucket_t *bucket;
ino_dev_hashtable_bucket_t *bucket, *next;
for (i = 0; ino_dev_hashtable && i < HASH_SIZE; i++) {
while (ino_dev_hashtable[i] != NULL) {
bucket = ino_dev_hashtable[i]->next;
free(ino_dev_hashtable[i]);
ino_dev_hashtable[i] = bucket;
if (!ino_dev_hashtable)
return;
for (i = 0; i < HASH_SIZE; i++) {
bucket = ino_dev_hashtable[i];
while (bucket != NULL) {
next = bucket->next;
free(bucket);
bucket = next;
}
}
free(ino_dev_hashtable);
+9 -3
View File
@@ -1255,7 +1255,9 @@ line_input_t* FAST_FUNC new_line_input_t(int flags)
{
line_input_t *n = xzalloc(sizeof(*n));
n->flags = flags;
#if MAX_HISTORY > 0
n->max_history = MAX_HISTORY;
#endif
return n;
}
@@ -2254,9 +2256,13 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
INIT_S();
if (tcgetattr(STDIN_FILENO, &initial_settings) < 0
|| !(initial_settings.c_lflag & ECHO)
|| (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON
) {
/* Happens when e.g. stty -echo was run before */
/* Happens when e.g. stty -echo was run before.
* But if ICANON is not set, we don't come here.
* (example: interactive python ^Z-backgrounded,
* tty is still in "raw mode").
*/
parse_and_put_prompt(prompt);
/* fflush_all(); - done by parse_and_put_prompt */
if (fgets(command, maxsize, stdin) == NULL)
@@ -2605,7 +2611,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
* standard readline bindings (IOW: bash) do.
* Often, Alt-<key> generates ESC-<key>.
*/
ic = lineedit_read_key(read_key_buffer, timeout);
ic = lineedit_read_key(read_key_buffer, 50);
switch (ic) {
//case KEYCODE_LEFT: - bash doesn't do this
case 'b':
+24
View File
@@ -0,0 +1,24 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 2014 by Fugro Intersite B.V. <m.stam@fugro.nl>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
void FAST_FUNC bb_logenv_override(void)
{
const char* mode = getenv("LOGGING");
if (!mode)
return;
if (strcmp(mode, "none") == 0)
logmode = LOGMODE_NONE;
#if ENABLE_FEATURE_SYSLOG
else if (strcmp(mode, "syslog") == 0)
logmode = LOGMODE_SYSLOG;
#endif
}
+12 -6
View File
@@ -94,19 +94,19 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
/* Open the file. Barf if this doesn't work. */
mode = ro ? O_RDONLY : O_RDWR;
open_ffd:
ffd = open(file, mode);
if (ffd < 0) {
if (mode != O_RDONLY) {
mode = O_RDONLY;
ffd = open(file, mode);
goto open_ffd;
}
if (ffd < 0)
return -errno;
return -errno;
}
/* Find a loop device. */
try = *device ? *device : dev;
/* 1048575 is a max possible minor number in Linux circa 2010 */
/* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */
for (i = 0; rc && i < 1048576; i++) {
sprintf(dev, LOOP_FORMAT, i);
@@ -121,7 +121,7 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
goto try_to_open;
}
/* Ran out of block devices, return failure. */
rc = -ENOENT;
rc = -1;
break;
}
try_to_open:
@@ -131,8 +131,14 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
mode = O_RDONLY;
dfd = open(try, mode);
}
if (dfd < 0)
if (dfd < 0) {
if (errno == ENXIO) {
/* Happens if loop module is not loaded */
rc = -1;
break;
}
goto try_again;
}
rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo);
+4
View File
@@ -99,6 +99,10 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
if (!c) {
goto ret0;
}
} else {
if (flags & FILEUTILS_VERBOSE) {
printf("created directory: '%s'\n", path);
}
}
if (!c) {
+39 -1
View File
@@ -76,7 +76,7 @@ static int string_checker(const char *p1, const char *p2)
ret |= string_checker_helper(p, p2);
/* clean up */
memset(p, 0, size);
nuke_str(p);
free(p);
return ret;
@@ -182,3 +182,41 @@ int FAST_FUNC obscure(const char *old, const char *newval, const struct passwd *
}
return 0;
}
#if ENABLE_UNIT_TEST
/* Test obscure_msg() instead of obscure() in order not to print anything. */
static const struct passwd pw = {
.pw_name = (char *)"johndoe",
.pw_gecos = (char *)"John Doe",
};
BBUNIT_DEFINE_TEST(obscure_weak_pass)
{
/* Empty password */
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "", &pw));
/* Pure numbers */
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "23577315", &pw));
/* Similar to pw_name */
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "johndoe123%", &pw));
/* Similar to pw_gecos, reversed */
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "eoD nhoJ^44@", &pw));
/* Similar to the old password */
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "d4#21?'S", &pw));
/* adjacent letters */
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "qwerty123", &pw));
/* Many similar chars */
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "^33Daaaaaa1", &pw));
BBUNIT_ENDTEST;
}
BBUNIT_DEFINE_TEST(obscure_strong_pass)
{
BBUNIT_ASSERT_NULL(obscure_msg("Rt4##2&:'|", "}(^#rrSX3S*22", &pw));
BBUNIT_ENDTEST;
}
#endif /* ENABLE_UNIT_TEST */
+18
View File
@@ -17,6 +17,24 @@ char* FAST_FUNC strchrnul(const char *s, int c)
}
#endif
#ifndef HAVE_USLEEP
int FAST_FUNC usleep(unsigned usec)
{
struct timespec ts;
ts.tv_sec = usec / 1000000u;
ts.tv_nsec = (usec % 1000000u) * 1000u;
/*
* If a signal has non-default handler, nanosleep returns early.
* Our version of usleep doesn't return early
* if interrupted by such signals:
*
*/
while (nanosleep(&ts, &ts) != 0)
continue;
return 0;
}
#endif
#ifndef HAVE_VASPRINTF
int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
{
+8 -1
View File
@@ -142,7 +142,14 @@ char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
{
return xstrdup(crypt(clear, salt));
char *s;
s = crypt(clear, salt);
/*
* glibc used to return "" on malformed salts (for example, ""),
* but since 2.17 it returns NULL.
*/
return xstrdup(s ? s : "");
}
#endif
+8
View File
@@ -78,6 +78,10 @@ int FAST_FUNC remove_file(const char *path, int flags)
return -1;
}
if (flags & FILEUTILS_VERBOSE) {
printf("removed directory: '%s'\n", path);
}
return status;
}
@@ -98,5 +102,9 @@ int FAST_FUNC remove_file(const char *path, int flags)
return -1;
}
if (flags & FILEUTILS_VERBOSE) {
printf("removed '%s'\n", path);
}
return 0;
}
+45
View File
@@ -0,0 +1,45 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//kbuild:lib-y += replace.o
#include "libbb.h"
unsigned FAST_FUNC count_strstr(const char *str, const char *sub)
{
size_t sub_len = strlen(sub);
unsigned count = 0;
while ((str = strstr(str, sub)) != NULL) {
count++;
str += sub_len;
}
return count;
}
char* FAST_FUNC xmalloc_substitute_string(const char *src, int count, const char *sub, const char *repl)
{
char *buf, *dst, *end;
size_t sub_len = strlen(sub);
size_t repl_len = strlen(repl);
//dbg_msg("subst(s:'%s',count:%d,sub:'%s',repl:'%s'", src, count, sub, repl);
buf = dst = xmalloc(strlen(src) + count * ((int)repl_len - (int)sub_len) + 1);
/* we replace each sub with repl */
while ((end = strstr(src, sub)) != NULL) {
dst = mempcpy(dst, src, end - src);
dst = mempcpy(dst, repl, repl_len);
/*src = end + 1; - GNU findutils 4.5.10 doesn't do this... */
src = end + sub_len; /* but this. Try "xargs -Iaa echo aaa" */
}
strcpy(dst, src);
//dbg_msg("subst9:'%s'", buf);
return buf;
}
+42 -10
View File
@@ -33,23 +33,55 @@ int FAST_FUNC rtc_adjtime_is_utc(void)
return utc;
}
/* rtc opens are exclusive.
* Try to run two "hwclock -w" at the same time to see it.
* Users wouldn't expect that to fail merely because /dev/rtc
* was momentarily busy, let's try a bit harder on errno == EBUSY.
*/
static int open_loop_on_busy(const char *name, int flags)
{
int rtc;
/*
* Tested with two parallel "hwclock -w" loops.
* With try = 10, no failures with 2x1000000 loop iterations.
*/
int try = 1000 / 20;
again:
errno = 0;
rtc = open(name, flags);
if (errno == EBUSY) {
usleep(20 * 1000);
if (--try != 0)
goto again;
/* EBUSY. Last try, exit on error instead of returning -1 */
return xopen(name, flags);
}
return rtc;
}
/* Never fails */
int FAST_FUNC rtc_xopen(const char **default_rtc, int flags)
{
int rtc;
const char *name =
"/dev/rtc""\0"
"/dev/rtc0""\0"
"/dev/misc/rtc""\0";
if (!*default_rtc) {
*default_rtc = "/dev/rtc";
rtc = open(*default_rtc, flags);
if (!*default_rtc)
goto try_name;
name = ""; /*else: we have rtc name, don't try other names */
for (;;) {
rtc = open_loop_on_busy(*default_rtc, flags);
if (rtc >= 0)
return rtc;
*default_rtc = "/dev/rtc0";
rtc = open(*default_rtc, flags);
if (rtc >= 0)
return rtc;
*default_rtc = "/dev/misc/rtc";
if (!name[0])
return xopen(*default_rtc, flags);
try_name:
*default_rtc = name;
name += strlen(name) + 1;
}
return xopen(*default_rtc, flags);
}
void FAST_FUNC rtc_read_tm(struct tm *ptm, int fd)
+5
View File
@@ -10,7 +10,12 @@
#include "libbb.h"
struct speed_map {
#if defined __FreeBSD__
/* On FreeBSD, B<num> constants don't fit into a short */
unsigned speed;
#else
unsigned short speed;
#endif
unsigned short value;
};
Loaded 100 of 195 files, more files were not shown because too many files have changed in this diff. Show more