Compare commits

...
231 Commits
Author SHA1 Message Date
Denys Vlasenko db726ae0c6 Bump version to 1.33.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-11-24 14:27:03 +01:00
Denys Vlasenko bb61205290 hush: fix handling of "cmd && &"
function                                             old     new   delta
done_pipe                                            213     231     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 83a4967e50)
2021-11-23 05:31:30 +01:00
Denys Vlasenko 56a335378a hush: fix handling of \^C and "^C"
function                                             old     new   delta
parse_stream                                        2238    2252     +14
encode_string                                        243     256     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 27/0)               Total: 27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 1b7a9b68d0)
2021-11-23 05:31:30 +01:00
Denys Vlasenko 5b939a6d29 ash: parser: Fix VSLENGTH parsing with trailing garbage
Let's adopt Herbert Xu's patch, not waiting for it to reach dash git:
hush already has a similar fix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 53a7a9cd8c)
2021-11-23 05:31:30 +01:00
Denys Vlasenko d326be2850 unlzma: fix a case where we could read before beginning of buffer
Testcase:

  21 01 01 00 00 00 00 00 e7 01 01 01 ef 00 df b6
  00 17 02 10 11 0f ff 00 16 00 00

Unfortunately, the bug is not reliably causing a segfault,
the behavior depends on what's in memory before the buffer.

function                                             old     new   delta
unpack_lzma_stream                                  2762    2768      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 04f052c56d)
2021-11-23 05:31:30 +01:00
Denys Vlasenko bcc5b0e6ca Bump version to 1.33.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-05-03 20:07:13 +02:00
Denys Vlasenko 611bbfc148 ash: fix ${unset_var/pattern/repl}
function                                             old     new   delta
subevalvar                                          1349    1353      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-05-03 20:06:49 +02:00
Samuel Sapalski 23dd1c75b7 decompress_gunzip: Fix DoS if gzip is corrupt
On certain corrupt gzip files, huft_build will set the error bit on
the result pointer. If afterwards abort_unzip is called huft_free
might run into a segmentation fault or an invalid pointer to
free(p).

In order to mitigate this, we check in huft_free if the error bit
is set and clear it before the linked list is freed.

Signed-off-by: Samuel Sapalski <samuel.sapalski@nokia.com>
Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-05-03 14:50:09 +02:00
Denys Vlasenko 89358a7131 traceroute: fix option parsing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-09 00:28:26 +01:00
Bernd Kuhls 39b71881b8 update_passwd: fix context variable
Commit
https://git.busybox.net/busybox/commit/libbb/update_passwd.c?id=2496616b0a8d1c80cd1416b73a4847b59b9f969a

changed the variable used from context to seuser but forgot this
change resulting in build errors detected by buildroot autobuilders:

http://autobuild.buildroot.net/results/b89/b89b7d0f0601bb706e76cea31cf4e43326e5540c//build-end.log

libbb/update_passwd.c:51:11: error: 'context' undeclared (first use in
 this function); did you mean 'ucontext'?
   freecon(context);

Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-09 00:28:26 +01:00
Denys Vlasenko 67cc582d42 ash: make a strdup copy of $HISTFILE for line editing
Otherwise if $HISTFILE is unset or reassigned, bad things can happen.

function                                             old     new   delta
ash_main                                            1210    1218      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-09 00:28:26 +01:00
Maxim Storchak ee1e0987e4 httpd: fix offset for sendfile
If the Range: header is not present it the request,
the offset passed to sendfile is wrong,
and httpd falls back to the read-write loop.

function                                             old     new   delta
send_file_and_exit                                   857     865      +8
handle_incoming_and_exit                            2239    2230      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 8/-9)               Total: -1 bytes

Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-03-09 00:28:26 +01:00
Denys Vlasenko a4c3a34139 Bump version to 1.33.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-29 17:42:59 +01:00
Denys Vlasenko ec9a5e6083 libiproute: band-aid for old uclibc missing IFA_FLAGS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-29 17:34:34 +01:00
Denys Vlasenko fecb1693cc modprobe-small: convert to new recursive_action() API
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-29 17:02:06 +01:00
Denys Vlasenko 40f9fe2160 bc: placate gcc (it thinks 's' can be uninitialized here)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-29 17:02:06 +01:00
Denys Vlasenko 77a51a2709 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-29 16:53:11 +01:00
Denys Vlasenko c7ef818768 hush: make comment more clear
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-27 16:04:54 +01:00
Denys Vlasenko 1462673dde man: implement SECTION parameters
function                                             old     new   delta
man_main                                             807     942    +135
is_section_name                                        -      52     +52
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 187/0)             Total: 187 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-27 16:02:37 +01:00
Denys Vlasenko cad20ced86 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 19:08:16 +01:00
Denys Vlasenko 1237d627e9 hush: fix this case: echo "SCRIPT" | hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 19:01:49 +01:00
Denys Vlasenko 46a71dc30c hush: if !EDITING, do not regenerate prompt for every input char
function                                             old     new   delta
fgetc_interactive                                    261     258      -3
pseudo_exec_argv                                     406     399      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10)             Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 18:49:29 +01:00
Lauri Kasanen 6cfec7dd02 mount: Surround syslog.h with the config check
This lets bb mount build for limited targets without syslog.h,
as long as the parts using it like NFS are disabled.

Signed-off-by: Lauri Kasanen <cand@gmx.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 18:15:37 +01:00
Denys Vlasenko 51a471d05d ash: change "clear ungetc counter on syntax errors" fix to match dash
function                                             old     new   delta
ash_main                                            1203    1210      +7
raise_exception                                       39      26     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-13)              Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-24 00:22:24 +01:00
Denys Vlasenko 521220ed1a hush: fix ^C in INTERACTIVE, !EDITING config
function                                             old     new   delta
refill_HFILE_and_getc                                 88     170     +82
fgetc_interactive                                    226     250     +24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 106/0)             Total: 106 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 23:44:55 +01:00
Denys Vlasenko 18bcaf374c hush: revert "make interactive ^C break out of PS2 mode"
It made ^C break out of the entire shell, if we aren't in PS2 mode.
Need a better idea.

function                                             old     new   delta
expand_one_var                                      2344    2353      +9
syntax_error_unterm_ch                                21      29      +8
parse_dollar                                         817     824      +7
parse_stream                                        2251    2238     -13
fgetc_interactive                                    249     227     -22
syntax_error_unterm_str                               26       -     -26
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/2 up/down: 24/-61)            Total: -37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 23:01:18 +01:00
Denys Vlasenko 649acb9e23 hush: fix PS1 prompth in !EDITING config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 15:29:13 +01:00
Denys Vlasenko a7b52d26c4 hush: fix fallout from tweaking ${var:START:LEN} code
function                                             old     new   delta
expand_one_var                                      2344    2353      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 12:38:03 +01:00
Denys Vlasenko 93e2a22482 shell: for signal exitcode, use 128 | sig, not 128 + sig - MIPS has signal 128
function                                             old     new   delta
wait_for_child_or_signal                             213     214      +1
refill_HFILE_and_getc                                 89      88      -1
getstatus                                             97      96      -1
builtin_wait                                         339     337      -2
checkjobs                                            187     183      -4
process_wait_result                                  450     444      -6
waitcmd                                              290     281      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 1/-23)             Total: -22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 12:23:21 +01:00
Denys Vlasenko 0ab2dd4f28 hush: fix comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 02:22:08 +01:00
Denys Vlasenko 6297d66eda factor: fix comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23 02:03:04 +01:00
Denys Vlasenko 6452c30036 factor: detect squares
If we have a square, the speedup can be extremely large
(in best case example below, it's ~40000 times faster):

$ time ./busybox_old factor 18446743988964486098
18446743988964486098: 2 3037000493 3037000493
real	0m4.246s
$ time ./busybox factor 18446743988964486098
18446743988964486098: 2 3037000493 3037000493
real	0m0.000s

function                                             old     new   delta
isqrt_odd                                              -      57     +57
print_w                                                -      36     +36
factorize                                            218     236     +18
print_h                                                -       7      +7
factorize_numstr                                      65      72      +7
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/0 up/down: 125/0)             Total: 125 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-22 20:24:30 +01:00
Denys Vlasenko 96717d9fb4 lineedit: code shrink
function                                             old     new   delta
read_line_input                                     3171    3157     -14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 22:50:23 +01:00
Denys Vlasenko fae7332ebf lineedit: add a comment about possible use of tcflush()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 21:55:03 +01:00
Denys Vlasenko 00eb23b47a bc: do not allocate line editing state until needed
function                                             old     new   delta
xc_read_line                                         324     353     +29
free_line_input_t                                     34      39      +5
xc_vm_init                                           656     640     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-16)             Total: 18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 21:36:58 +01:00
Andy Shevchenko e4202df091 modprobe: Add support for modprobe.blacklist=module1,module2,...
function                                             old     new   delta
parse_and_add_kcmdline_module_options                  -     186    +186
modprobe_main                                        713     798     +85
do_modprobe                                          648     451    -197
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 271/-197)           Total: 74 bytes

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 21:15:35 +01:00
Denys Vlasenko 07abc7c6f7 hush: deal with FIXMEs for corner cases in parameter expansion
function                                             old     new   delta
expand_one_var                                      2323    2344     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 10:14:18 +01:00
Denys Vlasenko 901d2c3862 factor: fix typo in undef
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 07:45:08 +01:00
Denys Vlasenko 3e544d6ec7 factor: code shrink
function                                             old     new   delta
factor_main                                          176     171      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 07:22:55 +01:00
Denys Vlasenko f079f91371 factor: 30% faster trial division (better sieve)
function                                             old     new   delta
packed_wheel                                           -     192    +192
factor_main                                          108     176     +68
factorize                                            284     218     -66
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 260/-66)           Total: 194 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-20 21:37:29 +01:00
Denys Vlasenko bb4e32befa hush: remove one redundant getpid() on every startup
function                                             old     new   delta
hush_main                                           1151    1147      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-20 16:36:00 +01:00
Denys Vlasenko c8f6c1d775 ping6: add -w/-W NUM to --help
function                                             old     new   delta
packed_usage                                       33515   33533     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-20 11:25:50 +01:00
Denys Vlasenko bc2c1b4f86 ping: fix -wN to not think that one packet is always lost
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-20 11:16:32 +01:00
Denys Vlasenko 2124c0ec97 ash: clear ungetc counter on syntax errors
function                                             old     new   delta
raise_exception                                       26      39     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-19 14:33:02 +01:00
Denys Vlasenko 4152b41183 tftp: fix --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-19 00:33:06 +01:00
Denys Vlasenko ddc6dfdb4d route: code shrink
function                                             old     new   delta
kw_lookup                                             84      86      +2
tbl_hash_net_host                                     15      14      -1
tbl_verb                                              21      19      -2
tbl_ipvx                                             104      92     -12
packed_usage                                       33527   33493     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 2/-49)             Total: -47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-19 00:07:13 +01:00
Denys Vlasenko b164cdb854 help text tweaks, mainly expanding one for route
function                                             old     new   delta
packed_usage                                       33485   33527     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-18 23:33:19 +01:00
Denys Vlasenko 8cc3a744fb help text: use -P PORT form
function                                             old     new   delta
packed_usage                                       33502   33491     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-18 22:51:46 +01:00
Denys Vlasenko a2f18d950a help text tweaks
function                                             old     new   delta
packed_usage                                       33570   33502     -68

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-18 04:12:51 +01:00
Denys Vlasenko 15733cb48e mount: if we race with other loop mount, we forget to close loop dev
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 23:38:06 +01:00
Denys Vlasenko 251e08ffa6 move ADJTIME_PATH define to header files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 20:53:43 +01:00
Denys Vlasenko a4c5cb2335 traceroute: fix --help text
function                                             old     new   delta
traceroute_init                                     1151    1153      +2
packed_usage                                       33568   33570      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 4/0)                 Total: 4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 18:17:03 +01:00
Denys Vlasenko ff4ca18501 traceroute: avoid collecting target local address if !VERBOSE
function                                             old     new   delta
common_traceroute_main                              1542    1537      -5
traceroute_init                                     1151    1101     -50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-55)             Total: -55 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 17:47:49 +01:00
Denys Vlasenko 4bc59a4cf7 mount: fix a race when a free loop device is snatched under us by another mount.
function                                             old     new   delta
set_loop                                             850     809     -41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 15:05:14 +01:00
Denys Vlasenko cd48f07117 mail: launch_helper(): flush stdio before vfork, set G.helper_pid only in parent
function                                             old     new   delta
launch_helper                                        188     193      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 12:55:22 +01:00
Denys Vlasenko b0e7cb4c3f mail: deobfuscate launch_helper()
13 bytes are not worth the risk of doing something iffy after vfork().
Let's have much clearer code there.

function                                             old     new   delta
launch_helper                                        175     188     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 12:51:58 +01:00
Denys Vlasenko b6237c0657 mail: commonalize send_r_n()
function                                             old     new   delta
send_mail_command                                     85      55     -30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 12:34:25 +01:00
Denys Vlasenko 25b2680056 mail: move "opts" from globals
function                                             old     new   delta
popmaildir_main                                      812     823     +11
sendmail_main                                       1295    1301      +6
makemime_main                                        291     288      -3
parse                                                970     966      -4
reformime_main                                       107     100      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 17/-14)              Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 12:24:50 +01:00
Denys Vlasenko 91e330a53f shells: a fix for systems without RLIMIT_NICE
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 12:07:54 +01:00
Denys Vlasenko 0723131628 Fixes for Hurd build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-17 11:22:44 +01:00
Denys Vlasenko bb15969333 libbb: do not compile selinux_or_die() if !SELINUX
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 23:00:51 +01:00
Denys Vlasenko 39646dce32 build system: make -static-libgcc selectable in config
OpenWrt wants this off.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 21:36:36 +01:00
Denys Vlasenko d3c36882dc hwclock: improve --help (-l is a compatible shortcut for --localtime)
function                                             old     new   delta
packed_usage                                       33605   33568     -37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 20:55:30 +01:00
Denys Vlasenko 9e262f13c2 hwclock: fix musl breakage of settimeofday(tz)
function                                             old     new   delta
set_kernel_timezone_and_clock                          -     119    +119
set_kernel_tz                                          -      28     +28
hwclock_main                                         480     301    -179
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/1 up/down: 147/-179)          Total: -32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 14:00:47 +01:00
Denys Vlasenko a97a795dcb lineedit: disable completion and fancy prompts if no shells are selected
function                                             old     new   delta
get_previous_history                                  51      56      +5
get_next_history                                      47      52      +5
null_str                                               1       -      -1
beep                                                  10       -     -10
bb_msg_unknown                                        10       -     -10
bb_internal_setpwent                                  24       -     -24
remove_chunk                                          30       -     -30
goto_new_line                                         33       -     -33
bb_internal_endpwent                                  36       -     -36
deinit_S                                              51       -     -51
free_tab_completion_data                              54       -     -54
read_line_input                                     3171    3114     -57
rewind                                                68       -     -68
add_match                                             70       -     -70
complete_username                                     77       -     -77
quote_special_chars                                   78       -     -78
build_match_prefix                                   557       -    -557
complete_cmd_dir_file                                697       -    -697
parse_and_put_prompt                                 823      53    -770
input_tab                                            926       -    -926
------------------------------------------------------------------------------
(add/remove: 0/17 grow/shrink: 2/2 up/down: 10/-3549)       Total: -3539 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 11:14:08 +01:00
Denys Vlasenko 1d180cd749 lineedit: use strncmp instead of is_prefixed_with (we know the length)
Also: add comments, rename some variables

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 11:00:20 +01:00
Denys Vlasenko eaced1ec85 lineedit: remove ->path_lookup if ash is not configured
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 10:01:21 +01:00
Ron Yorston 8baa643a34 lineedit: match local directories when searching PATH
When tab-completing a command we search PATH if the partial text
doesn't include a slash.  Also match subdirectories of the current
directory, in case the user intends to run a binary from one of
them.

function                                             old     new   delta
complete_cmd_dir_file                                894     917     +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 23/0)               Total: 23 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 09:38:25 +01:00
Ron Yorston 8506dd6730 lineedit: omit directories when tab-completing from PATH
Only files should be matched when using PATH for tab-completion.

function                                             old     new   delta
complete_cmd_dir_file                                883     894     +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 09:38:18 +01:00
Denys Vlasenko caba1a16ec tweak help texts
function                                             old     new   delta
packed_usage                                       33650   33605     -45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-16 01:19:08 +01:00
Denys Vlasenko 9b44deac01 ntpd: allow non-root to run it (e.g. with -w option)
This is safe: it's not a setuid applet, the attempt to set time
will simply fail if attempted by non-root

From openwrt 600-allow-ntpd-non-root.patch

function                                             old     new   delta
ntp_init                                            1049    1005     -44

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 23:23:44 +01:00
Denys Vlasenko 73d93d9f83 libbb: make pw_encrypt() die if supplied salt is bad (e.g. emply)
Fished from 520-loginutils-handle-crypt-failures.patch in openwrt

function                                             old     new   delta
pw_encrypt                                           913     927     +14
des_crypt                                           1327    1318      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9)               Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 23:19:22 +01:00
Denys Vlasenko f3d6711c97 udhcpc6: code shrink - sending functions do not need ifindex parameter
function                                             old     new   delta
d6_send_raw_packet_from_client_data_ifindex            -     427    +427
d6_send_kernel_packet_from_client_data_ifindex         -     275    +275
send_d6_renew                                        182     176      -6
perform_d6_release                                   246     240      -6
d6_mcast_from_client_data_ifindex                     45      39      -6
d6_send_kernel_packet                                274       -    -274
d6_send_raw_packet                                   429       -    -429
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/3 up/down: 702/-721)          Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 21:55:15 +01:00
Michal Kazior b817699e6c udhcp: bind to device even for ucast packets
There are cases where binding to source IP and
destination IP is insufficient to guarantee sane
xmit netdev.

One case where this can fail is when
route-matching netdev carrier is down (cable
unplugged, wifi disconnected), or the netdev is
admin down. Then all the IP based bindings (bind()
+ connect()) will seemingly succeed but the actual
packet can go out through a default gw path.

Depending on the network this happens on
it can create issues or false alarms. It can
also leak some subnet info across networks that
shouldn't be routed.

As such better be safe than sorry and bind to a
netdev to be sure it's used for xmit.

function                                             old     new   delta
udhcp_send_kernel_packet                             293     336     +43
send_packet                                          182     188      +6
bcast_or_ucast                                        37      43      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 55/0)               Total: 55 bytes

Signed-off-by: Michal Kazior <michal@plume.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 21:44:21 +01:00
Denys Vlasenko 01004f9796 libbb: enable fixed 4k pagesize for 32bit ARM
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 21:24:04 +01:00
Denys Vlasenko 4a9ec95565 tls: code shrink in AES code
function                                             old     new   delta
aes_cbc_decrypt                                      862     847     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 18:47:25 +01:00
Denys Vlasenko fad8d6b6c0 build system: combat gcc zealotry in data alignment, now for x86_64 too
function                                             old     new   delta
.rodata                                           182928  182620    -308

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-15 18:39:05 +01:00
Denys Vlasenko 2aaacc1453 dd: support for O_DIRECT i/o
Based on patch by Akash Hadke <hadkeakash4@gmail.com>

function                                             old     new   delta
dd_read                                                -      66     +66
clear_O_DIRECT                                         -      55     +55
write_and_stats                                      102     135     +33
dd_main                                             1578    1601     +23
static.oflag_words                                    19      26      +7
static.iflag_words                                    22      29      +7
packed_usage                                       33665   33668      +3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/0 up/down: 194/0)             Total: 194 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 20:27:57 +01:00
Denys Vlasenko c7b858ff8d libbb: add and use infrastructure for fixed page size optimization
function                                             old     new   delta
procps_scan                                         1121    1118      -3
getpagesize                                            6       -      -6
rpm_main                                            1037    1027     -10
rpm2cpio_main                                        120     110     -10
ptok                                                  38      21     -17
time_main                                           1282    1261     -21
mkswap_main                                          317     278     -39
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/6 up/down: 0/-106)           Total: -106 bytes

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 18:25:28 +01:00
Denys Vlasenko db793480cb build system: combat gcc zealotry in data alignment
text	   data	    bss	    dec	    hex	filename
1020934	    559	   5052	1026545	  fa9f1	busybox_old
1020750	    559	   5052	1026361	  fa939	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 05:53:45 +01:00
Denys Vlasenko a8e19608fc hush: code shrink
function                                             old     new   delta
run_applet_main                                        -      20     +20
builtin_kill                                         296     288      -8
builtin_test                                          19      10      -9
builtin_printf                                        19      10      -9
builtin_echo                                          19      10      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 20/-35)            Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-14 03:52:54 +01:00
Denys Vlasenko 84d5eddb25 help text: replace [OPTIONS] with actual options (if not too long)
function                                             old     new   delta
packed_usage                                       33620   33665     +45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 22:34:05 +01:00
Denys Vlasenko 63139b531f hush: if login shell, also source ~/.profile
function                                             old     new   delta
hush_main                                           1101    1151     +50

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 22:00:56 +01:00
Denys Vlasenko 1b367cbeda examples: remove /sbin/ prefixes, system should be configured with $PATH to find utilities
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 21:35:26 +01:00
Denys Vlasenko 5d553bc558 more --help text tweaks
function                                             old     new   delta
packed_usage                                       33545   33581     +36

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 19:18:28 +01:00
Denys Vlasenko 11f1a2553e help text tweaks
function                                             old     new   delta
packed_usage                                       33547   33545      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 19:04:19 +01:00
Denys Vlasenko 49142d48bd hush: NOMMU fix for hush-psubst/tick6.tests
function                                             old     new   delta
hush_main                                           1759    1766      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 18:44:07 +01:00
Denys Vlasenko 9cabd17e55 hush: fix -c SCRIPT handling
function                                             old     new   delta
hush_main                                           1763    1759      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 18:24:11 +01:00
Denys Vlasenko 31df5a3eee ash: reset SIGHUP earlier: allows HUP traps in .profile, closes 13371
function                                             old     new   delta
ash_main                                            1188    1203     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 16:36:28 +01:00
Denys Vlasenko 6c5f4296dc traceroute: code shrink
function                                             old     new   delta
hexdump_if_verbose                                     -     255    +255
common_traceroute_main                              1668    1644     -24
hexdump                                              239       -    -239
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 255/-263)           Total: -8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 15:58:47 +01:00
Denys Vlasenko 623e55a396 traceroute: even with -v, don't show other ping processes reply's
function                                             old     new   delta
traceroute_init                                     1135    1151     +16
common_ping_main                                    1919    1935     +16
common_traceroute_main                              1715    1668     -47
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 32/-47)            Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 15:53:06 +01:00
Denys Vlasenko d067acb005 traceroute: simpler hexdump()
function                                             old     new   delta
hexdump                                              270     239     -31

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 15:10:07 +01:00
Denys Vlasenko b4b1828076 traceroute: make "ipv4 or ipv6?" cheaper to find out
function                                             old     new   delta
traceroute_init                                     1131    1135      +4
hexdump                                              274     270      -4
common_traceroute_main                              1730    1715     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 4/-19)             Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 14:58:11 +01:00
Denys Vlasenko 8055173128 traceroute: don't set SO_DONTROUTE on recv socket, it only affects send
function                                             old     new   delta
traceroute_init                                     1147    1131     -16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-13 14:18:05 +01:00
Denys Vlasenko 724c7df683 traceroute: untangle main loop
function                                             old     new   delta
common_traceroute_main                              1785    1730     -55

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 21:44:32 +01:00
Denys Vlasenko e76f03b267 traceroute: commonalize verbose printing
function                                             old     new   delta
hexdump                                                -     274    +274
traceroute_init                                     1172    1147     -25
pr_type                                               79       -     -79
common_traceroute_main                              2091    1785    -306
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 274/-410)         Total: -136 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 21:09:21 +01:00
Denys Vlasenko df5c5394b0 traceroute: set IP_PKTINFO to see correct local IP of received pkt (fixes -v display)
Also, assorted code shrink:

function                                             old     new   delta
traceroute_init                                     1210    1172     -38
common_traceroute_main                              2141    2091     -50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-88)             Total: -88 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 20:09:52 +01:00
Denys Vlasenko cc55bbef75 traceroute: code shrink
Move init code to a separate function.

function                                             old     new   delta
traceroute_init                                        -    1203   +1203
common_traceroute_main                              3391    2141   -1250
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 1203/-1250)        Total: -47 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 18:09:45 +01:00
Denys Vlasenko 70726640b3 traceroute: code shrink
Do not pass "from" and "to" addresses as parameters, keep them in globals

function                                             old     new   delta
common_traceroute_main                              3426    3391     -35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 18:09:45 +01:00
Denys Vlasenko d0dea17900 traceroute: code shrink
Do not byteswap ident (why we were doing it?)

function                                             old     new   delta
common_traceroute_main                              3544    3426    -118

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 18:09:45 +01:00
Denys Vlasenko 3978adc445 traceroute: fix traceroute6 -I (icmp mode)
function                                             old     new   delta
common_traceroute_main                              3530    3544     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 18:09:45 +01:00
Denys Vlasenko ef2366cdca nsenter: stop option parsing on 1st non-option
"nsenter ls -l" gives: invalid option -- 'l'

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-12 08:44:32 +01:00
Denys Vlasenko 030fe31760 libbb: make msleep() result in only one syscall instead of looping
function                                             old     new   delta
msleep                                                45      52      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-11 16:48:47 +01:00
Denys Vlasenko 56ee576507 mount: fix incorrect "success" exitcode if loop device setup fails
When mounting, in parallel, multiple loop devices (squashfs for the
submitter's case), the following behavior can be observed:

stat64(/path/to/image, {st_mode=S_IFREG|0644, st_size=4096, ...}) = 0
openat(AT_FDCWD, /path/to/image, O_RDWR|O_LARGEFILE) = 3
openat(AT_FDCWD, /dev/loop-control, O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
ioctl(4, LOOP_CTL_GET_FREE)             = 12
close(4)                                = 0
openat(AT_FDCWD, /dev/loop12, O_RDWR|O_LARGEFILE) = 4
ioctl(4, LOOP_GET_STATUS64, {lo_offset=0, lo_number=12, lo_flags=LO_FLAGS_AUTOCLEAR, lo_file_name=/path/to/image, ...}) = 0
close(4)                                = 0
close(3)                                = 0
write(2, "mount: can't setup loop device\n", 31mount: can't setup loop device
) = 31
exit_group(0)                           = ?
+++ exited with 0 +++

The ioctl LOOP_CTL_GET_FREE has resulted in the same result for
a competing mount process. The subsequent ioctl LOOP_GET_STATUS64
fails, having succeeded for the competing mount process.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-09 20:56:43 +01:00
Denys Vlasenko e7d853b4eb wget: do not ftruncate if -O- is used, closes 13351
function                                             old     new   delta
wget_main                                           2558    2571     +13
retrieve_file_data                                   612     621      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0)               Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-08 19:06:28 +01:00
Xabier Oneca abaee4aada mkdtemp: proper error detection on mktemp
On error, mktemp returns an empty string, not NULL.

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-08 18:46:32 +01:00
Denys Vlasenko c9b93cf290 tar: expand --help
function                                             old     new   delta
packed_usage                                       33486   33590    +104

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-08 16:46:41 +01:00
Denys Vlasenko 34c5115a7f mount: implement -o nosymfollow, remove bogus -o union
The (1 << 8) MS_ flag is MS_NOSYMFOLLOW, not MS_UNION.
As far as I see in git history of kernel and util-linux,
MS_UNION did not ever exist.
Why did it appear in our tree in 2009?...

function                                             old     new   delta
mount_option_str                                     379     385      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-06 21:56:22 +01:00
Denys Vlasenko 696c38ddca mount: add -o nostrictatime and -o [no]lazytime
function                                             old     new   delta
mount_option_str                                     345     379     +34
mount_options                                        176     188     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 46/0)               Total: 46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-06 20:59:41 +01:00
Denys Vlasenko b1eedfcfa1 mount: do not guess mount as NFS if "hostname:" contains slashes
function                                             old     new   delta
singlemount                                         1273    1295     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-05 14:14:11 +01:00
Denys Vlasenko 758c2bd58e awk: add a test that $NF is empty
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-04 19:00:06 +01:00
Denys Vlasenko f4f6e5144b libbb: exec_login_shell() - new function
function                                             old     new   delta
exec_login_shell                                       -      12     +12
sulogin_main                                         247     240      -7
login_main                                           960     953      -7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 12/-14)             Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 21:51:08 +01:00
Denys Vlasenko 0622416fec libbb: code shrink in exec_shell()
function                                             old     new   delta
exec_shell                                           129     120      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 21:39:57 +01:00
Denys Vlasenko 2075aa93e0 libbb: rename run_shell() to exec_shell()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 21:28:47 +01:00
Denys Vlasenko b4f93f562d mount: do not guess bind mounts as nfs
Fails as follows:

$ mount -o bind /dev/disk/by-path/pci-0000:13:00.0-scsi-0:0:3:0 /dir
mount: bad address '/dev/disk/by-path/pci-0000'

function                                             old     new   delta
singlemount                                         1256    1273     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 19:10:22 +01:00
Denys Vlasenko 665a659530 awk: FS regex matches only non-empty separators (gawk compat)
function                                             old     new   delta
awk_split                                            484     553     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 19:07:31 +01:00
Denys Vlasenko 50ead33c45 login: log to syslog every bad password, not only 3rd
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 17:47:16 +01:00
Denys Vlasenko 6599e380ed mount: make filesystems[] array byte-aligned
text	   data	    bss	    dec	    hex	filename
1021120	    559	   5052	1026731	  faaab	busybox_old
1021092	    559	   5052	1026703	  faa8f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 15:10:43 +01:00
Denys Vlasenko 6cc4962b60 decrease padding: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nilly
text	   data	    bss	    dec	    hex	filename
1021236	    559	   5052	1026847	  fab1f	busybox_old
1021120	    559	   5052	1026731	  faaab	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 14:58:02 +01:00
Denys Vlasenko 965b795b87 decrease paddign: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nilly
text	   data	    bss	    dec	    hex	filename
1021988	    559	   5052	1027599	  fae0f	busybox_old
1021236	    559	   5052	1026847	  fab1f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 13:03:03 +01:00
Denys Vlasenko 2fba2f5bb9 unicode: relax array alignment for tables
text	   data	    bss	    dec	    hex	filename
1022075	    559	   5052	1027686	  fae66	busybox_old
1021988	    559	   5052	1027599	  fae0f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 11:30:17 +01:00
Denys Vlasenko 33e955ab91 unicode: fix handling of short 1-4 char tables
function                                             old     new   delta
in_uint16_table                                       92     107     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-30 11:18:00 +01:00
Denys Vlasenko eb773054e4 libbb: code shrink
function                                             old     new   delta
generate_uuid                                        124     103     -21

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-29 12:40:25 +01:00
Denys Vlasenko b86a9ed699 use write_str() functions where appropriate
function                                             old     new   delta
chat_main                                           1300    1295      -5
finalize_tty_attrs                                    80      70     -10
getty_main                                          1538    1519     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-34)             Total: -34 bytes

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

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-29 11:32:48 +01:00
Denys Vlasenko 32a8f70ac1 libbb: in @SECONDS date format, use 64-bit time if libc allows
function                                             old     new   delta
packed_usage                                       33472   33486     +14
parse_datestr                                        919     916      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 23:21:13 +01:00
Denys Vlasenko 4dee016059 date: tweak --help: -D FMT is used for -s TIME as well
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 23:04:09 +01:00
Denys Vlasenko 56a5731a1a date: remove non-standard special-casing of date '+%f'
git log did not reveal why it is there.

function                                             old     new   delta
date_main                                           1016     995     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 22:07:00 +01:00
Denys Vlasenko f26c5660c2 date: trim --help (no need to show long opts)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 22:01:15 +01:00
Denys Vlasenko 900eae1738 date: support -Ins, more compatible timezone display in -I
function                                             old     new   delta
date_main                                            941    1016     +75
static.isoformats                                     28      31      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 78/0)               Total: 78 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 21:44:58 +01:00
Denys Vlasenko ab6991c6f5 date: for -uR and -uIh, timezone still have to be shown at +hhmm, not as abbreviation
function                                             old     new   delta
date_main                                            963     941     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 20:58:42 +01:00
Denys Vlasenko 818a4aa2ef fix comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 14:22:52 +01:00
Denys Vlasenko ae04ce82cf base32/64: "truncated base64 input" -> "truncated input"
text	   data	    bss	    dec	    hex	filename
1021739	    559	   5052	1027350	  fad16	busybox_old
1021732	    559	   5052	1027343	  fad0f	busybox_unstripped

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 13:27:36 +01:00
Denys Vlasenko fc6faac84e libbb: trim base32/64 tables
function                                             old     new   delta
bb_uuenc_tbl_base64                                   66      65      -1
bb_uuenc_tbl_base32                                   34      32      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 12:48:34 +01:00
Denys Vlasenko f140b49f5f base32/64: code shrink
function                                             old     new   delta
decode_base64                                        178     173      -5
decode_base32                                        217     186     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-36)             Total: -36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 12:33:50 +01:00
Denys Vlasenko 7467e905e5 base32/64: code shrink
function                                             old     new   delta
decode_base64                                        180     178      -2
decode_base32                                        224     217      -7
read_base64                                          236     222     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-23)             Total: -23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-28 09:50:14 +01:00
Denys Vlasenko 2cd37d65e2 libbb: faster and smaller decode_base32()
function                                             old     new   delta
decode_base32                                        275     224     -51

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-27 21:25:34 +01:00
Denys Vlasenko 170b8628fa libbb: smaller and faster decode_base64()
function                                             old     new   delta
decode_base64                                        195     180     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-27 20:45:15 +01:00
Denys Vlasenko dc68a5ddac sha3sum: fix --help: -a does not depend on FEATURE_MD5_SHA1_SUM_CHECK
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-27 15:55:46 +01:00
Denys Vlasenko cdab3c4fac base32/64: decode in-place
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-27 15:39:23 +01:00
Denys Vlasenko c8b3d9a145 base32/64: implement -w COL
function                                             old     new   delta
baseNUM_main                                         568     655     +87
packed_usage                                       33478   33533     +55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 142/0)             Total: 142 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-27 15:25:31 +01:00
Denys Vlasenko fc63549352 free: code shrink
function                                             old     new   delta
free_main                                            664     657      -7

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-26 09:04:16 +01:00
Denys Vlasenko 03eb6eba43 mdev: clear LOGMODE_STDIO only directly before daemonizing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 16:35:56 +01:00
Denys Vlasenko cb143b9793 uevent: make it survive ENOBUFS
function                                             old     new   delta
uevent_main                                          285     337     +52

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 16:22:16 +01:00
Denys Vlasenko 1c9cd9b71b mdev: clean up
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 14:43:35 +01:00
Jan Klötzke 768153bf8c mdev: add -v to increase log verbosity
If logging to stderr and/or syslog the -v option can be given one or
more times to increase the log verbosity. If mdev is used as hotplug
helper the log level is fixed set to 2 if mdev.log is found an appended
because there is no possiblity to pass arguments to the hotplug helper.

Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 14:33:58 +01:00
Jan Klötzke e9003caf6d mdev: add syslog logging mode
If mdev is run as daemon it should be possible to forward the debug
messages to syslog. This feature might be useful if mdev is run with -s
during boot too. OTOH it makes no sense for the daemon to log to
mdev.log. This can be handled by a syslog daemon way better. If the
daemon stays in the foreground due to -f, the messages are still written
to stderr as before.

Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 14:33:58 +01:00
Jan Klötzke d560030548 mdev: re-initialize if uevent messages were lost
If the netlink read() failed with ENOBUFS we know that we have missed at
least one message due to a socket receive buffer overrun. The only way
how to recover is to drop the old socket, open a fresh one and make a
cold-plug scan of the current system state.

Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 14:33:58 +01:00
Jan Klötzke e3f4759019 mdev: move daemon setup to dedicated function
Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 14:33:58 +01:00
Denys Vlasenko a569fd37fe uevent: increase netlink buffer sizes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 13:34:07 +01:00
Jan Klötzke 3cd55d49a2 mdev: increase netlink buffer sizes
The socket receive buffer turned out to be too small for real world
systems. Use the same size as udevd to be on the safe side. As this is
just a limit and the memory is not allocated by the kernel until really
needed there is actually no memory wasted.

Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 13:32:06 +01:00
Jan Klötzke 12aa68d10f libbb: set netlink socket revbuf size before binding
As soon as the socket is bound it will receive messages. Make sure the
recieve buffer size is increased before the first message is received.

Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-22 13:12:51 +01:00
Audun-Marius Gangstø 9bf4499dd7 lineedit: fix unicode characters in prompt
function                                             old     new   delta
parse_and_put_prompt                                 779     823     +44

Signed-off-by: Audun-Marius Gangstø <audun@gangsto.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-21 17:34:42 +01:00
Denys Vlasenko 4323ac861e libiproute: reuse string constants
text	   data	    bss	    dec	    hex	filename
1020826	    559	   5052	1026437	  fa985	busybox_old
1020815	    559	   5052	1026426	  fa97a	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-21 17:23:13 +01:00
Denys Vlasenko 2c92d1ec58 volume_id: improve struct layout (smaller offesets, smaller insns on x86)
function                                             old     new   delta
volume_id_probe_xfs                                  101      98      -3
volume_id_probe_vfat                                 827     824      -3
volume_id_probe_udf                                  541     538      -3
volume_id_probe_ubifs                                 67      64      -3
volume_id_probe_squashfs                              86      83      -3
volume_id_probe_romfs                                 97      94      -3
volume_id_probe_reiserfs                             246     243      -3
volume_id_probe_ocfs2                                110     107      -3
volume_id_probe_ntfs                                 288     285      -3
volume_id_probe_nilfs                                100      97      -3
volume_id_probe_minix                                 85      82      -3
volume_id_probe_luks                                  92      89      -3
volume_id_probe_linux_swap                           251     248      -3
volume_id_probe_linux_raid                           131     128      -3
volume_id_probe_lfs                                   62      59      -3
volume_id_probe_jfs                                  110     107      -3
volume_id_probe_iso9660                              318     315      -3
volume_id_probe_f2fs                                 107     104      -3
volume_id_probe_exfat                                285     282      -3
volume_id_probe_erofs                                 89      86      -3
volume_id_probe_cramfs                                67      64      -3
volume_id_probe_btrfs                                134     131      -3
volume_id_probe_bcache                               107     104      -3
volume_id_probe_sysv                                 194     188      -6
volume_id_probe_hfs_hfsplus                          518     512      -6
add_to_uuid_cache                                    271     265      -6
volume_id_probe_ext                                  131     122      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/27 up/down: 0/-96)            Total: -96 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-19 13:58:25 +01:00
Cristian Ionescu-Idbohrn ddfdf68ca1 fix warning: label 'out1' defined but not used
Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-19 13:14:59 +01:00
Norbert Lange c20e42e320 util-linux: support erofs filesystem
Add erofs to the known volume_ids.

function                                             old     new   delta
volume_id_probe_erofs                                  -      89     +89
fs1                                                   24      28      +4
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 1/0 up/down: 93/0)               Total: 93 bytes

Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-18 19:19:23 +01:00
Joachim Nilsson bd46f64dcb archival: avoid std namespace for local includes
Avoid using same include file naming pattern as available in GLIBC.
Renamed to match grp_.h et al.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 13:24:24 +01:00
Denys Vlasenko 4ac35a30db ash: make interactive ^C break out of PS2 mode
Based on patch by Joachim Nilsson <troglobit@gmail.com>

function                                             old     new   delta
pgetc                                                570     547     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 13:09:37 +01:00
Denys Vlasenko dc9c10a7b2 hush: make interactive ^C break out of PS2 mode
function                                             old     new   delta
syntax_error_unterm_str                                -      26     +26
parse_stream                                        2238    2251     +13
fgetc_interactive                                    243     249      +6
parse_dollar                                         824     817      -7
syntax_error_unterm_ch                                29      21      -8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 45/-15)             Total: 30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 13:00:44 +01:00
Joachim Nilsson efe99b59c6 syslogd: delay PID file creation until syslogd is ready
This patch moves the creation of the PID file until after syslogd has
set up signal handlers and is ready.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 12:12:04 +01:00
Joachim Nilsson a4747230ab login: update UTMP before forking
/bin/login updates the preliminary UTMP record created by /bin/getty for
$LOGNAME.  However, if the PID of login is not the same as getty, then
it will create a new entry.  This causes GLIBC getlogin(3) to return the
string 'LOGIN' (set by getty) instead of $LOGNAME.  This affects tools
like /usr/bin/logname but also various 3rd party PAM applications.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 12:09:53 +01:00
Denys Vlasenko 5323af7f51 awk: fix dodgy multi-char separators splitting logic
function                                             old     new   delta
awk_split                                            521     484     -37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-16 10:40:32 +01:00
Christian Eggers 89f063b900 chrt: support for musl C library
musl "implements" several sched_xxx() functions by returning ENOSYS. As
an alternative, either pthread_(g|s)etschedparam() or direct syscalls
can be used.

References: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/schedutils/chrt.c?id=fcc3078754291d2f5121797eb91b364f8e24b2f1
References: http://git.musl-libc.org/cgit/musl/commit/src/sched/sched_setscheduler.c?id=1e21e78bf7a5c24c217446d8760be7b7188711c2
Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-15 20:26:46 +01:00
Denys Vlasenko 64981b4c8e hush: document bugs in [[ =~ ]] comparison
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-01 18:47:24 +01:00
Denys Vlasenko a7c065354f shell: update comments on the status of [[ ]] compat
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31 04:32:34 +01:00
Denys Vlasenko b259e97d47 hush: add tests for unquoted < > in [[ ]]
They pass.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31 03:51:37 +01:00
Denys Vlasenko d2241f5902 shell: better support of [[ ]] bashism
Still rather rudimentary for ash

function                                             old     new   delta
binop                                                433     589    +156
check_operator                                        65     101     +36
done_word                                            736     769     +33
test_main                                            405     418     +13
parse_stream                                        2227    2238     +11
ops_texts                                            124     133      +9
ops_table                                             80      86      +6
run_pipe                                            1557    1562      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/0 up/down: 269/0)             Total: 269 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31 03:34:07 +01:00
Denys Vlasenko 112453acf2 od: unbreak it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-25 23:44:22 +01:00
Denys Vlasenko 32e1f69ae0 compat: move hexdump -R functionality to xxd -r
function                                             old     new   delta
xxd_main                                             466     680    +214
packed_usage                                       33474   33483      +9
hexdump_opts                                          17      16      -1
hexdump_main                                         565     401    -164
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 223/-165)           Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-25 16:06:45 +01:00
Denys Vlasenko e16f7eb596 hush: output bash-compat killing signal names
This significantly syncronises ash-signals and hush-signals tests.

function                                             old     new   delta
process_wait_result                                  449     450      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24 04:26:43 +02:00
Denys Vlasenko b65d6cb00f hush: do not print killing signal name in cmd_whihc_dies_on_signal
function                                             old     new   delta
process_wait_result                                  438     449     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24 03:33:32 +02:00
Denys Vlasenko 079487b487 hexdump: fix dup block comparison
function                                             old     new   delta
bb_dump_dump                                        1523    1520      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-20 19:29:32 +02:00
Denys Vlasenko dac5b83142 xxd: fix printing of trailing spaces
function                                             old     new   delta
bb_dump_dump                                        1497    1523     +26
xxd_main                                             459     466      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 33/0)               Total: 33 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-20 18:57:02 +02:00
Denys Vlasenko 085f19cdff uudecode: fix possible signed char bug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-07 17:02:46 +02:00
Denys Vlasenko 2496616b0a avoid using strok - eliminates use of hidden global variable
function                                             old     new   delta
udhcp_str2optset                                     616     650     +34
setpriv_main                                         950     975     +25
switch_root_main                                     688     706     +18
parse                                                958     970     +12
getopt_main                                          622     628      +6
parse_resolvconf                                     302     306      +4
mpstat_main                                         1139    1142      +3
static.p                                               4       -      -4
cdcmd                                                717     702     -15
strtok                                               148       -    -148
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 7/1 up/down: 102/-167)          Total: -65 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-06 02:36:47 +02:00
Xabier Oneca 535a509846 httpd: code shrink
Use decode_base64() from uuencode.c when uudecode/base64 applets are included.
That function is bigger than httpd's decodeBase64(), so we use the old one when
those applets are disabled. Bloat-o-meter when one of those is enabled:

function                                             old     new   delta
handle_incoming_and_exit                            2371    2265    -106

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-06 02:36:06 +02:00
Rui Salvaterra eecd6f7a6c ip rule: add support for fwmark/fwmask for policy routing
This adds support for fwmark/fwmask in ip rule which is needed, for example, in
OpenWrt's mwan3. Masks are supported since Linux 2.6.19.

Fixes: https://bugs.busybox.net/show_bug.cgi?id=11621

Signed-off-by: Rui Salvaterra <rsalvaterra@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-03 22:08:39 +02:00
Denys Vlasenko 16e82c61d4 tar: fix fallout of last_char_is(NULL) no longer being allowed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-02 18:30:53 +02:00
Denys Vlasenko a90a54aead udhcp: remove struct packing attribute, eliminates gcc-9.x
"error: taking address of packed member of 'struct ip_udp_dhcp_packet'
may result in an unaligned pointer value" here:

	udhcp_dump_packet(&packet.data);

and in other places.

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 21:52:16 +02:00
Denys Vlasenko 3c3928fc65 tydy up a few uses of recursive_action(), no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 20:27:28 +02:00
Denys Vlasenko 4a0eb0370c gcc-9.x warning fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 03:07:22 +02:00
Denys Vlasenko aaa0709e7b libbb: do not open-code __errno_location() call
Thanks dalias!

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 01:44:26 +02:00
Denys Vlasenko 841878e7ee shell: remove FAST_FUNC from a static function
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 00:57:05 +02:00
Denys Vlasenko b1c7a66ca6 libbb: extend "errno pointer" trick to other than __GLIBC__
Savings on musl:

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

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

    squashfs: Unknown parameter 'sizelimit'

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

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

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

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-01 00:31:11 +02:00
Denys Vlasenko abefc3c276 libbb: fold common64_hash() into its only user
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-30 22:22:04 +02:00
Denys Vlasenko bd202a5ec1 xargs: fix -I SUBSTR behaviour
function                                             old     new   delta
process_stdin_with_replace                           165     204     +39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-30 00:00:43 +02:00
Denys Vlasenko d4dd48f294 shell: add testsuite for "wait $pid" waiting for other tasks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 22:36:36 +02:00
Denys Vlasenko 91e11eba6e ash: jobs: Fix waitcmd busy loop
Upstream commit:

    Date: Tue, 2 Jun 2020 23:46:48 +1000
    jobs: Fix waitcmd busy loop

    We need to clear gotsigchld in waitproc because it is used as
    a loop conditional for the waitcmd case.  Without it waitcmd
    may busy loop after a SIGCHLD.

    This patch also changes gotsigchld into a volatile sig_atomic_t
    to prevent compilers from optimising its accesses away.

    Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

This change also incorporates other changes to bring us closer to upstream.

function                                             old     new   delta
dowait                                               553     636     +83

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 20:35:55 +02:00
Denys Vlasenko 8d5f465a20 ash: jobs: Fix infinite loop in waitproc
Upstream commit:

    Date: Fri, 10 Apr 2020 21:03:09 +1000
    jobs: Fix infinite loop in waitproc

    After we changed the resetting of gotsigchld so that it is only
    done if jp is NULL, we can now get an infinite loop in waitproc
    if gotsigchld is set but there is no outstanding child because
    everything had been waited for previously without gotsigchld being
    zeroed.

    This patch fixes it by always zeroing gotsigchld as we did before.
    The bug that the previous patch was trying to fix is now resolved
    by switching the blocking mode to DOWAIT_NORMAL after the specified
    job has been completed so that we really do wait for all outstanding
    dead children.

    Reported-by: Harald van Dijk <harald@gigawatt.nl>
    Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
dowait                                               553     631     +78

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 20:21:27 +02:00
Denys Vlasenko 777a6357c0 ash: remove a tentative TODO, it's a wrong idea
Upstream tried it, and then reverted by:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Tue, 26 May 2020 23:19:05 +1000
    parser: Fix double-backslash nl in old-style command sub

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 20:21:27 +02:00
Denys Vlasenko afb5d8b2db ntpd: fix the case where two replies received at once and first one causes a step
function                                             old     new   delta
recv_and_process_peer_pkt                           2476    2486     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 14:19:17 +02:00
Sergey Ponomarev a949399d17 httpd: Make Deny/Allow by IP config support optional
When disabled:

function                                             old     new   delta
if_ip_denied_send_HTTP_FORBIDDEN_and_exit             52       -     -52
handle_incoming_and_exit                            2201    2097    -104
scan_ip                                              170       -    -170
parse_conf                                          1365    1065    -300
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-626)           Total: -626 bytes

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-16 14:58:31 +02:00
Sergey Ponomarev 4864a68596 httpd: Support caching via ETag header
If server responds with ETag then next time client can resend it via If-None-Match header.
Then httpd will check if file wasn't modified and if not return 304 Not Modified status code.
The ETag value is constructed from file's last modification date in unix epoch and it's size:
"hex(last_mod)-hex(file_size)" e.g. "5e132e20-417" (with quotes).
That means that it's not completely reliable as hash functions but fair enough.
The same form of ETag is used by Nginx so load balancing of static content is safe.

function                                             old     new   delta
handle_incoming_and_exit                            2135    2201     +66
http_response                                         88      96      +8
send_headers                                         676     683      +7
parse_conf                                          1362    1365      +3
http_response_type                                    22      24      +2
send_file_and_exit                                   847     841      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/1 up/down: 86/-6)              Total: 80 bytes

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 23:54:48 +02:00
Sergey Ponomarev b6efac31d8 httpd: Don't add Last-Modified header to response
The Last-Modified header is used for caching.
The client (browser) will send back the received date to server via If-Modified-Since request header.
But both headers MUST be an RFC 1123 formatted string.
And the formatting consumes resources on request parsing and response generation.
Instead we can use ETag header.
This simplifies logic and the only downside is that in JavaScript the document.lastModified will return null.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 23:23:45 +02:00
Sergey Ponomarev 68f75bb9ce httpd: Don't add Date header to response
RFC 2616 sec. 14.18 says that server MUST send Date header.
But in fact the header make sense only for Cache-Control and can be omitted.
In the same time the Date eats power, CPU and network resources which are critical for embedded systems.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 23:04:49 +02:00
Sergey Ponomarev b414cdf5b4 httpd: Update to HTTP/1.1
HTTP v1.1 was released in 1999 year and it's time to update BB HTTPD.
Browsers may behave badly with HTTP/1.0
E.g. Chrome does not send the If-None-Match header with ETag.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 22:51:14 +02:00
Eddie James 1a5d6fcbb5 hwclock: Fix settimeofday for glibc v2.31+
The glibc implementation changed for settimeofday, resulting in "invalid
argument" error when attempting to set both timezone and time with a single
call. Fix this by calling settimeofday twice

Signed-off-by: Eddie James <eajames@linux.ibm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 22:29:00 +02:00
Denys Vlasenko a77f3ecf68 grep: for -L, exitcode 0 means files *without* matches were found, closes 13151
This is a recent change in GNU grep as well (after 3.1)

function                                             old     new   delta
grep_file                                           1215    1228     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-15 00:39:30 +02:00
Ron Yorston 5c69ad0ecd build system: drop PLATFORM_LINUX
PLATFORM_LINUX is a hidden configuration option which is disabled by
default and enabled at over a hundred locations for features that are
deemed to be Linux specific.

The only effect of PLATFORM_LINUX is to control compilation of
libbb/match_fstype.c.  This file is only needed by mount and umount.

Remove all references to PLATFORM_LINUX and compile match_fstype.c
if mount or umount is enabled.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-13 17:12:56 +02:00
Martin Lewis 9914d8b861 udhcpc: add support for long options
Duplicate options are currently overridden (only the last option is kept).
This leads to unexpected behavior when using long options.

The patch adds support for long options in compliance with RFC 3396.

Fixes #13136.

function                                             old     new   delta
udhcp_run_script                                     601     725    +124
optitem_unset_env_and_free                             -      38     +38
putenvp                                               46      59     +13
static.xmalloc_optname_optval                        718     717      -1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 175/-1)            Total: 174 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-08-13 16:48:07 +02:00
Christian Eggers 8a485b0a36 ip address: Add support for "valid_lft" and "preferred_lft" options
Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:48:50 +02:00
Christian Eggers 31d34f3bd8 ip: Add support for "noprefixroute" option
The "noprefixroute" option suppresses automatic generation of a routing
table entry based on the interface's ip address.

The ifa_flags field has only 8 bit. If higher bits are set,
rta_tb[IFA_FLAGS] has to be used instead.

Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:45:36 +02:00
Christian Eggers 39925026f6 shell: Fix "read -d ''" behavior
With bash's read builtin it is possible to read from a file (e.g.
device-tree) until the first '\0' character:

IFS= read -r -d '' VARIABLE < file

In busybox ash the -d extension is also implemented, but checking the
read character for '\0' has to be performed after comparing with the
delimiter.

Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:42:30 +02:00
Sergey Ponomarev a088da4476 httpd_indexcgi.c: use CSS for odd/even rows
Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 18:14:54 +02:00
Sergey Ponomarev 197ae0f9ae httpd_indexcgi.c: minimize style CSS
Remove new lines \n and some semicolons ;. This minimize page style size from 655 to 604

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31 17:53:48 +02:00
Denys Vlasenko 2dd82f465e lsscsi: code shrink
function                                             old     new   delta
lsscsi_main                                          298     302      +4
get_line                                              56      45     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-11)              Total: -7 bytes

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

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-20 00:04:33 +02:00
Denys Vlasenko 06a407c628 networking: support ftp PASV responses not ending with ')'
Patch by Baruch Burstein <bmburstein@gmail.com>

function                                             old     new   delta
parse_pasv_epsv                                      153     181     +28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-19 20:59:35 +02:00
Denys Vlasenko 79a4032eef libbb: shrink last_char_is(), no longer allow NULL string argument
function                                             old     new   delta
last_char_is                                          40      28     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-19 20:49:22 +02:00
Martin Lewis 4468c569f7 domain_codec: optimize dname_dec and convert_dname
dname_dec: now iterates over the packet only once.
convert_dname: remove redundant checks and code shrink.

While testing I've noticed that some of the tests didn't compile
properly, so I fixed them.

function                                             old     new   delta
dname_dec                                            286     267     -19
dname_enc                                            166     143     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-42)             Total: -42 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-12 21:19:13 +02:00
Gray Wolf 051665ef69 crontab: Fix -e with editors saving using renaming strategy
Some editors (like vim) use renaming strategy to save file. That means
they save a file to some random name and then rename it to final
location. The advantage is that such save is atomic.

However, crontab -e holds open fd to the temporary file, meaning it
never sees the changes. The temporary file needs to be re-opened after
the editor terminates for the changes to properly save.

Fixes #12491

Signed-off-by: Gray Wolf <wolf@wolfsden.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-11 17:02:37 +02:00
Denys Vlasenko d21a63f9fc libbb: code shrink in last_char_is()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-30 08:33:02 +02:00
Martin Lewis c9fc15359e compare_string_array: code shrink
Code shrink and prevention of possible out of bounds access.

function                                             old     new   delta
nth_string                                            36      26     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10)             Total: -10 bytes
   text	   data	    bss	    dec	    hex	filename
 981342	  16915	   1872	1000129	  f42c1	busybox_old
 981332	  16915	   1872	1000119	  f42b7	busybox_unstripped

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 16:09:46 +02:00
Martin Lewis ac79db6a3b procps: code shrink
function                                             old     new   delta
skip_whitespace_if_prefixed_with                       -      17     +17
procps_read_smaps                                    911     854     -57
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 17/-57)            Total: -40 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 16:07:20 +02:00
Martin Lewis 1f86ecb729 udhcpc: fix a TODO in fill_envp using option scanner
fill_envp now iterates over the packet only once instead of a few hundred times
using the new option scanner.

function                                             old     new   delta
udhcp_scan_options                                     -     189    +189
putenvp                                                -      46     +46
init_scan_state                                        -      22     +22
udhcp_get_option                                     227     104    -123
udhcp_run_script                                     835     601    -234
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/2 up/down: 257/-357)         Total: -100 bytes

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 15:26:09 +02:00
Martin Lewis acdc8eed89 udhcp: add option scanner
Added an option scanner to udhcp to enable iteration over packet options.

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:57:02 +02:00
Scott Court fc2ce04a38 wget: fix openssl options for cert verification
function                                             old     new   delta
is_ip_address                                          -      54     +54
spawn_https_helper_openssl                           461     486     +25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 79/0)               Total: 79 bytes

Signed-off-by: Scott Court <z5t1@z5t1.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:32:09 +02:00
Norbert Lange 79bd7c3f7b acpid: only display -p if supported in usage
Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:11:03 +02:00
Norbert Lange 05faa6103b dhcpd: remove hardcoded pidfile path
Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:07:57 +02:00
Norbert Lange 86a633ef9a dpkg: prevent important directories from being removed
busybox will remove directory symlinks, which is at
odds with common layouts that have some of
bin/lib/lib32/lib64 symlinked.

this adds a exludelist for critcal and often symlinked
directories.

Fixes: Bug 12551

function                                             old     new   delta
remove_file_array                                    139     231     +92

Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 14:06:40 +02:00
Norbert Lange a16c8ef212 nc_bloaty: support udp broadcast ports
Add a -b option, identical to debians "traditional" netcat.
This allows sending (subnet) UDP Broadcasts.

function                                             old     new   delta
packed_usage                                       33420   33441     +21
nc_main                                             1041    1057     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0)               Total: 37 bytes

Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-29 13:53:17 +02:00
Denys Vlasenko c918ea1673 Start 1.33.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-26 21:30:50 +02:00
352 changed files with 4731 additions and 3006 deletions

No files matched your search

+8 -12
View File
@@ -312,7 +312,6 @@ config BUSYBOX_EXEC_PATH
config SELINUX
bool "Support NSA Security Enhanced Linux"
default n
select PLATFORM_LINUX
help
Enable support for SELinux in applets ls, ps, and id. Also provide
the option of compiling in SELinux applets.
@@ -358,17 +357,6 @@ config FEATURE_SYSLOG
#This option is auto-selected when you select any applet which may
#send its output to syslog. You do not need to select it manually.
config PLATFORM_LINUX
bool #No description makes it a hidden option
default n
#help
#For the most part, busybox requires only POSIX compatibility
#from the target system, but some applets and features use
#Linux-specific interfaces.
#
#This is automatically selected if any applet or feature requires
#Linux-specific interfaces. You do not need to select it manually.
comment 'Build Options'
config STATIC
@@ -541,6 +529,14 @@ config STACK_OPTIMIZATION_386
do not work with it (they use SSE instructions without
ensuring stack alignment).
config STATIC_LIBGCC
bool "Use -static-libgcc"
default y
help
This option instructs gcc to link in a static version of its
support library, libgcc. This means that the binary will require
one fewer dynamic library at run time.
comment 'Installation Options ("make install" behavior)'
choice
+2 -2
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 32
SUBLEVEL = 0
PATCHLEVEL = 33
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
+2 -1
View File
@@ -58,7 +58,8 @@ CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-s
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
CFLAGS += $(call cc-option,-funsigned-char,)
ifneq ($(CC),clang)
ifeq ($(CONFIG_STATIC_LIBGCC),y)
# Disable it, for example, if you get
# "clang-9: warning: argument unused during compilation: '-static-libgcc'"
CFLAGS += $(call cc-option,-static-libgcc,)
endif
+4
View File
@@ -20,6 +20,10 @@
#undef ARRAY_SIZE
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#include "../include/autoconf.h"
#include "../include/applet_metadata.h"
+8
View File
@@ -11,3 +11,11 @@ ifeq ($(CONFIG_STACK_OPTIMIZATION_386),y)
# from aligning stack to 16 bytes. (Which is gcc's way of supporting SSE).
CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2,)
endif
# "Control how GCC aligns variables.
# Supported values for type are compat uses increased alignment value
# compatible uses GCC 4.8 and earlier, abi uses alignment value as specified by the psABI,
# and cacheline uses increased alignment value to match the cache line size.
# compat is the default."
# "abi" seems to be somewhat successful in preventing oversealous data alignment.
CFLAGS += $(call cc-option,-malign-data=abi,)
+11
View File
@@ -0,0 +1,11 @@
# ==========================================================================
# Build system
# ==========================================================================
# "Control how GCC aligns variables.
# Supported values for type are compat uses increased alignment value
# compatible uses GCC 4.8 and earlier, abi uses alignment value as specified by the psABI,
# and cacheline uses increased alignment value to match the cache line size.
# compat is the default."
# "abi" seems to be somewhat successful in preventing oversealous data alignment.
CFLAGS += $(call cc-option,-malign-data=abi,)
+32 -29
View File
@@ -48,19 +48,9 @@
//kbuild:lib-$(CONFIG_AR) += ar.o
//usage:#define ar_trivial_usage
//usage: "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES"
//usage:#define ar_full_usage "\n\n"
//usage: "Extract or list FILES from an ar archive\n"
//usage: "\n -o Preserve original dates"
//usage: "\n -p Extract to stdout"
//usage: "\n -t List"
//usage: "\n -x Extract"
//usage: "\n -v Verbose"
#include "libbb.h"
#include "bb_archive.h"
#include "ar.h"
#include "ar_.h"
#if ENABLE_FEATURE_AR_CREATE
/* filter out entries with same names as specified on the command line */
@@ -220,23 +210,36 @@ static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
);
}
#define AR_OPT_VERBOSE (1 << 0)
#define AR_OPT_PRESERVE_DATE (1 << 1)
/* "ar r" implies create, but warns about it. c suppresses warning.
* bbox accepts but ignores it: */
#define AR_OPT_CREATE (1 << 2)
#define AR_CMD_PRINT (1 << 3)
#define FIRST_CMD AR_CMD_PRINT
#define AR_CMD_LIST (1 << 4)
#define AR_CMD_EXTRACT (1 << 5)
#define AR_CMD_INSERT (1 << 6)
//usage:#define ar_trivial_usage
//usage: "x|p|t"IF_FEATURE_AR_CREATE("|r")" [-ov] ARCHIVE [FILE]..."
//usage:#define ar_full_usage "\n\n"
//usage: "Extract or list FILEs from an ar archive"IF_FEATURE_AR_CREATE(", or create it")"\n"
//usage: "\n x Extract"
//usage: "\n p Extract to stdout"
//usage: "\n t List"
//usage: IF_FEATURE_AR_CREATE(
//usage: "\n r Create"
//usage: )
//usage: "\n -o Restore mtime"
//usage: "\n -v Verbose"
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ar_main(int argc UNUSED_PARAM, char **argv)
{
archive_handle_t *archive_handle;
unsigned opt, t;
enum {
OPT_VERBOSE = (1 << 0),
OPT_PRESERVE_DATE = (1 << 1),
/* "ar r" implies create, but warns about it. c suppresses warning.
* bbox accepts but ignores it: */
OPT_CREATE = (1 << 2),
CMD_PRINT = (1 << 3),
FIRST_CMD = CMD_PRINT,
CMD_LIST = (1 << 4),
CMD_EXTRACT = (1 << 5),
CMD_INSERT = ((1 << 6) * ENABLE_FEATURE_AR_CREATE),
};
archive_handle = init_handle();
@@ -256,26 +259,26 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
if (t & (t-1)) /* more than one of p,t,x[,r] are specified */
bb_show_usage();
if (opt & AR_CMD_PRINT) {
if (opt & CMD_PRINT) {
archive_handle->action_data = data_extract_to_stdout;
}
if (opt & AR_CMD_LIST) {
if (opt & CMD_LIST) {
archive_handle->action_header = header_list;
}
if (opt & AR_CMD_EXTRACT) {
if (opt & CMD_EXTRACT) {
archive_handle->action_data = data_extract_all;
}
if (opt & AR_OPT_PRESERVE_DATE) {
if (opt & OPT_PRESERVE_DATE) {
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
}
if (opt & AR_OPT_VERBOSE) {
if (opt & OPT_VERBOSE) {
archive_handle->action_header = header_verbose_list_ar;
}
#if ENABLE_FEATURE_AR_CREATE
archive_handle->ar__name = *argv;
#endif
archive_handle->src_fd = xopen(*argv++,
(opt & AR_CMD_INSERT)
(opt & CMD_INSERT)
? O_RDWR | O_CREAT
: O_RDONLY
);
@@ -287,7 +290,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
}
#if ENABLE_FEATURE_AR_CREATE
if (opt & AR_CMD_INSERT)
if (opt & CMD_INSERT)
return write_ar_archive(archive_handle);
#endif
+5 -5
View File
@@ -219,7 +219,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
//usage:#define uncompress_trivial_usage
//usage: "[-cf] [FILE]..."
//usage:#define uncompress_full_usage "\n\n"
//usage: "Decompress .Z file[s]\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Overwrite"
@@ -461,7 +461,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//usage:#define unlzma_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage:#define unlzma_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
@@ -469,7 +469,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//usage:#define lzma_trivial_usage
//usage: "-d [-cfk] [FILE]..."
//usage:#define lzma_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
@@ -532,7 +532,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//usage:#define unxz_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage:#define unxz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
@@ -541,7 +541,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//usage:#define xz_trivial_usage
//usage: "-d [-cfk] [FILE]..."
//usage:#define xz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
+1 -1
View File
@@ -50,7 +50,7 @@
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
//usage:#define bzip2_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage: "[-cfk" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789] [FILE]..."
//usage:#define bzip2_full_usage "\n\n"
//usage: "Compress FILEs (or stdin) with bzip2 algorithm\n"
//usage: "\n -1..9 Compression level"
+1 -1
View File
@@ -68,7 +68,7 @@
//usage: "\n -H newc Archive format"
//usage: )
//usage: "\n -d Make leading directories"
//usage: "\n -m Preserve mtime"
//usage: "\n -m Restore mtime"
//usage: "\n -v Verbose"
//usage: "\n -u Overwrite"
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
+24 -1
View File
@@ -1204,6 +1204,27 @@ static char **create_list(const char *filename)
return file_list;
}
/** This tests if the filename is an "important" directory, which might be symlinked.
* Debians dpkg test if directories are used by other packages, this
* implementation doesn't and would remove for ex. an lib -> usr/lib symlink.
*/
static int is_builtin_exclude(const char *name)
{
if (*name++ != '/')
return 0;
if (index_in_strings(".\0" "etc\0" "opt\0" "srv\0" "var\0" "var/lib\0",
name) >= 0)
return 1;
if (is_prefixed_with(name, "usr/")) {
name += sizeof("usr/") - 1;
if (is_prefixed_with(name, "local/"))
name += sizeof("local/") - 1;
}
return index_in_strings("bin\0" "lib\0" "lib32\0" "lib64\0" "sbin\0",
name) >= 0;
}
/* maybe i should try and hook this into remove_file.c somehow */
static int remove_file_array(char **remove_names, char **exclude_names)
{
@@ -1215,6 +1236,8 @@ static int remove_file_array(char **remove_names, char **exclude_names)
return 0;
}
for (i = 0; remove_names[i] != NULL; i++) {
if (is_builtin_exclude(remove_names[i]))
continue;
if (exclude_names != NULL) {
for (j = 0; exclude_names[j] != NULL; j++) {
if (strcmp(remove_names[i], exclude_names[j]) == 0) {
@@ -1281,7 +1304,7 @@ postrm abort-install <old_version>
postrm abort-upgrade <old_version>
postrm disappear <overwriter> <version>
*/
static const char *const all_control_files[] = {
static const char *const all_control_files[] ALIGN_PTR = {
"preinst", "postinst", "prerm", "postrm",
"list", "md5sums", "shlibs", "conffiles",
"config", "templates"
+1 -1
View File
@@ -28,7 +28,7 @@
//usage: "\n -f Print control fields"
//usage: "\n -e Extract control files to DIR (default: ./DEBIAN)"
//usage: "\n -x Extract files to DIR (no default)"
//usage: "\n -X Verbose -x"
//usage: "\n -X Verbose extract"
//usage:
//usage:#define dpkg_deb_example_usage
//usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
+1 -1
View File
@@ -459,7 +459,7 @@ int mainGtU(EState* state,
* usually small, typically <= 20.
*/
static
const uint32_t incs[14] = {
const uint32_t incs[14] ALIGN4 = {
1, 4, 13, 40, 121, 364, 1093, 3280,
9841, 29524, 88573, 265720,
797161, 2391484
@@ -20,7 +20,7 @@ enum {
TAR_MAX,
};
static const char *const tar_var[] = {
static const char *const tar_var[] ALIGN_PTR = {
// "FILETYPE",
"MODE",
"FILENAME",
+12 -4
View File
@@ -194,14 +194,14 @@ struct cp_ext {
};
/* Copy lengths and extra bits for literal codes 257..285 */
/* note: see note #13 above about the 258 in this list. */
static const struct cp_ext lit = {
static const struct cp_ext lit ALIGN2 = {
/*257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 */
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 */
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 } /* 99 == invalid */
};
/* Copy offsets and extra bits for distance codes 0..29 */
static const struct cp_ext dist = {
static const struct cp_ext dist ALIGN2 = {
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 */
{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 },
{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }
@@ -220,10 +220,20 @@ static const uint8_t border[] ALIGN1 = {
* each table.
* t: table to free
*/
#define BAD_HUFT(p) ((uintptr_t)(p) & 1)
#define ERR_RET ((huft_t*)(uintptr_t)1)
static void huft_free(huft_t *p)
{
huft_t *q;
/*
* If 'p' has the error bit set we have to clear it, otherwise we might run
* into a segmentation fault or an invalid pointer to free(p)
*/
if (BAD_HUFT(p)) {
p = (huft_t*)((uintptr_t)(p) ^ (uintptr_t)(ERR_RET));
}
/* Go through linked list, freeing from the malloced (t[-1]) address. */
while (p) {
q = (--p)->v.t;
@@ -289,8 +299,6 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
* or a valid pointer to a Huffman table, ORed with 0x1 if incompete table
* is given: "fixed inflate" decoder feeds us such data.
*/
#define BAD_HUFT(p) ((uintptr_t)(p) & 1)
#define ERR_RET ((huft_t*)(uintptr_t)1)
static huft_t* huft_build(const unsigned *b, const unsigned n,
const unsigned s, const struct cp_ext *cp_ext,
unsigned *m)
+4 -1
View File
@@ -290,8 +290,11 @@ unpack_lzma_stream(transformer_state_t *xstate)
uint32_t pos;
pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
if ((int32_t)pos < 0) {
pos += header.dict_size;
if ((int32_t)pos < 0)
goto bad;
}
match_byte = buffer[pos];
do {
int bit;
+1 -1
View File
@@ -6,7 +6,7 @@
*/
#include "libbb.h"
#include "bb_archive.h"
#include "ar.h"
#include "ar_.h"
/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
static unsigned read_num(char *str, int base, int len)
+1 -1
View File
@@ -352,7 +352,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* case 0: */
case '0':
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
if (last_char_is(file_header->name, '/')) {
if (file_header->name && last_char_is(file_header->name, '/')) {
goto set_dir;
}
#endif
+1 -1
View File
@@ -4,7 +4,7 @@
*/
#include "libbb.h"
#include "bb_archive.h"
#include "ar.h"
#include "ar_.h"
void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
{
+7 -5
View File
@@ -83,7 +83,9 @@ struct globals {
void *map;
rpm_index *mytags;
int tagcount;
unsigned mapsize, pagesize;
unsigned mapsize;
IF_VARIABLE_ARCH_PAGESIZE(unsigned pagesize;)
#define G_pagesize cached_pagesize(G.pagesize)
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
@@ -141,11 +143,11 @@ static int rpm_gettags(const char *filename)
G.mytags = tags;
/* Map the store */
storepos = (storepos + G.pagesize) & -(int)G.pagesize;
storepos = (storepos + G_pagesize) & -(int)G_pagesize;
/* remember size for munmap */
G.mapsize = storepos;
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0);
G.map = mmap_read(fd, storepos);
if (G.map == MAP_FAILED)
bb_perror_msg_and_die("mmap '%s'", filename);
@@ -356,7 +358,7 @@ int rpm_main(int argc, char **argv)
int opt, func = 0;
INIT_G();
G.pagesize = getpagesize();
INIT_PAGESIZE(G.pagesize);
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
switch (opt) {
@@ -523,7 +525,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
int rpm_fd;
INIT_G();
G.pagesize = getpagesize();
INIT_PAGESIZE(G.pagesize);
rpm_fd = rpm_gettags(argv[1]);
+23 -16
View File
@@ -297,7 +297,8 @@ static void writeLongname(int fd, int type, const char *name, int dir)
header.typeflag = type;
strcpy(header.name, "././@LongLink");
/* This sets mode/uid/gid/mtime to "00...00<NUL>" strings */
memset(header.mode, '0', sizeof(struct prefilled));
memset((char*)&header + offsetof(struct tar_header_t, mode), /* make gcc-9.x happy */
'0', sizeof(struct prefilled));
header.mode [sizeof(header.mode ) - 1] = '\0';
header.uid [sizeof(header.uid ) - 1] = '\0';
header.gid [sizeof(header.gid ) - 1] = '\0';
@@ -490,10 +491,11 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
# define exclude_file(excluded_files, file) 0
# endif
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth UNUSED_PARAM)
static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
const char *fileName,
struct stat *statbuf)
{
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
struct TarBallInfo *tbInfo = (struct TarBallInfo *) state->userData;
const char *header_name;
int inputFileFd = -1;
@@ -699,7 +701,7 @@ static NOINLINE int writeTarFile(
/* Read the directory/files and iterate over them one at a time */
while (filelist) {
if (!recursive_action(filelist->data, recurseFlags,
writeFileToTarball, writeFileToTarball, tbInfo, 0)
writeFileToTarball, writeFileToTarball, tbInfo)
) {
errorFlag = TRUE;
}
@@ -773,7 +775,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
//usage: "vokO] "
//usage: "[-f TARFILE] [-C DIR] "
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN]... "))
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[OPTION]... "))
//usage: "[FILE]..."
//usage:#define tar_full_usage "\n\n"
//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
@@ -807,6 +809,11 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_SEAMLESS_BZ2(
//usage: "\n -j (De)compress using bzip2"
//usage: )
//usage: IF_FEATURE_SEAMLESS_LZMA(
//usage: IF_FEATURE_TAR_LONG_OPTIONS(
//usage: "\n --lzma (De)compress using lzma"
//usage: )
//usage: )
//usage: "\n -a (De)compress based on extension"
//usage: IF_FEATURE_TAR_CREATE(
//usage: "\n -h Follow symlinks"
@@ -818,21 +825,21 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: "\n --exclude PATTERN Glob pattern to exclude"
//usage: )
//usage: )
//usage: IF_FEATURE_TAR_LONG_OPTIONS(
//usage: "\n --overwrite Replace existing files"
//usage: "\n --strip-components NUM NUM of leading components to strip"
//usage: "\n --no-recursion Don't descend in directories"
//usage: "\n --numeric-owner Use numeric user:group"
//usage: "\n --no-same-permissions Don't restore access permissions"
//usage: IF_FEATURE_TAR_TO_COMMAND(
//usage: "\n --to-command COMMAND Pipe files to COMMAND"
//usage: )
//usage: )
//usage:
//usage:#define tar_example_usage
//usage: "$ zcat /tmp/tarball.tar.gz | tar -xf -\n"
//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n"
// Supported but aren't in --help:
// lzma
// no-recursion
// numeric-owner
// no-same-permissions
// overwrite
//IF_FEATURE_TAR_TO_COMMAND(
// to-command
//)
enum {
OPTBIT_KEEP_OLD = 8,
IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
-1
View File
@@ -16,7 +16,6 @@ CONFIG_HAVE_DOT_CONFIG=y
# CONFIG_EXTRA_COMPAT is not set
# CONFIG_INCLUDE_SUSv2 is not set
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
-1
View File
@@ -87,7 +87,6 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
CONFIG_INCLUDE_SUSv2=y
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
-1
View File
@@ -16,7 +16,6 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
# CONFIG_INCLUDE_SUSv2 is not set
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
-1
View File
@@ -16,7 +16,6 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
# CONFIG_INCLUDE_SUSv2 is not set
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
-1
View File
@@ -16,7 +16,6 @@ CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
CONFIG_INCLUDE_SUSv2=y
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_PLATFORM_LINUX=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
-1
View File
@@ -16,7 +16,6 @@ CONFIG_HAVE_DOT_CONFIG=y
# CONFIG_EXTRA_COMPAT is not set
CONFIG_INCLUDE_SUSv2=y
CONFIG_USE_PORTABLE_CODE=y
# CONFIG_PLATFORM_LINUX is not set
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
-1
View File
@@ -9,7 +9,6 @@
//config:config CHVT
//config: bool "chvt (2 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to change to another terminal.
//config: Example: chvt 4 (change to terminal /dev/tty4)
-1
View File
@@ -10,7 +10,6 @@
//config:config DEALLOCVT
//config: bool "deallocvt (1.9 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program deallocates unused virtual consoles.
-1
View File
@@ -9,7 +9,6 @@
//config:config DUMPKMAP
//config: bool "dumpkmap (1.6 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program dumps the kernel's keyboard translation table to
//config: stdout, in binary format. You can then use loadkmap to load it.
-1
View File
@@ -9,7 +9,6 @@
//config:config FGCONSOLE
//config: bool "fgconsole (1.5 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program prints active (foreground) console number.
-1
View File
@@ -11,7 +11,6 @@
//config:config KBD_MODE
//config: bool "kbd_mode (4.1 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program reports and sets keyboard mode.
-2
View File
@@ -12,14 +12,12 @@
//config:config LOADFONT
//config: bool "loadfont (5.2 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a console font from standard input.
//config:
//config:config SETFONT
//config: bool "setfont (24 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Allows to load console screen map. Useful for i18n.
//config:
-1
View File
@@ -9,7 +9,6 @@
//config:config LOADKMAP
//config: bool "loadkmap (1.8 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a keyboard translation table from
//config: standard input.
-1
View File
@@ -10,7 +10,6 @@
//config:config OPENVT
//config: bool "openvt (7.2 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to start a command on an unused
//config: virtual terminal.
-1
View File
@@ -10,7 +10,6 @@
//config:config SETCONSOLE
//config: bool "setconsole (3.6 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Redirect writes to /dev/console to another device,
//config: like the current tty while logged in via telnet.
-1
View File
@@ -11,7 +11,6 @@
//config:config SETKEYCODES
//config: bool "setkeycodes (2.1 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads entries into the kernel's scancode-to-keycode
//config: map, allowing unusual keyboards to generate usable keycodes.
-1
View File
@@ -11,7 +11,6 @@
//config:config SETLOGCONS
//config: bool "setlogcons (1.8 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program redirects the output console of kernel messages.
-1
View File
@@ -9,7 +9,6 @@
//config:config SHOWKEY
//config: bool "showkey (4.7 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Shows keys pressed.
+7 -6
View File
@@ -65,12 +65,14 @@
* symbolic links encountered during recursive directory traversals.
*/
static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
static int FAST_FUNC fileAction(struct recursive_state *state,
const char *fileName,
struct stat *statbuf)
{
mode_t newmode;
/* match coreutils behavior */
if (depth == 0) {
if (state->depth == 0) {
/* statbuf holds lstat result, but we need stat (follow link) */
if (stat(fileName, statbuf))
goto err;
@@ -79,9 +81,9 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void
return TRUE;
}
newmode = bb_parse_mode((char *)param, statbuf->st_mode);
newmode = bb_parse_mode((char *)state->userData, statbuf->st_mode);
if (newmode == (mode_t)-1)
bb_error_msg_and_die("invalid mode '%s'", (char *)param);
bb_error_msg_and_die("invalid mode '%s'", (char *)state->userData);
if (chmod(fileName, newmode) == 0) {
if (OPT_VERBOSE
@@ -136,8 +138,7 @@ int chmod_main(int argc UNUSED_PARAM, char **argv)
OPT_RECURSE, // recurse
fileAction, // file action
fileAction, // dir action
smode, // user data
0) // depth
smode) // user data
) {
retval = EXIT_FAILURE;
}
+4 -5
View File
@@ -97,10 +97,10 @@ struct param_t {
chown_fptr chown_func;
};
static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf,
void *vparam, int depth UNUSED_PARAM)
static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
const char *fileName, struct stat *statbuf)
{
#define param (*(struct param_t*)vparam)
#define param (*(struct param_t*)state->userData)
#define opt option_mask32
uid_t u = (param.ugid.uid == (uid_t)-1L) ? statbuf->st_uid : param.ugid.uid;
gid_t g = (param.ugid.gid == (gid_t)-1L) ? statbuf->st_gid : param.ugid.gid;
@@ -159,8 +159,7 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
flags, /* flags */
fileAction, /* file action */
fileAction, /* dir action */
&param, /* user data */
0) /* depth */
&param) /* user data */
) {
retval = EXIT_FAILURE;
}
+1 -1
View File
@@ -38,7 +38,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
//usage:#define cp_trivial_usage
//usage: "[OPTIONS] SOURCE... DEST"
//usage: "[-arPLHpfilsTu] SOURCE... DEST"
//usage:#define cp_full_usage "\n\n"
//usage: "Copy SOURCE(s) to DEST\n"
//usage: "\n -a Same as -dpR"
+44 -55
View File
@@ -37,7 +37,6 @@
//config: bool "Support %[num]N nanosecond format specifier"
//config: default n # stat's nanosecond field is a bit non-portable
//config: depends on DATE
//config: select PLATFORM_LINUX
//config: help
//config: Support %[num]N format specifier. Adds ~250 bytes of code.
//config:
@@ -94,36 +93,25 @@
*/
//usage:#define date_trivial_usage
//usage: "[OPTIONS] [+FMT] [TIME]"
//usage: "[OPTIONS] [+FMT] [[-s] TIME]"
//usage:#define date_full_usage "\n\n"
//usage: "Display time (using +FMT), or set time\n"
//usage: IF_NOT_LONG_OPTS(
//usage: "\n [-s] TIME Set time to TIME"
//usage: "\n -u Work in UTC (don't convert to local time)"
//usage: "\n -R Output RFC-2822 compliant date string"
//usage: ) IF_LONG_OPTS(
//usage: "\n [-s,--set] TIME Set time to TIME"
//usage: "\n -u,--utc Work in UTC (don't convert to local time)"
//usage: "\n -R,--rfc-2822 Output RFC-2822 compliant date string"
//usage: )
//usage: IF_FEATURE_DATE_ISOFMT(
//usage: "\n -I[SPEC] Output ISO-8601 compliant date string"
//usage: "\n SPEC='date' (default) for date only,"
//usage: "\n 'hours', 'minutes', or 'seconds' for date and"
//usage: "\n time to the indicated precision"
//usage: )
//usage: IF_NOT_LONG_OPTS(
//usage: "\n -r FILE Display last modification time of FILE"
//usage: "\n [-s] TIME Set time to TIME"
//usage: "\n -d TIME Display TIME, not 'now'"
//usage: ) IF_LONG_OPTS(
//usage: "\n -r,--reference FILE Display last modification time of FILE"
//usage: "\n -d,--date TIME Display TIME, not 'now'"
//usage: )
//usage: IF_FEATURE_DATE_ISOFMT(
//usage: "\n -D FMT Use FMT (strptime format) for -d TIME conversion"
//usage: "\n -D FMT FMT (strptime format) for -s/-d TIME conversion"
////////^^^^^^^^^^^^^^^^^^^^^^ busybox invention, not compat
//usage: )
//usage: "\n -r FILE Display last modification time of FILE"
//usage: "\n -R Output RFC-2822 date"
//usage: IF_FEATURE_DATE_ISOFMT(
//usage: "\n -I[SPEC] Output ISO-8601 date"
//usage: "\n SPEC=date (default), hours, minutes, seconds or ns"
//usage: )
//usage: "\n"
//usage: "\nRecognized TIME formats:"
//usage: "\n @seconds_since_1970"
//usage: "\n hh:mm[:ss]"
//usage: "\n [YYYY.]MM.DD-hh:mm[:ss]"
//usage: "\n YYYY-MM-DD hh:mm[:ss]"
@@ -148,8 +136,8 @@ enum {
OPT_UTC = (1 << 2), /* u */
OPT_DATE = (1 << 3), /* d */
OPT_REFERENCE = (1 << 4), /* r */
OPT_TIMESPEC = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
OPT_ISO8601 = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
OPT_STR2DT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
};
#if ENABLE_LONG_OPTS
@@ -171,12 +159,6 @@ static const char date_longopts[] ALIGN1 =
* - after xasprintf we use other xfuncs
*/
static void maybe_set_utc(int opt)
{
if (opt & OPT_UTC)
putenv((char*)"TZ=UTC0");
}
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int date_main(int argc UNUSED_PARAM, char **argv)
{
@@ -184,7 +166,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
struct tm tm_time;
char buf_fmt_dt2str[64];
unsigned opt;
int ifmt = -1;
int isofmt = -1;
char *date_str;
char *fmt_dt2str;
char *fmt_str2dt;
@@ -203,15 +185,16 @@ int date_main(int argc UNUSED_PARAM, char **argv)
);
argv += optind;
maybe_set_utc(opt);
if (opt & OPT_UTC)
putenv((char*)"TZ=UTC0");
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_TIMESPEC)) {
ifmt = 0; /* default is date */
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_ISO8601)) {
isofmt = 0; /* default is date */
if (isofmt_arg) {
static const char isoformats[] ALIGN1 =
"date\0""hours\0""minutes\0""seconds\0"; /* ns? */
ifmt = index_in_substrings(isoformats, isofmt_arg);
if (ifmt < 0)
"date\0""hours\0""minutes\0""seconds\0ns\0";
isofmt = index_in_substrings(isoformats, isofmt_arg);
if (isofmt < 0)
bb_show_usage();
}
}
@@ -221,7 +204,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
fmt_dt2str = &argv[0][1]; /* skip over the '+' */
argv++;
}
if (!(opt & (OPT_SET | OPT_DATE))) {
if (!(opt & (OPT_SET | OPT_DATE))) { /* neither -s TIME nor -d TIME? */
opt |= OPT_SET;
date_str = argv[0]; /* can be NULL */
if (date_str) {
@@ -289,7 +272,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
tm_time.tm_hour = 0;
/* Process any date input to UNIX time since 1 Jan 1970 */
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_HINT)) {
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_STR2DT)) {
if (strptime(date_str, fmt_str2dt, &tm_time) == NULL)
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
} else {
@@ -315,24 +298,34 @@ int date_main(int argc UNUSED_PARAM, char **argv)
if (fmt_dt2str == NULL) {
int i;
fmt_dt2str = buf_fmt_dt2str;
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds */
if (ENABLE_FEATURE_DATE_ISOFMT && isofmt >= 0) {
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds 4:ns*/
strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S");
i = 8 + 3 * ifmt;
if (ifmt != 0) {
/* TODO: if (ifmt==4) i += sprintf(&fmt_dt2str[i], ",%09u", nanoseconds); */
format_utc:
fmt_dt2str[i++] = '%';
fmt_dt2str[i++] = (opt & OPT_UTC) ? 'Z' : 'z';
i = 8 + 3 * isofmt;
if (isofmt != 0) {
int n;
if (isofmt == 4) {
i -= 3;
i += sprintf(&fmt_dt2str[i], ",%09u", (unsigned)ts.tv_nsec);
}
/* %z prints "+hhmm" timezone, but coreutils-8.30 prints "+hh:mm"! */
/* ...therefore this atrocity: */
n = strftime(&fmt_dt2str[i], 8, "%z", &tm_time);
i += n;
if (n == 5 && (fmt_dt2str[i-5] == '+' || fmt_dt2str[i-5] == '-')) {
/* "mm" -> ":mm" */
fmt_dt2str[i ] = fmt_dt2str[i - 1];
fmt_dt2str[i - 1] = fmt_dt2str[i - 2];
fmt_dt2str[i - 2] = ':';
i++;
}
}
fmt_dt2str[i] = '\0';
} else if (opt & OPT_RFC2822) {
/* -R. undo busybox.c setlocale */
if (ENABLE_LOCALE_SUPPORT)
setlocale(LC_TIME, "C");
strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S ");
i = sizeof("%a, %d %b %Y %H:%M:%S ")-1;
goto format_utc;
fmt_dt2str = (char*)"%a, %d %b %Y %H:%M:%S %z";
} else { /* default case */
fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
}
@@ -384,10 +377,6 @@ int date_main(int argc UNUSED_PARAM, char **argv)
/* With no format string, just print a blank line */
date_buf[0] = '\0';
} else {
/* Handle special conversions */
if (is_prefixed_with(fmt_dt2str, "%f")) {
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
}
/* Generate output string */
strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
}
+80 -31
View File
@@ -59,7 +59,7 @@
//usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]\n"
//usage: IF_FEATURE_DD_IBS_OBS(
//usage: " [conv=notrunc|noerror|sync|fsync]\n"
//usage: " [iflag=skip_bytes|fullblock] [oflag=seek_bytes|append]"
//usage: " [iflag=skip_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]"
//usage: )
//usage:#define dd_full_usage "\n\n"
//usage: "Copy a file with converting and formatting\n"
@@ -82,9 +82,11 @@
//usage: "\n conv=fsync Physically write data out before finishing"
//usage: "\n conv=swab Swap every pair of bytes"
//usage: "\n iflag=skip_bytes skip=N is in bytes"
//usage: "\n iflag=fullblock Read full blocks"
//usage: "\n oflag=seek_bytes seek=N is in bytes"
//usage: "\n oflag=append Open output file in append mode"
//usage: "\n iflag=direct O_DIRECT input"
//usage: "\n oflag=direct O_DIRECT output"
//usage: "\n iflag=fullblock Read full blocks"
//usage: "\n oflag=append Open output in append mode"
//usage: )
//usage: IF_FEATURE_DD_STATUS(
//usage: "\n status=noxfer Suppress rate output"
@@ -137,16 +139,18 @@ enum {
FLAG_IFLAG_SHIFT = 5,
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_IDIRECT = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of input flags */
/* start of output flags */
FLAG_OFLAG_SHIFT = 7,
FLAG_SEEK_BYTES = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_APPEND = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_OFLAG_SHIFT = 8,
FLAG_SEEK_BYTES = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_APPEND = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_ODIRECT = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of output flags */
FLAG_TWOBUFS = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 10,
FLAG_STATUS_NONE = 1 << 11,
FLAG_STATUS_NOXFER = 1 << 12,
FLAG_TWOBUFS = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 12,
FLAG_STATUS_NONE = 1 << 13,
FLAG_STATUS_NOXFER = 1 << 14,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -192,12 +196,50 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
#endif
}
#if ENABLE_FEATURE_DD_IBS_OBS
static int clear_O_DIRECT(int fd)
{
if (errno == EINVAL) {
int fl = fcntl(fd, F_GETFL);
if (fl & O_DIRECT) {
fcntl(fd, F_SETFL, fl & ~O_DIRECT);
return 1;
}
}
return 0;
}
#endif
static ssize_t dd_read(void *ibuf, size_t ibs)
{
ssize_t n;
#if ENABLE_FEATURE_DD_IBS_OBS
read_again:
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, ibs);
else
#endif
n = safe_read(ifd, ibuf, ibs);
#if ENABLE_FEATURE_DD_IBS_OBS
if (n < 0 && (G.flags & FLAG_IDIRECT) && clear_O_DIRECT(ifd))
goto read_again;
#endif
return n;
}
static bool write_and_stats(const void *buf, size_t len, size_t obs,
const char *filename)
{
ssize_t n;
IF_FEATURE_DD_IBS_OBS(write_again:)
n = full_write(ofd, buf, len);
#if ENABLE_FEATURE_DD_IBS_OBS
if (n < 0 && (G.flags & FLAG_ODIRECT) && clear_O_DIRECT(ofd))
goto write_again;
#endif
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
if (n > 0)
G.total_bytes += n;
@@ -254,6 +296,14 @@ static int parse_comma_flags(char *val, const char *words, const char *error_in)
}
#endif
static void *alloc_buf(size_t size)
{
/* Important for "{i,o}flag=direct" - buffers must be page aligned */
if (size >= bb_getpagesize())
return xmmap_anon(size);
return xmalloc(size);
}
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dd_main(int argc UNUSED_PARAM, char **argv)
{
@@ -267,9 +317,9 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
static const char conv_words[] ALIGN1 =
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
static const char iflag_words[] ALIGN1 =
"skip_bytes\0""fullblock\0";
"skip_bytes\0""fullblock\0""direct\0";
static const char oflag_words[] ALIGN1 =
"seek_bytes\0append\0";
"seek_bytes\0append\0""direct\0";
#endif
#if ENABLE_FEATURE_DD_STATUS
static const char status_words[] ALIGN1 =
@@ -310,7 +360,9 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
//swab swap every pair of input bytes: will abort on non-even reads
OP_iflag_skip_bytes,
OP_iflag_fullblock,
OP_iflag_direct,
OP_oflag_seek_bytes,
OP_oflag_direct,
#endif
};
smallint exitcode = EXIT_FAILURE;
@@ -426,13 +478,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
#endif
} /* end of "for (argv[i])" */
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
ibuf = xmalloc(ibs);
ibuf = alloc_buf(ibs);
obuf = ibuf;
#if ENABLE_FEATURE_DD_IBS_OBS
if (ibs != obs) {
G.flags |= FLAG_TWOBUFS;
obuf = xmalloc(obs);
obuf = alloc_buf(obs);
}
#endif
@@ -444,7 +495,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
#endif
if (infile) {
xmove_fd(xopen(infile, O_RDONLY), ifd);
int iflag = O_RDONLY;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_IDIRECT)
iflag |= O_DIRECT;
#endif
xmove_fd(xopen(infile, iflag), ifd);
} else {
infile = bb_msg_standard_input;
}
@@ -455,7 +511,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
oflag |= O_TRUNC;
if (G.flags & FLAG_APPEND)
oflag |= O_APPEND;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_ODIRECT)
oflag |= O_DIRECT;
#endif
xmove_fd(xopen(outfile, oflag), ofd);
if (seek && !(G.flags & FLAG_NOTRUNC)) {
@@ -478,13 +537,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
do {
ssize_t n;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, blocksz);
else
#endif
n = safe_read(ifd, ibuf, blocksz);
ssize_t n = dd_read(ibuf, blocksz);
if (n < 0)
goto die_infile;
if (n == 0)
@@ -499,13 +552,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
}
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
ssize_t n;
#if ENABLE_FEATURE_DD_IBS_OBS
if (G.flags & FLAG_FULLBLOCK)
n = full_read(ifd, ibuf, ibs);
else
#endif
n = safe_read(ifd, ibuf, ibs);
ssize_t n = dd_read(ibuf, ibs);
if (n == 0)
break;
if (n < 0) {
@@ -600,11 +647,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (!ENABLE_FEATURE_DD_STATUS || !(G.flags & FLAG_STATUS_NONE))
dd_output_status(0);
#if 0 /* can't just free(), they can be mmap()ed */
if (ENABLE_FEATURE_CLEAN_UP) {
free(obuf);
if (G.flags & FLAG_TWOBUFS)
free(ibuf);
}
#endif
return exitcode;
}
+132 -77
View File
@@ -19,6 +19,7 @@
//usage: "Print prime factors"
#include "libbb.h"
#include "common_bufsiz.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
@@ -42,9 +43,116 @@ typedef unsigned long half_t;
#error Cant find an integer type which is half as wide as ullong
#endif
/* The trial divisor increment wheel. Use it to skip over divisors that
* are composites of 2, 3, 5, 7, or 11.
* Larger wheels improve sieving only slightly, but quickly grow in size
* (adding just one prime, 13, results in 5766 element sieve).
*/
#define R(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
(((uint64_t)(a<<0) | (b<<3) | (c<<6) | (d<<9) | (e<<12) | (f<<15) | (g<<18) | (h<<21) | (i<<24) | (j<<27)) << 1) | \
(((uint64_t)(A<<0) | (B<<3) | (C<<6) | (D<<9) | (E<<12) | (F<<15) | (G<<18) | (H<<21) | (I<<24) | (J<<27)) << 31)
#define P(a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J) \
R( (a/2),(b/2),(c/2),(d/2),(e/2),(f/2),(g/2),(h/2),(i/2),(j/2), \
(A/2),(B/2),(C/2),(D/2),(E/2),(F/2),(G/2),(H/2),(I/2),(J/2) )
static const uint64_t packed_wheel[] = {
/*1, 2, 2, 4, 2,*/
P( 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4), //01
P( 2, 4, 2, 4,14, 4, 6, 2,10, 2, 6, 6, 4, 2, 4, 6, 2,10, 2, 4), //02
P( 2,12,10, 2, 4, 2, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 6, 4), //03
P( 6, 8, 4, 2, 4, 6, 8, 6,10, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2), //04
P( 6, 4, 2, 6,10, 2,10, 2, 4, 2, 4, 6, 8, 4, 2, 4,12, 2, 6, 4), //05
P( 2, 6, 4, 6,12, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6,10, 2), //06
P( 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 6, 6, 2, 6, 6, 4, 6), //07
P( 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6, 4, 6, 2, 4, 6), //08
P( 8, 6, 4, 2,10, 2, 6, 4, 2, 4, 2,10, 2,10, 2, 4, 2, 4, 8, 6), //09
P( 4, 2, 4, 6, 6, 2, 6, 4, 8, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4), //10
P( 6, 6, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2,10, 2,10, 2), //11
P( 6, 4, 6, 2, 6, 4, 2, 4, 6, 6, 8, 4, 2, 6,10, 8, 4, 2, 4, 2), //12
P( 4, 8,10, 6, 2, 4, 8, 6, 6, 4, 2, 4, 6, 2, 6, 4, 6, 2,10, 2), //13
P(10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 6, 6, 4, 6, 8), //14
P( 4, 2, 4, 2, 4, 8, 6, 4, 8, 4, 6, 2, 6, 6, 4, 2, 4, 6, 8, 4), //15
P( 2, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2,10, 2, 4, 6, 8, 6, 4, 2), //16
P( 6, 4, 6, 8, 4, 6, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 6), //17
P( 6, 2, 6, 6, 4, 2,10, 2,10, 2, 4, 2, 4, 6, 2, 6, 4, 2,10, 6), //18
P( 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2,12, 6, 4, 6, 2, 4, 6, 2), //19
P(12, 4, 2, 4, 8, 6, 4, 2, 4, 2,10, 2,10, 6, 2, 4, 6, 2, 6, 4), //20
P( 2, 4, 6, 6, 2, 6, 4, 2,10, 6, 8, 6, 4, 2, 4, 8, 6, 4, 6, 2), //21
P( 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 2, 4, 2,10,12, 2, 4, 2,10), //22
P( 2, 6, 4, 2, 4, 6, 6, 2,10, 2, 6, 4,14, 4, 2, 4, 2, 4, 8, 6), //23
P( 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4,12, 2,12), //24
};
#undef P
#undef R
#define WHEEL_START 5
#define WHEEL_SIZE (5 + 24 * 20)
#define square_count (((uint8_t*)&bb_common_bufsiz1)[0])
#define wheel_tab (((uint8_t*)&bb_common_bufsiz1) + 1)
/*
* Why, you ask?
* plain byte array:
* function old new delta
* wheel_tab - 485 +485
* 3-bit-packed insanity:
* packed_wheel - 192 +192
* factor_main 108 171 +63
*/
static void unpack_wheel(void)
{
int i;
uint8_t *p;
setup_common_bufsiz();
wheel_tab[0] = 1;
wheel_tab[1] = 2;
wheel_tab[2] = 2;
wheel_tab[3] = 4;
wheel_tab[4] = 2;
p = &wheel_tab[5];
for (i = 0; i < ARRAY_SIZE(packed_wheel); i++) {
uint64_t v = packed_wheel[i];
while ((v & 0xe) != 0) {
*p = v & 0xe;
//printf("%2u,", *p);
p++;
v >>= 3;
}
//printf("\n");
}
}
/* Prevent inlining, factorize() needs all help it can get with reducing register pressure */
static NOINLINE void print_w(wide_t n)
{
unsigned rep = square_count;
do
printf(" %llu", n);
while (--rep != 0);
}
static NOINLINE void print_h(half_t n)
{
print_w(n);
}
static void factorize(wide_t N);
static half_t isqrt_odd(wide_t N)
{
half_t s = isqrt(N);
/* s^2 is <= N, (s+1)^2 > N */
/* If s^2 in fact is EQUAL to N, it's very lucky.
* Examples:
* factor 18446743988964486098 = 2 * 3037000493 * 3037000493
* factor 18446743902517389507 = 3 * 2479700513 * 2479700513
*/
if ((wide_t)s * s == N) {
/* factorize sqrt(N), printing each factor twice */
square_count *= 2;
factorize(s);
/* Let caller know we recursed */
return 0;
}
/* Subtract 1 from even s, odd s won't change: */
/* (doesnt work for zero, but we know that s != 0 here) */
s = (s - 1) | 1;
@@ -53,43 +161,20 @@ static half_t isqrt_odd(wide_t N)
static NOINLINE void factorize(wide_t N)
{
unsigned w;
half_t factor;
half_t max_factor;
// unsigned count3;
// unsigned count5;
// unsigned count7;
// ^^^^^^^^^^^^^^^ commented-out simple sieving code (easier to grasp).
// Faster sieving, using one word for potentially up to 6 counters:
// count upwards in each mask, counter "triggers" when it sets its mask to "100[0]..."
// 10987654321098765432109876543210 - bits 31-0 in 32-bit word
// 17777713333311111777775555333 - bit masks for counters for primes 3,5,7,11,13,17
// 100000100001000010001001 - value for adding 1 to each mask
// 10000010000010000100001000100 - value for checking that any mask reached msb
enum {
SHIFT_3 = 1 << 0,
SHIFT_5 = 1 << 3,
SHIFT_7 = 1 << 7,
INCREMENT_EACH = SHIFT_3 | SHIFT_5 | SHIFT_7,
MULTIPLE_OF_3 = 1 << 2,
MULTIPLE_OF_5 = 1 << 6,
MULTIPLE_OF_7 = 1 << 11,
MULTIPLE_DETECTED = MULTIPLE_OF_3 | MULTIPLE_OF_5 | MULTIPLE_OF_7,
};
unsigned sieve_word;
if (N < 4)
goto end;
while (!(N & 1)) {
printf(" 2");
N >>= 1;
}
/* The code needs to be optimized for the case where
* there are large prime factors. For example,
* this is not hard:
* 8262075252869367027 = 3 7 17 23 47 101 113 127 131 137 823
* (the largest factor to test is only ~sqrt(823) = 28)
* (the largest divisor to test for largest factor 823
* is only ~sqrt(823) = 28, the entire factorization needs
* only ~33 trial divisions)
* but this is:
* 18446744073709551601 = 53 348051774975651917
* the last factor requires testing up to
@@ -98,70 +183,37 @@ static NOINLINE void factorize(wide_t N)
* factor 18446744073709551557 (0xffffffffffffffc5).
*/
max_factor = isqrt_odd(N);
// count3 = 3;
// count5 = 6;
// count7 = 9;
sieve_word = 0
/* initial count for SHIFT_n is (n-1)/2*3: */
+ (MULTIPLE_OF_3 - 3 * SHIFT_3)
+ (MULTIPLE_OF_5 - 6 * SHIFT_5)
+ (MULTIPLE_OF_7 - 9 * SHIFT_7)
//+ (MULTIPLE_OF_11 - 15 * SHIFT_11)
//+ (MULTIPLE_OF_13 - 18 * SHIFT_13)
//+ (MULTIPLE_OF_17 - 24 * SHIFT_17)
;
factor = 3;
if (!max_factor)
return; /* square was detected and recursively factored */
factor = 2;
w = 0;
for (;;) {
half_t fw;
/* The division is the most costly part of the loop.
* On 64bit CPUs, takes at best 12 cycles, often ~20.
*/
while ((N % factor) == 0) { /* not likely */
N = N / factor;
printf(" %"HALF_FMT"u", factor);
print_h(factor);
max_factor = isqrt_odd(N);
if (!max_factor)
return; /* square was detected */
}
next_factor:
if (factor >= max_factor)
break;
factor += 2;
/* Rudimentary wheel sieving: skip multiples of 3, 5 and 7:
* Every third odd number is divisible by three and thus isn't a prime:
* 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47...
* ^ ^ ^ ^ ^ ^ ^ _ ^ ^ _ ^ ^ ^ ^
* (^ = primes, _ = would-be-primes-if-not-divisible-by-5)
* The numbers with space under them are excluded by sieve 3.
*/
// count7--;
// count5--;
// count3--;
// if (count3 && count5 && count7)
// continue;
sieve_word += INCREMENT_EACH;
if (!(sieve_word & MULTIPLE_DETECTED))
fw = factor + wheel_tab[w];
if (fw < factor)
break; /* overflow */
factor = fw;
w++;
if (w < WHEEL_SIZE)
continue;
/*
* "factor" is multiple of 3 33% of the time (count3 reached 0),
* else, multiple of 5 13% of the time,
* else, multiple of 7 7.6% of the time.
* Cumulatively, with 3,5,7 sieving we are here 54.3% of the time.
*/
// if (count3 == 0)
// count3 = 3;
if (sieve_word & MULTIPLE_OF_3)
sieve_word -= SHIFT_3 * 3;
// if (count5 == 0)
// count5 = 5;
if (sieve_word & MULTIPLE_OF_5)
sieve_word -= SHIFT_5 * 5;
// if (count7 == 0)
// count7 = 7;
if (sieve_word & MULTIPLE_OF_7)
sieve_word -= SHIFT_7 * 7;
goto next_factor;
w = WHEEL_START;
}
end:
if (N > 1)
printf(" %llu", N);
print_w(N);
bb_putchar('\n');
}
@@ -176,12 +228,15 @@ static void factorize_numstr(const char *numstr)
if (errno)
bb_show_usage();
printf("%llu:", N);
square_count = 1;
factorize(N);
}
int factor_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int factor_main(int argc UNUSED_PARAM, char **argv)
{
unpack_wheel();
//// coreutils has undocumented option ---debug (three dashes)
//getopt32(argv, "");
//argv += optind;
+1 -1
View File
@@ -33,7 +33,7 @@
/* BB_AUDIT SUSv3 compliant. */
//usage:#define id_trivial_usage
//usage: "[OPTIONS] [USER]"
//usage: "[-ugGnr"IF_SELINUX("Z")"] [USER]"
//usage:#define id_full_usage "\n\n"
//usage: "Print information about USER or the current user\n"
//usage: IF_SELINUX(
+2 -2
View File
@@ -21,14 +21,14 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/ln.html */
//usage:#define ln_trivial_usage
//usage: "[OPTIONS] TARGET... LINK|DIR"
//usage: "[-sfnbtv] [-S SUF] TARGET... LINK|DIR"
//usage:#define ln_full_usage "\n\n"
//usage: "Create a link LINK or DIR/TARGET to the specified TARGET(s)\n"
//usage: "\n -s Make symlinks instead of hardlinks"
//usage: "\n -f Remove existing destinations"
//usage: "\n -n Don't dereference symlinks - treat like normal file"
//usage: "\n -b Make a backup of the target (if exists) before link operation"
//usage: "\n -S suf Use suffix instead of ~ when making backup files"
//usage: "\n -S SUF Use suffix instead of ~ when making backup files"
//usage: "\n -T Treat LINK as a file, not DIR"
//usage: "\n -v Verbose"
//usage:
+1 -1
View File
@@ -117,8 +117,8 @@
//usage: "\n -c Check sums against list in FILEs"
//usage: "\n -s Don't output anything, status code shows success"
//usage: "\n -w Warn about improperly formatted checksum lines"
//usage: "\n -a BITS 224 (default), 256, 384, 512"
//usage: )
//usage: "\n -a BITS 224 (default), 256, 384, 512"
//FIXME: GNU coreutils 8.25 has no -s option, it has only these two long opts:
// --quiet don't print OK for each successfully verified file
+1 -1
View File
@@ -27,7 +27,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
//usage:#define mkdir_trivial_usage
//usage: "[OPTIONS] DIRECTORY..."
//usage: "[-m MODE] [-p] DIRECTORY..."
//usage:#define mkdir_full_usage "\n\n"
//usage: "Create DIRECTORY\n"
//usage: "\n -m MODE Mode"
+1 -1
View File
@@ -19,7 +19,7 @@
//usage:#define nl_full_usage "\n\n"
//usage: "Write FILEs to standard output with line numbers added\n"
//usage: "\n -b STYLE Which lines to number - a: all, t: nonempty, n: none"
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TODO: support "pBRE": number only lines thatmatch regexp BRE"
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TODO: support "pBRE": number only lines that match regexp BRE"
////usage: "\n -f STYLE footer lines"
////usage: "\n -h STYLE header lines"
////usage: "\n -d CC use CC for separating logical pages"
+2 -2
View File
@@ -627,7 +627,7 @@ decode_one_format(const char *s_orig, const char *s, struct tspec *tspec)
bytes_to_unsigned_dec_digits,
bytes_to_hex_digits,
};
static const char doux_fmtstring[][sizeof(" %%0%u%s")] = {
static const char doux_fmtstring[][sizeof(" %%0%u%s")] ALIGN1 = {
" %%%u%s",
" %%0%u%s",
" %%%u%s",
@@ -1148,7 +1148,7 @@ dump_strings(off_t address, off_t end_offset)
static int
parse_old_offset(const char *s, off_t *offset)
{
static const struct suffix_mult Bb[] = {
static const struct suffix_mult Bb[] ALIGN_SUFFIX = {
{ "B", 1024 },
{ "b", 512 },
{ "", 0 }
+1 -1
View File
@@ -18,7 +18,7 @@
//kbuild:lib-$(CONFIG_PASTE) += paste.o
//usage:#define paste_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage: "[-d LIST] [-s] [FILE]..."
//usage:#define paste_full_usage "\n\n"
//usage: "Paste lines from each input file, separated with tab\n"
//usage: "\n -d LIST Use delimiters from LIST, not tab"
+1 -1
View File
@@ -20,7 +20,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/rmdir.html */
//usage:#define rmdir_trivial_usage
//usage: "[OPTIONS] DIRECTORY..."
//usage: "[-p] DIRECTORY..."
//usage:#define rmdir_full_usage "\n\n"
//usage: "Remove DIRECTORY if it is empty\n"
//usage: "\n -p Include parents"
+1 -1
View File
@@ -43,7 +43,7 @@
//usage:#define sort_trivial_usage
//usage: "[-nru"
//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR")
//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k START[.OFS][OPTS][,END[.OFS][OPTS]] [-t CHAR")
//usage: "] [FILE]..."
//usage:#define sort_full_usage "\n\n"
//usage: "Sort lines of text\n"
+1 -1
View File
@@ -44,7 +44,7 @@
#include "common_bufsiz.h"
#if ENABLE_FEATURE_SPLIT_FANCY
static const struct suffix_mult split_suffixes[] = {
static const struct suffix_mult split_suffixes[] ALIGN_SUFFIX = {
{ "b", 512 },
{ "k", 1024 },
{ "m", 1024*1024 },
+2 -3
View File
@@ -31,7 +31,6 @@
//config: bool "Enable display of filesystem status (-f)"
//config: default y
//config: depends on STAT
//config: select PLATFORM_LINUX # statfs()
//config: help
//config: Without this, stat will not support the '-f' option to display
//config: information about filesystem status.
@@ -41,7 +40,7 @@
//kbuild:lib-$(CONFIG_STAT) += stat.o
//usage:#define stat_trivial_usage
//usage: "[OPTIONS] FILE..."
//usage: "[-lt"IF_FEATURE_STAT_FILESYSTEM("f")"] "IF_FEATURE_STAT_FORMAT("[-c FMT] ")"FILE..."
//usage:#define stat_full_usage "\n\n"
//usage: "Display file"
//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
@@ -209,7 +208,7 @@ FS_TYPE(0x62656572, "sysfs")
static const char *human_fstype(uint32_t f_type)
{
# define FS_TYPE(type, name) type,
static const uint32_t fstype[] = {
static const uint32_t fstype[] ALIGN4 = {
FS_TYPE_LIST
};
# undef FS_TYPE
+2 -2
View File
@@ -487,7 +487,7 @@ static const char mode_name[] ALIGN1 =
#undef MI_ENTRY
#define MI_ENTRY(N,T,F,B,M) { T, F, M, B },
static const struct mode_info mode_info[] = {
static const struct mode_info mode_info[] ALIGN4 = {
/* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
@@ -905,7 +905,7 @@ static void display_window_size(int fancy)
}
}
static const struct suffix_mult stty_suffixes[] = {
static const struct suffix_mult stty_suffixes[] ALIGN_SUFFIX = {
{ "b", 512 },
{ "k", 1024 },
{ "B", 1024 },
+83 -1
View File
@@ -76,6 +76,8 @@
//usage: "1\n"
#include "libbb.h"
#include <regex.h>
#include <fnmatch.h>
/* This is a NOFORK applet. Be very careful! */
@@ -146,6 +148,14 @@
#define TEST_DEBUG 0
#if ENABLE_TEST2 \
|| (ENABLE_ASH_BASH_COMPAT && ENABLE_ASH_TEST) \
|| (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST)
# define BASH_TEST2 1
#else
# define BASH_TEST2 0
#endif
enum token {
EOI,
@@ -184,6 +194,10 @@ enum token {
STRLT,
STRGT,
#if BASH_TEST2
REGEX,
#endif
INTEQ, /* int ops */
INTNE,
INTGE,
@@ -257,6 +271,9 @@ static const char *const TOKSTR[] = {
"STRNE",
"STRLT",
"STRGT",
#if BASH_TEST2
"REGEX",
#endif
"INTEQ",
"INTNE",
"INTGE",
@@ -289,7 +306,7 @@ struct operator_t {
unsigned char op_num, op_type;
};
static const struct operator_t ops_table[] = {
static const struct operator_t ops_table[] ALIGN2 = {
{ /* "-r" */ FILRD , UNOP },
{ /* "-w" */ FILWR , UNOP },
{ /* "-x" */ FILEX , UNOP },
@@ -320,6 +337,9 @@ static const struct operator_t ops_table[] = {
{ /* "!=" */ STRNE , BINOP },
{ /* "<" */ STRLT , BINOP },
{ /* ">" */ STRGT , BINOP },
#if BASH_TEST2
{ /* "=~" */ REGEX , BINOP },
#endif
{ /* "-eq"*/ INTEQ , BINOP },
{ /* "-ne"*/ INTNE , BINOP },
{ /* "-ge"*/ INTGE , BINOP },
@@ -332,6 +352,10 @@ static const struct operator_t ops_table[] = {
{ /* "!" */ UNOT , BUNOP },
{ /* "-a" */ BAND , BBINOP },
{ /* "-o" */ BOR , BBINOP },
#if BASH_TEST2
{ /* "&&" */ BAND , BBINOP },
{ /* "||" */ BOR , BBINOP },
#endif
{ /* "(" */ LPAREN , PAREN },
{ /* ")" */ RPAREN , PAREN },
};
@@ -365,6 +389,9 @@ static const char ops_texts[] ALIGN1 =
"!=" "\0"
"<" "\0"
">" "\0"
#if BASH_TEST2
"=~" "\0"
#endif
"-eq" "\0"
"-ne" "\0"
"-ge" "\0"
@@ -377,6 +404,10 @@ static const char ops_texts[] ALIGN1 =
"!" "\0"
"-a" "\0"
"-o" "\0"
#if BASH_TEST2
"&&" "\0"
"||" "\0"
#endif
"(" "\0"
")" "\0"
;
@@ -397,6 +428,9 @@ struct test_statics {
const struct operator_t *last_operator;
gid_t *group_array;
int ngroups;
#if BASH_TEST2
bool bash_test2;
#endif
jmp_buf leaving;
};
@@ -408,6 +442,7 @@ extern struct test_statics *const test_ptr_to_statics;
#define last_operator (S.last_operator)
#define group_array (S.group_array )
#define ngroups (S.ngroups )
#define bash_test2 (S.bash_test2 )
#define leaving (S.leaving )
#define INIT_S() do { \
@@ -501,6 +536,20 @@ static enum token check_operator(const char *s)
n = index_in_strings(ops_texts, s);
if (n < 0)
return OPERAND;
#if BASH_TEST2
if (ops_table[n].op_num == REGEX && !bash_test2) {
/* =~ is only for [[ ]] */
return OPERAND;
}
if (ops_table[n].op_num == BAND || ops_table[n].op_num == BOR) {
/* [ ] accepts -a and -o but not && and || */
/* [[ ]] accepts && and || but not -a and -o */
if (bash_test2 == (s[0] == '-'))
return OPERAND;
}
#endif
last_operator = &ops_table[n];
return ops_table[n].op_num;
}
@@ -536,6 +585,29 @@ static int binop(void)
/*if (op->op_num == INTLT)*/
return val1 < val2;
}
#if BASH_TEST2
if (bash_test2) {
if (op->op_num == STREQ) {
val1 = fnmatch(opnd2, opnd1, 0);
return val1 == 0;
}
if (op->op_num == STRNE) {
val1 = fnmatch(opnd2, opnd1, 0);
return val1 != 0;
}
if (op->op_num == REGEX) {
regex_t re_buffer;
memset(&re_buffer, 0, sizeof(re_buffer));
if (regcomp(&re_buffer, opnd2, REG_EXTENDED)) { // REG_NEWLINE?
/* Bad regex */
longjmp(leaving, 2); /* [[ a =~ * ]]; echo $? - prints 2 (silently, no error msg) */
}
val1 = regexec(&re_buffer, opnd1, 0, NULL, 0);
regfree(&re_buffer);
return val1 == 0;
}
}
#endif
if (is_str_op(op->op_num)) {
val1 = strcmp(opnd1, opnd2);
if (op->op_num == STREQ)
@@ -824,6 +896,9 @@ int test_main(int argc, char **argv)
{
int res;
const char *arg0;
#if BASH_TEST2
bool bt2 = 0;
#endif
arg0 = bb_basename(argv[0]);
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_TEST || ENABLE_HUSH_TEST)
@@ -840,6 +915,9 @@ int test_main(int argc, char **argv)
bb_simple_error_msg("missing ]]");
return 2;
}
#if BASH_TEST2
bt2 = 1;
#endif
}
argv[argc] = NULL;
}
@@ -848,6 +926,10 @@ int test_main(int argc, char **argv)
/* We must do DEINIT_S() prior to returning */
INIT_S();
#if BASH_TEST2
bash_test2 = bt2;
#endif
res = setjmp(leaving);
if (res)
goto ret;
+2 -2
View File
@@ -41,7 +41,7 @@
//usage:#define timeout_trivial_usage
//usage: "[-s SIG] SECS PROG ARGS"
//usage:#define timeout_full_usage "\n\n"
//usage: "Runs PROG. Sends SIG to it if it is not gone in SECS seconds.\n"
//usage: "Run PROG. Send SIG to it if it is not gone in SECS seconds.\n"
//usage: "Default SIG: TERM."
#include "libbb.h"
@@ -105,7 +105,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
grandchild:
/* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
while (1) {
sleep(1);
sleep1();
if (--timeout <= 0)
break;
if (kill(parent, 0)) {
+1 -1
View File
@@ -20,7 +20,7 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */
//usage:#define uniq_trivial_usage
//usage: "[-cdu][-f,s,w N] [INPUT [OUTPUT]]"
//usage: "[-cdui] [-f,s,w N] [INPUT [OUTPUT]]"
//usage:#define uniq_full_usage "\n\n"
//usage: "Discard duplicate lines\n"
//usage: "\n -c Prefix lines by the number of occurrences"
+140 -24
View File
@@ -110,9 +110,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
}
bb_simple_error_msg_and_die("short file");
}
#endif
#if ENABLE_UUDECODE
int uudecode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uudecode_main(int argc UNUSED_PARAM, char **argv)
{
@@ -170,9 +168,11 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
}
#endif
//applet:IF_BASE64(APPLET(base64, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_BASE64) += uudecode.o
//config:config BASE32
//config: bool "base32 (4.9 kb)"
//config: default y
//config: help
//config: Base32 encode and decode
//config:config BASE64
//config: bool "base64 (4.9 kb)"
@@ -180,49 +180,165 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
//config: help
//config: Base64 encode and decode
//usage:#define base32_trivial_usage
//usage: "[-d] [-w COL] [FILE]"
//usage:#define base32_full_usage "\n\n"
//usage: "Base32 encode or decode FILE to standard output"
//usage: "\n -d Decode data"
//usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
////usage: "\n -i When decoding, ignore non-alphabet characters"
//usage:#define base64_trivial_usage
//usage: "[-d] [FILE]"
//usage: "[-d] [-w COL] [FILE]"
//usage:#define base64_full_usage "\n\n"
//usage: "Base64 encode or decode FILE to standard output"
//usage: "\n -d Decode data"
////usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
//usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
////usage: "\n -i When decoding, ignore non-alphabet characters"
#if ENABLE_BASE64
int base64_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int base64_main(int argc UNUSED_PARAM, char **argv)
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_BASE32(APPLET_ODDNAME(base32, baseNUM, BB_DIR_BIN, BB_SUID_DROP, base32))
//applet:IF_BASE64(APPLET_ODDNAME(base64, baseNUM, BB_DIR_BIN, BB_SUID_DROP, base64))
//kbuild:lib-$(CONFIG_BASE64) += uudecode.o
//kbuild:lib-$(CONFIG_BASE32) += uudecode.o
#if ENABLE_BASE32 || ENABLE_BASE64
# if ENABLE_BASE32
static void bb_b32encode(char *p, const void *src, int length)
{
#define tbl bb_uuenc_tbl_base32
const unsigned char *s = src;
/* Transform 5x8 bits to 8x5 bits */
while (length > 0) {
unsigned cur, next;
length--;
cur = *s++;
*p++ = tbl[cur >> 3]; // xxxxx--- -------- -------- -------- --------
cur &= 7;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 2) + (next >> 6)]; // -----xxx xx------ -------- -------- --------
cur = next & 0x3f;
*p++ = tbl[cur >> 1]; // -------- --xxxxx- -------- -------- --------
cur &= 1;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 4) + (next >> 4)]; // -------- -------x xxxx---- -------- --------
cur = next & 0xf;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 1) + (next >> 7)]; // -------- -------- ----xxxx x------- --------
cur = next & 0x7f;
*p++ = tbl[cur >> 2]; // -------- -------- -------- -xxxxx-- --------
cur &= 3;
next = 0;
if (--length >= 0)
next = *s++;
*p++ = tbl[(cur << 3) + (next >> 5)]; // -------- -------- -------- ------xx xxx-----
cur = next & 0x1f;
*p++ = tbl[cur]; // -------- -------- -------- -------- ---xxxxx
}
#undef tbl
/* Zero-terminate */
*p = '\0';
/* Pad as necessary */
length = ((-length) * 3) >> 1; /* -4 => 6 pad chars, -3 => 4, -2 => 3, -1 => 1 */
while (length--) {
*--p = '=';
}
}
# else
void bb_b32encode(char *p, const void *src, int length); /* undefined */
# endif
int baseNUM_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int baseNUM_main(int argc UNUSED_PARAM, char **argv)
{
FILE *src_stream;
unsigned opts;
unsigned col = 76;
opts = getopt32(argv, "^" "d" "\0" "?1"/* 1 arg max*/);
opts = getopt32(argv, "^" "dw:+" "\0" "?1"/* 1 arg max*/, &col);
argv += optind;
if (!argv[0])
*--argv = (char*)"-";
src_stream = xfopen_stdin(argv[0]);
if (opts) {
read_base64(src_stream, stdout, /*flags:*/ (char)EOF);
if (opts & 1) {
/* -d: decode */
int flags = (unsigned char)EOF;
if (ENABLE_BASE32 && (!ENABLE_BASE64 || applet_name[4] == '3'))
flags = ((unsigned char)EOF) | BASE64_32;
read_base64(src_stream, stdout, flags);
} else {
enum {
SRC_BUF_SIZE = 76/4*3, /* This *MUST* be a multiple of 3 */
DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
SRC_BUF_SIZE = 3 * 5 * 32, /* this *MUST* be a multiple of 3 and 5 */
DST_BUF_SIZE = 8 * ((SRC_BUF_SIZE + 4) / 5), /* max growth on encode (base32 case) */
};
char src_buf[SRC_BUF_SIZE];
char dst_buf[DST_BUF_SIZE + 1];
int src_fd = fileno(src_stream);
/* Use one buffer for both input and output:
* encoding reads input "left-to-right",
* it's safe to place source at the end of the buffer and
* overwrite it while encoding, just be careful to have a gap.
*/
char dst_buf[((DST_BUF_SIZE + /*gap:*/ 16) /*round up to 16:*/ | 0xf) + 1];
#define src_buf (dst_buf + sizeof(dst_buf) - SRC_BUF_SIZE)
int src_fd, rem;
src_fd = fileno(src_stream);
rem = 0;
while (1) {
size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE);
if (!size)
break;
if ((ssize_t)size < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
if (size == 0) {
if (rem != 0) bb_putchar('\n');
break;
}
/* Encode the buffer we just read in */
bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3));
bb_putchar('\n');
fflush(stdout);
if (ENABLE_BASE32 && (!ENABLE_BASE64 || applet_name[4] == '3')) {
bb_b32encode(dst_buf, src_buf, size);
size = 8 * ((size + 4) / 5);
} else {
bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
size = 4 * ((size + 2) / 3);
}
if (col == 0) {
fputs(dst_buf, stdout);
} else {
char *result = dst_buf;
if (rem == 0)
rem = col;
while (1) {
int out = size < rem ? size : rem;
rem -= out;
printf(rem != 0 ? "%.*s" : "%.*s\n", out, result);
if (rem != 0)
break;
size -= out;
if (size == 0)
break;
result += out;
rem = col;
}
}
}
#undef src_buf
}
fflush_stdout_and_exit(EXIT_SUCCESS);
+6 -6
View File
@@ -131,12 +131,13 @@ static int bb_alphasort(const void *p1, const void *p2)
return (option_mask32 & OPT_r) ? -r : r;
}
static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUSED_PARAM, int depth)
static int FAST_FUNC act(struct recursive_state *state,
const char *file, struct stat *statbuf)
{
if (depth == 1)
if (state->depth == 0)
return TRUE;
if (depth == 2
if (state->depth == 1
&& ( !(statbuf->st_mode & (S_IFREG | S_IFLNK))
|| invalid_name(file)
|| (!(option_mask32 & OPT_l) && access(file, X_OK) != 0))
@@ -199,9 +200,8 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
ACTION_RECURSE|ACTION_FOLLOWLINKS,
act, /* file action */
act, /* dir action */
NULL, /* user data */
1 /* depth */
);
NULL /* user data */
);
if (!names)
return 0;
+2 -2
View File
@@ -17,9 +17,9 @@
//kbuild:lib-$(CONFIG_WHICH) += which.o
//usage:#define which_trivial_usage
//usage: "[COMMAND]..."
//usage: "COMMAND..."
//usage:#define which_full_usage "\n\n"
//usage: "Locate a COMMAND"
//usage: "Locate COMMAND"
//usage:
//usage:#define which_example_usage
//usage: "$ which login\n"
+1 -1
View File
@@ -127,7 +127,7 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f
/* Print file attributes on an ext2 file system */
const uint32_t e2attr_flags_value[] = {
const uint32_t e2attr_flags_value[] ALIGN4 = {
#ifdef ENABLE_COMPRESSION
EXT2_COMPRBLK_FL,
EXT2_DIRTY_FL,
+1 -1
View File
@@ -480,7 +480,7 @@ static int wait_one(int flags)
* time to set up the signal handler
*/
if (inst2->start_time >= time(NULL) - 1)
sleep(1);
sleep1();
kill(inst2->pid, SIGUSR1);
inst2->flags |= FLAG_PROGRESS;
break;
-1
View File
@@ -12,7 +12,6 @@
//config:config LSATTR
//config: bool "lsattr (5.5 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: lsattr lists the file attributes on a second extended file system.
+39 -15
View File
@@ -405,7 +405,7 @@ static const char tokenlist[] ALIGN1 =
#define OC_B OC_BUILTIN
static const uint32_t tokeninfo[] = {
static const uint32_t tokeninfo[] ALIGN4 = {
0,
0,
OC_REGEXP,
@@ -1763,12 +1763,34 @@ static void fsrealloc(int size)
nfields = size;
}
static int regexec1_nonempty(const regex_t *preg, const char *s, regmatch_t pmatch[])
{
int r = regexec(preg, s, 1, pmatch, 0);
if (r == 0 && pmatch[0].rm_eo == 0) {
/* For example, happens when FS can match
* an empty string (awk -F ' *'). Logically,
* this should split into one-char fields.
* However, gawk 5.0.1 searches for first
* _non-empty_ separator string match:
*/
size_t ofs = 0;
do {
ofs++;
if (!s[ofs])
return REG_NOMATCH;
regexec(preg, s + ofs, 1, pmatch, 0);
} while (pmatch[0].rm_eo == 0);
pmatch[0].rm_so += ofs;
pmatch[0].rm_eo += ofs;
}
return r;
}
static int awk_split(const char *s, node *spl, char **slist)
{
int l, n;
int n;
char c[4];
char *s1;
regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
/* in worst case, each char would be a separate field */
*slist = s1 = xzalloc(strlen(s) * 2 + 3);
@@ -1785,29 +1807,31 @@ static int awk_split(const char *s, node *spl, char **slist)
return n; /* "": zero fields */
n++; /* at least one field will be there */
do {
int l;
regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
l = strcspn(s, c+2); /* len till next NUL or \n */
if (regexec(icase ? spl->r.ire : spl->l.re, s, 1, pmatch, 0) == 0
if (regexec1_nonempty(icase ? spl->r.ire : spl->l.re, s, pmatch) == 0
&& pmatch[0].rm_so <= l
) {
/* if (pmatch[0].rm_eo == 0) ... - impossible */
l = pmatch[0].rm_so;
if (pmatch[0].rm_eo == 0) {
l++;
pmatch[0].rm_eo++;
}
n++; /* we saw yet another delimiter */
} else {
pmatch[0].rm_eo = l;
if (s[l])
pmatch[0].rm_eo++;
}
memcpy(s1, s, l);
/* make sure we remove *all* of the separator chars */
do {
s1[l] = '\0';
} while (++l < pmatch[0].rm_eo);
nextword(&s1);
s1 = mempcpy(s1, s, l);
*s1++ = '\0';
s += pmatch[0].rm_eo;
} while (*s);
/* echo a-- | awk -F-- '{ print NF, length($NF), $NF }'
* should print "2 0 ":
*/
*s1 = '\0';
return n;
}
if (c[0] == '\0') { /* null split */
@@ -2011,7 +2035,7 @@ static int ptest(node *pattern)
static int awk_getline(rstream *rsm, var *v)
{
char *b;
regmatch_t pmatch[2];
regmatch_t pmatch[2]; // TODO: why [2]? [1] is enough...
int size, a, p, pp = 0;
int fd, so, eo, r, rp;
char c, *m, *s;
+11 -11
View File
@@ -803,11 +803,11 @@ struct dlist {
};
/* This function adds a filename to dl, the directory listing. */
static int FAST_FUNC add_to_dirlist(const char *filename,
struct stat *sb UNUSED_PARAM,
void *userdata, int depth UNUSED_PARAM)
static int FAST_FUNC add_to_dirlist(struct recursive_state *state,
const char *filename,
struct stat *sb UNUSED_PARAM)
{
struct dlist *const l = userdata;
struct dlist *const l = state->userData;
const char *file = filename + l->len;
while (*file == '/')
file++;
@@ -820,12 +820,12 @@ static int FAST_FUNC add_to_dirlist(const char *filename,
/* If recursion is not set, this function adds the directory
* to the list and prevents recursive_action from recursing into it.
*/
static int FAST_FUNC skip_dir(const char *filename,
struct stat *sb, void *userdata,
int depth)
static int FAST_FUNC skip_dir(struct recursive_state *state,
const char *filename,
struct stat *sb)
{
if (!(option_mask32 & FLAG(r)) && depth) {
add_to_dirlist(filename, sb, userdata, depth);
if (!(option_mask32 & FLAG(r)) && state->depth) {
add_to_dirlist(state, filename, sb);
return SKIP;
}
if (!(option_mask32 & FLAG(N))) {
@@ -833,7 +833,7 @@ static int FAST_FUNC skip_dir(const char *filename,
* which do not exist on the "other side".
* Testcase: diff -r /tmp /
* (it would recurse deep into /proc without this code) */
struct dlist *const l = userdata;
struct dlist *const l = state->userData;
filename += l->len;
if (filename[0]) {
struct stat osb;
@@ -868,7 +868,7 @@ static void diffdir(char *p[2], const char *s_start)
* add_to_dirlist will remove it. */
list[i].len = strlen(p[i]);
recursive_action(p[i], ACTION_RECURSE | ACTION_FOLLOWLINKS,
add_to_dirlist, skip_dir, &list[i], 0);
add_to_dirlist, skip_dir, &list[i]);
/* Sort dl alphabetically.
* GNU diff does this ignoring any number of trailing dots.
* We don't, so for us dotted files almost always are
+1 -1
View File
@@ -31,7 +31,7 @@
//kbuild:lib-$(CONFIG_PATCH) += patch.o
//usage:#define patch_trivial_usage
//usage: "[OPTIONS] [ORIGFILE [PATCHFILE]]"
//usage: "[-RNE] [-p N] [-i DIFF] [ORIGFILE [PATCHFILE]]"
//usage:#define patch_full_usage "\n\n"
//usage: " -p N Strip N leading components from file names"
//usage: "\n -i DIFF Read DIFF instead of stdin"
+1 -1
View File
@@ -166,7 +166,7 @@
//kbuild:lib-$(CONFIG_VI) += vi.o
//usage:#define vi_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage: IF_FEATURE_VI_COLON("[-c CMD] ")IF_FEATURE_VI_READONLY("[-R] ")"[FILE]..."
//usage:#define vi_full_usage "\n\n"
//usage: "Edit FILE\n"
//usage: IF_FEATURE_VI_COLON(
+1 -1
View File
@@ -31,7 +31,7 @@ time dgram udp wait root internal
#ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd
#telnet stream tcp nowait root /sbin/telnetd /sbin/telnetd
#nntp stream tcp nowait root tcpd in.nntpd
#smtp stream tcp nowait root tcpd sendmail -v
#smtp stream tcp nowait root tcpd sendmail -v
#
# Shell, login, exec and talk are BSD protocols.
#
+4 -4
View File
@@ -6,12 +6,12 @@ RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ]
then
echo "deleting routers"
while /sbin/route del default gw 0.0.0.0 dev $interface
while route del default gw 0.0.0.0 dev $interface
do :
done
@@ -23,9 +23,9 @@ then
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
/sbin/ip route add $i dev $interface
ip route add $i dev $interface
fi
/sbin/route add default gw $i dev $interface metric $((metric++))
route add default gw $i dev $interface metric $((metric++))
done
fi
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
# Sample udhcpc deconfig script
/sbin/ifconfig $interface 0.0.0.0
ifconfig $interface 0.0.0.0
+4 -4
View File
@@ -6,12 +6,12 @@ RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ]
then
echo "deleting routers"
while /sbin/route del default gw 0.0.0.0 dev $interface
while route del default gw 0.0.0.0 dev $interface
do :
done
@@ -23,9 +23,9 @@ then
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
/sbin/ip route add $i dev $interface
ip route add $i dev $interface
fi
/sbin/route add default gw $i dev $interface metric $((metric++))
route add default gw $i dev $interface metric $((metric++))
done
fi
+10 -11
View File
@@ -889,10 +889,10 @@ ACTF(links)
}
#endif
static int FAST_FUNC fileAction(const char *fileName,
struct stat *statbuf,
void *userData UNUSED_PARAM,
int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM))
static int FAST_FUNC fileAction(
struct recursive_state *state IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM),
const char *fileName,
struct stat *statbuf)
{
int r;
int same_fs = 1;
@@ -911,12 +911,12 @@ static int FAST_FUNC fileAction(const char *fileName,
#endif
#if ENABLE_FEATURE_FIND_MAXDEPTH
if (depth < G.minmaxdepth[0]) {
if (state->depth < G.minmaxdepth[0]) {
if (same_fs)
return TRUE; /* skip this, continue recursing */
return SKIP; /* stop recursing */
}
if (depth > G.minmaxdepth[1])
if (state->depth > G.minmaxdepth[1])
return SKIP; /* stop recursing */
#endif
@@ -927,7 +927,7 @@ static int FAST_FUNC fileAction(const char *fileName,
#if ENABLE_FEATURE_FIND_MAXDEPTH
if (S_ISDIR(statbuf->st_mode)) {
if (depth == G.minmaxdepth[1])
if (state->depth == G.minmaxdepth[1])
return SKIP;
}
#endif
@@ -1441,7 +1441,7 @@ static action*** parse_params(char **argv)
#else
#define XATOU_SFX xatoul_sfx
#endif
static const struct suffix_mult find_suffixes[] = {
static const struct suffix_mult find_suffixes[] ALIGN_SUFFIX = {
{ "c", 1 },
{ "w", 2 },
{ "", 512 },
@@ -1522,7 +1522,7 @@ int find_main(int argc UNUSED_PARAM, char **argv)
}
*past_HLP = NULL;
/* "+": stop on first non-option */
i = getopt32(argv, "+HLP");
i = getopt32(argv, "+""HLP");
if (i & (1<<0))
G.recurse_flags |= ACTION_FOLLOWLINKS_L0 | ACTION_DANGLING_OK;
if (i & (1<<1))
@@ -1570,8 +1570,7 @@ int find_main(int argc UNUSED_PARAM, char **argv)
G.recurse_flags,/* flags */
fileAction, /* file action */
fileAction, /* dir action */
NULL, /* user data */
0) /* depth */
NULL) /* user data */
) {
G.exitstatus |= EXIT_FAILURE;
}
+25 -26
View File
@@ -167,13 +167,11 @@ enum {
OPT_z = IF_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0,
};
#define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l)
#define PRINT_LINE_NUM (option_mask32 & OPT_n)
#define BE_QUIET (option_mask32 & OPT_q)
#define SUPPRESS_ERR_MSGS (option_mask32 & OPT_s)
#define PRINT_MATCH_COUNTS (option_mask32 & OPT_c)
#define FGREP_FLAG (option_mask32 & OPT_F)
#define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L)
#define NUL_DELIMITED (option_mask32 & OPT_z)
struct globals {
@@ -476,13 +474,13 @@ static int grep_file(FILE *file)
* even if errors were detected" */
exit(EXIT_SUCCESS);
}
/* if we're just printing filenames, we stop after the first match */
if (PRINT_FILES_WITH_MATCHES) {
/* -l "print filenames with matches": stop after the first match */
if (option_mask32 & OPT_l) {
puts(cur_file);
/* fall through to "return 1" */
return 1;
}
/* OPT_L aka PRINT_FILES_WITHOUT_MATCHES: return early */
return 1; /* one match */
/* -L "print filenames without matches": return early too */
return 0; /* 0: we do not print fname, hence it's "not a match" */
}
#if ENABLE_FEATURE_GREP_CONTEXT
@@ -602,15 +600,16 @@ static int grep_file(FILE *file)
printf("%d\n", nmatches);
}
/* grep -L: print just the filename */
if (PRINT_FILES_WITHOUT_MATCHES) {
/* grep -L: "print filenames without matches" */
if (option_mask32 & OPT_L) {
/* nmatches is zero, no need to check it:
* we return 1 early if we detected a match
* and PRINT_FILES_WITHOUT_MATCHES is set */
* we return 0 early if -L and we detect a match
*/
puts(cur_file);
return 1; /* 1: we printed fname, hence it's "a match" */
}
return nmatches;
return nmatches != 0; /* we return not a count, but a boolean */
}
#if ENABLE_FEATURE_CLEAN_UP
@@ -657,10 +656,9 @@ static void load_pattern_list(llist_t **lst, char *pattern)
llist_add_to(lst, new_grep_list_data(p, 0));
}
static int FAST_FUNC file_action_grep(const char *filename,
struct stat *statbuf,
void* matched,
int depth UNUSED_PARAM)
static int FAST_FUNC file_action_grep(struct recursive_state *state UNUSED_PARAM,
const char *filename,
struct stat *statbuf)
{
FILE *file;
@@ -687,7 +685,7 @@ static int FAST_FUNC file_action_grep(const char *filename,
return 0;
}
cur_file = filename;
*(int*)matched += grep_file(file);
*(int*)state->userData |= grep_file(file);
fclose(file);
return 1;
}
@@ -695,15 +693,16 @@ static int FAST_FUNC file_action_grep(const char *filename,
static int grep_dir(const char *dir)
{
int matched = 0;
recursive_action(dir,
/* recurse=yes */ ACTION_RECURSE |
/* followLinks=always */ ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0) |
/* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
/* depthFirst=yes */ ACTION_DEPTHFIRST,
recursive_action(dir, 0
| ACTION_RECURSE
| ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0)
| ACTION_FOLLOWLINKS_L0 /* grep -r ... SYMLINK follows it */
| ACTION_DEPTHFIRST
| 0,
/* fileAction= */ file_action_grep,
/* dirAction= */ NULL,
/* userData= */ &matched,
/* depth= */ 0);
/* userData= */ &matched
);
return matched;
}
@@ -844,7 +843,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) {
if (!(option_mask32 & OPT_h))
print_filename = 1;
matched += grep_dir(cur_file);
matched |= grep_dir(cur_file);
goto grep_done;
}
}
@@ -857,7 +856,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
continue;
}
}
matched += grep_file(file);
matched |= grep_file(file);
fclose_if_not_stdin(file);
grep_done: ;
} while (*argv && *++argv);
+16 -5
View File
@@ -80,9 +80,11 @@
/* This is a NOEXEC applet. Be very careful! */
//#define dbg_msg(...) bb_error_msg(__VA_ARGS__)
#define dbg_msg(...) ((void)0)
#if 0
# define dbg_msg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg_msg(...) ((void)0)
#endif
#ifdef TEST
# ifndef ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION
@@ -466,9 +468,18 @@ static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg
while (1) {
int c = getchar();
if (p == buf) {
if (c == EOF)
goto ret; /* last line is empty, return "" */
if (c == G.eol_ch)
continue; /* empty line, ignore */
/* Skip leading whitespace of each line: try
* echo -e ' \t\v1 2 3 ' | xargs -I% echo '[%]'
*/
if (ISSPACE(c))
continue;
}
if (c == EOF || c == G.eol_ch) {
if (p == buf)
goto ret; /* empty line */
c = '\0';
}
*p++ = c;
View File
File renamed without changes.
+1 -14
View File
@@ -2,20 +2,6 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
#define F_IGNORE 0x01 /* %_A */
#define F_SETREP 0x02 /* rep count set, not default */
#define F_ADDRESS 0x001 /* print offset */
#define F_BPAD 0x002 /* blank pad */
#define F_C 0x004 /* %_c */
#define F_CHAR 0x008 /* %c */
#define F_DBL 0x010 /* %[EefGf] */
#define F_INT 0x020 /* %[di] */
#define F_P 0x040 /* %_p */
#define F_STR 0x080 /* %s */
#define F_U 0x100 /* %_u */
#define F_UINT 0x200 /* %[ouXx] */
#define F_TEXT 0x400 /* no conversions */
enum dump_vflag_t { ALL, DUP, FIRST, WAIT }; /* -v values */
typedef struct PR {
@@ -46,6 +32,7 @@ typedef struct dumper_t {
off_t dump_skip; /* bytes to skip */
int dump_length; /* max bytes to read */
smallint dump_vflag; /*enum dump_vflag_t*/
const char *eofstring;
FS *fshead;
} dumper_t;
+86 -26
View File
@@ -339,12 +339,13 @@ struct BUG_off_t_size_is_misdetected {
#endif
#endif
#if defined(__GLIBC__)
/* glibc uses __errno_location() to get a ptr to errno */
/* We can just memorize it once - no multithreading in busybox :) */
#if defined(errno)
/* If errno is a define, assume it's "define errno (*__errno_location())"
* and we will cache it's result in this variable */
extern int *const bb_errno;
#undef errno
#define errno (*bb_errno)
#define bb_cached_errno_ptr 1
#endif
#if !(ULONG_MAX > 0xffffffff)
@@ -386,6 +387,32 @@ void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) F
char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
void *mmap_read(int fd, size_t size) FAST_FUNC;
void *mmap_anon(size_t size) FAST_FUNC;
void *xmmap_anon(size_t size) FAST_FUNC;
#if defined(__x86_64__) || defined(i386)
# define BB_ARCH_FIXED_PAGESIZE 4096
#elif defined(__arm__) /* only 32bit, 64bit ARM has variable page size */
# define BB_ARCH_FIXED_PAGESIZE 4096
#else /* if defined(ARCH) */
/* add you favorite arch today! */
//From Linux kernel inspection:
//xtenza,s390[x],riscv,nios2,csky,sparc32: fixed 4k pages
//sparc64,alpha,openrisc: fixed 8k pages
#endif
#if defined BB_ARCH_FIXED_PAGESIZE
# define IF_VARIABLE_ARCH_PAGESIZE(...) /*nothing*/
# define bb_getpagesize() BB_ARCH_FIXED_PAGESIZE
# define INIT_PAGESIZE(var) ((void)0)
# define cached_pagesize(var) BB_ARCH_FIXED_PAGESIZE
#else
# define IF_VARIABLE_ARCH_PAGESIZE(...) __VA_ARGS__
# define bb_getpagesize() getpagesize()
# define INIT_PAGESIZE(var) ((var) = getpagesize())
# define cached_pagesize(var) (var)
#endif
//TODO: supply a pointer to char[11] buffer (avoid statics)?
@@ -436,15 +463,23 @@ enum {
ACTION_FOLLOWLINKS = (1 << 1),
ACTION_FOLLOWLINKS_L0 = (1 << 2),
ACTION_DEPTHFIRST = (1 << 3),
/*ACTION_REVERSE = (1 << 4), - unused */
ACTION_QUIET = (1 << 5),
ACTION_DANGLING_OK = (1 << 6),
ACTION_QUIET = (1 << 4),
ACTION_DANGLING_OK = (1 << 5),
};
typedef uint8_t recurse_flags_t;
extern int recursive_action(const char *fileName, unsigned flags,
int FAST_FUNC (*fileAction)(const char *fileName, struct stat* statbuf, void* userData, int depth),
int FAST_FUNC (*dirAction)(const char *fileName, struct stat* statbuf, void* userData, int depth),
void* userData, unsigned depth) FAST_FUNC;
typedef struct recursive_state {
unsigned flags;
unsigned depth;
void *userData;
int FAST_FUNC (*fileAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf);
int FAST_FUNC (*dirAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf);
} recursive_state_t;
int recursive_action(const char *fileName, unsigned flags,
int FAST_FUNC (*fileAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf),
int FAST_FUNC (*dirAction)(struct recursive_state *state, const char *fileName, struct stat* statbuf),
void *userData
) FAST_FUNC;
extern int device_open(const char *device, int mode) FAST_FUNC;
enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */
extern int xgetpty(char *line) FAST_FUNC;
@@ -622,6 +657,8 @@ void parse_datestr(const char *date_str, struct tm *ptm) FAST_FUNC;
time_t validate_tm_time(const char *date_str, struct tm *ptm) FAST_FUNC;
char *strftime_HHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
void xsettimeofday(const struct timeval *tv) FAST_FUNC;
int xsocket(int domain, int type, int protocol) FAST_FUNC;
void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
@@ -817,7 +854,7 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
struct sockaddr *to,
socklen_t sa_size) FAST_FUNC;
uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
uint16_t inet_cksum(const void *addr, int len) FAST_FUNC;
int parse_pasv_epsv(char *buf) FAST_FUNC;
/* 0 if argv[0] is NULL: */
@@ -1017,8 +1054,9 @@ void generate_uuid(uint8_t *buf) FAST_FUNC;
/* Last element is marked by mult == 0 */
struct suffix_mult {
char suffix[4];
unsigned mult;
uint32_t mult;
};
#define ALIGN_SUFFIX ALIGN4
extern const struct suffix_mult bkm_suffixes[];
#define km_suffixes (bkm_suffixes + 1)
extern const struct suffix_mult cwbkMG_suffixes[];
@@ -1130,7 +1168,6 @@ int BB_EXECVP(const char *file, char *const argv[]) FAST_FUNC;
#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__)
#endif
void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
/* xvfork() can't be a _function_, return after vfork in child mangles stack
* in the parent. It must be a macro. */
@@ -1515,7 +1552,8 @@ int del_loop(const char *device) FAST_FUNC;
* malloc and return it in *devname.
* return value is the opened fd to the loop device, or < on error
*/
int set_loop(char **devname, const char *file, unsigned long long offset, unsigned flags) FAST_FUNC;
int set_loop(char **devname, const char *file, unsigned long long offset,
unsigned long long sizelimit, unsigned flags) FAST_FUNC;
/* These constants match linux/loop.h (without BB_ prefix): */
#define BB_LO_FLAGS_READ_ONLY 1
#define BB_LO_FLAGS_AUTOCLEAR 4
@@ -1591,12 +1629,14 @@ 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 **args) NORETURN FAST_FUNC;
void pause_after_failed_login(void) FAST_FUNC;
void bb_do_delay(unsigned seconds) FAST_FUNC;
void msleep(unsigned ms) FAST_FUNC;
void sleep1(void) FAST_FUNC;
void change_identity(const struct passwd *pw) FAST_FUNC;
void exec_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
void exec_login_shell(const char *shell) NORETURN FAST_FUNC;
void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
/* Returns $SHELL, getpwuid(getuid())->pw_shell, or DEFAULT_SHELL.
* Note that getpwuid result might need xstrdup'ing
@@ -1825,14 +1865,20 @@ typedef const char *get_exe_name_t(int i) FAST_FUNC;
typedef struct line_input_t {
int flags;
int timeout;
# if ENABLE_FEATURE_TAB_COMPLETION
# if ENABLE_SHELL_ASH
const char *path_lookup;
# if ENABLE_FEATURE_TAB_COMPLETION \
&& (ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH \
|| ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH \
)
# define EDITING_HAS_path_lookup 1
# else
# define EDITING_HAS_path_lookup 0
# endif
# if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH
/* function to fetch additional application-specific names to match */
get_exe_name_t *get_exe_name;
# define EDITING_HAS_get_exe_name 1
# define EDITING_HAS_get_exe_name 1
# else
# define EDITING_HAS_get_exe_name 0
# endif
# endif
# if MAX_HISTORY
int cnt_history;
@@ -1860,7 +1906,11 @@ enum {
FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
};
line_input_t *new_line_input_t(int flags) FAST_FUNC;
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
void free_line_input_t(line_input_t *n) FAST_FUNC;
#else
# define free_line_input_t(n) free(n)
#endif
/*
* maxsize must be >= 2.
* Returns:
@@ -2016,14 +2066,17 @@ char *percent_decode_in_place(char *str, int strict) FAST_FUNC;
extern const char bb_uuenc_tbl_base64[] ALIGN1;
extern const char bb_uuenc_tbl_base32[] ALIGN1;
extern const char bb_uuenc_tbl_std[] ALIGN1;
void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC;
enum {
BASE64_FLAG_UU_STOP = 0x100,
BASE64_32 = 0x200, /* base32 */
/* Sign-extends to a value which never matches fgetc result: */
BASE64_FLAG_NO_STOP_CHAR = 0x80,
};
const char *decode_base64(char **pp_dst, const char *src) FAST_FUNC;
char *decode_base64(char *dst, const char **pp_src) FAST_FUNC;
char *decode_base32(char *dst, const char **pp_src) FAST_FUNC;
void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
typedef struct md5_ctx_t {
@@ -2063,6 +2116,13 @@ unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
typedef struct md5_ctx_t md5sha_ctx_t;
#define md5sha_hash md5_hash
#define sha_end sha1_end
enum {
MD5_OUTSIZE = 16,
SHA1_OUTSIZE = 20,
SHA256_OUTSIZE = 32,
SHA512_OUTSIZE = 64,
SHA3_OUTSIZE = 28,
};
extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
+2
View File
@@ -342,6 +342,8 @@ typedef unsigned smalluint;
# define ALIGN2
# define ALIGN4
#endif
#define ALIGN8 __attribute__((aligned(8)))
#define ALIGN_PTR __attribute__((aligned(sizeof(void*))))
/*
* For 0.9.29 and svn, __ARCH_USE_MMU__ indicates no-mmu reliably.
+6
View File
@@ -11,6 +11,12 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
#if ENABLE_FEATURE_HWCLOCK_ADJTIME_FHS
# define ADJTIME_PATH "/var/lib/hwclock/adjtime"
#else
# define ADJTIME_PATH "/etc/adjtime"
#endif
int rtc_adjtime_is_utc(void) FAST_FUNC;
int rtc_xopen(const char **default_rtc, int flags) FAST_FUNC;
void rtc_read_tm(struct tm *ptm, int fd) FAST_FUNC;
+6
View File
@@ -25,6 +25,12 @@
" (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
#endif
#if ENABLE_FEATURE_HWCLOCK_ADJTIME_FHS
# define ADJTIME_PATH "/var/lib/hwclock/adjtime"
#else
# define ADJTIME_PATH "/etc/adjtime"
#endif
INSERT
#define busybox_notes_usage \
+5 -5
View File
@@ -65,7 +65,7 @@
//kbuild:lib-$(CONFIG_REBOOT) += halt.o
//usage:#define halt_trivial_usage
//usage: "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
//usage: "[-d DELAY] [-nf"IF_FEATURE_WTMP("w")"]"
//usage:#define halt_full_usage "\n\n"
//usage: "Halt the system\n"
//usage: "\n -d SEC Delay interval"
@@ -76,7 +76,7 @@
//usage: )
//usage:
//usage:#define poweroff_trivial_usage
//usage: "[-d DELAY] [-n] [-f]"
//usage: "[-d DELAY] [-nf]"
//usage:#define poweroff_full_usage "\n\n"
//usage: "Halt and shut off power\n"
//usage: "\n -d SEC Delay interval"
@@ -84,7 +84,7 @@
//usage: "\n -f Force (don't go through init)"
//usage:
//usage:#define reboot_trivial_usage
//usage: "[-d DELAY] [-n] [-f]"
//usage: "[-d DELAY] [-nf]"
//usage:#define reboot_full_usage "\n\n"
//usage: "Reboot the system\n"
//usage: "\n -d SEC Delay interval"
@@ -144,14 +144,14 @@ static int init_was_not_there(void)
*/
#if 0
while (kill(1, 0) != 0 && --cnt >= 0)
sleep(1);
sleep1();
#endif
/* ... so let's wait for some evidence a usual startup event,
* mounting of /proc, happened. By that time init should be ready
* for signals.
*/
while (access("/proc/meminfo", F_OK) != 0 && --cnt >= 0)
sleep(1);
sleep1();
/* Does it look like init wasn't there? */
return (cnt != initial - 1);
+6 -6
View File
@@ -736,7 +736,7 @@ static void pause_and_low_level_reboot(unsigned magic)
pid_t pid;
/* Allow time for last message to reach serial console, etc */
sleep(1);
sleep1();
/* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS)
* in linux/kernel/sys.c, which can cause the machine to panic when
@@ -751,7 +751,7 @@ static void pause_and_low_level_reboot(unsigned magic)
* we would eternally sleep here - not what we want.
*/
waitpid(pid, NULL, 0);
sleep(1); /* paranoia */
sleep1(); /* paranoia */
_exit(EXIT_SUCCESS);
}
@@ -768,12 +768,12 @@ static void run_shutdown_and_kill_processes(void)
kill(-1, SIGTERM);
message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
sync();
sleep(1);
sleep1();
kill(-1, SIGKILL);
message(L_CONSOLE, "Sent SIG%s to all processes", "KILL");
sync();
/*sleep(1); - callers take care about making a pause */
/*sleep1(); - callers take care about making a pause */
}
/* Signal handling by init:
@@ -904,7 +904,7 @@ static void stop_handler(int sig UNUSED_PARAM)
wpid = wait_any_nohang(NULL);
mark_terminated(wpid);
if (wpid <= 0) /* no processes exited? sleep a bit */
sleep(1);
sleep1();
}
signal(SIGCONT, SIG_DFL);
@@ -1209,7 +1209,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
}
/* Don't consume all CPU time - sleep a bit */
sleep(1);
sleep1();
} /* while (1) */
}
-1
View File
@@ -8,7 +8,6 @@
//config:config RUN_INIT
//config: bool "run-init (7.7 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: The run-init utility is used from initramfs to select a new
//config: root device. Under initramfs, you have to use this instead of
-2
View File
@@ -334,7 +334,6 @@ config FEATURE_VERBOSE_CP_MESSAGE
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
@@ -376,7 +375,6 @@ config FEATURE_SKIP_ROOTFS
config MONOTONIC_SYSCALL
bool "Use clock_gettime(CLOCK_MONOTONIC) syscall"
default y
select PLATFORM_LINUX
help
Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring
time intervals (time, ping, traceroute etc need this).
+2 -1
View File
@@ -112,7 +112,8 @@ lib-y += xgethostbyname.o
lib-y += xreadlink.o
lib-y += xrealloc_vector.o
lib-$(CONFIG_PLATFORM_LINUX) += match_fstype.o
lib-$(CONFIG_MOUNT) += match_fstype.o
lib-$(CONFIG_UMOUNT) += match_fstype.o
lib-$(CONFIG_FEATURE_UTMP) += utmp.o
+7 -2
View File
@@ -25,6 +25,11 @@
*
* FEATURE_INSTALLER or FEATURE_SUID will still link printf routines in. :(
*/
/* Define this accessor before we #define "errno" our way */
#include <errno.h>
static inline int *get_perrno(void) { return &errno; }
#include "busybox.h"
#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
@@ -303,8 +308,8 @@ void lbb_prepare(const char *applet
void lbb_prepare(const char *applet
IF_FEATURE_INDIVIDUAL(, char **argv))
{
#ifdef __GLIBC__
(*(int **)not_const_pp(&bb_errno)) = __errno_location();
#ifdef bb_cached_errno_ptr
(*(int **)not_const_pp(&bb_errno)) = get_perrno();
barrier();
#endif
applet_name = applet;
+54 -7
View File
@@ -8,13 +8,60 @@
*/
#include "libbb.h"
void FAST_FUNC bb_do_delay(int seconds)
{
time_t start, now;
/* void FAST_FUNC bb_do_delay(unsigned seconds) { ... } - no users yet */
start = time(NULL);
#ifndef LOGIN_FAIL_DELAY
#define LOGIN_FAIL_DELAY 3
#endif
void FAST_FUNC pause_after_failed_login(void)
{
#if 0 /* over-engineered madness */
time_t end, diff;
end = time(NULL) + LOGIN_FAIL_DELAY;
diff = LOGIN_FAIL_DELAY;
do {
sleep(seconds);
now = time(NULL);
} while ((now - start) < seconds);
sleep(diff);
diff = end - time(NULL);
} while (diff > 0);
#else
sleep(LOGIN_FAIL_DELAY);
#endif
}
void FAST_FUNC sleep1(void)
{
sleep(1);
}
void FAST_FUNC msleep(unsigned ms)
{
#if 0
/* 1. usleep(n) is not guaranteed by standards to accept n >= 1000000
* 2. multiplication in usleep(ms * 1000) can overflow if ms > 4294967
* (sleep of ~71.5 minutes)
* Let's play safe and loop:
*/
while (ms > 500) {
usleep(500000);
ms -= 500;
}
usleep(ms * 1000);
#else
//usleep is often implemented as a call to nanosleep.
//Simply do the same to implement msleep.
//it's marginally larger, but wakes your CPU less often:
//function old new delta
//msleep 45 52 +7
struct timespec ts;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000000;
/*
* If a signal has non-default handler, nanosleep returns early.
* Our version of msleep doesn't return early
* if interrupted by such signals:
*/
while (nanosleep(&ts, &ts) != 0)
continue;
#endif
}
+1 -1
View File
@@ -17,7 +17,7 @@ extern int capget(cap_user_header_t header, const cap_user_data_t data);
// This way, libcap needs not be installed in build environment.
#include "libbb.h"
static const char *const capabilities[] = {
static const char *const capabilities[] ALIGN_PTR = {
"chown",
"dac_override",
"dac_read_search",
+5 -2
View File
@@ -117,8 +117,11 @@ int FAST_FUNC index_in_substrings(const char *strings, const char *key)
const char* FAST_FUNC nth_string(const char *strings, int n)
{
while (n) {
n--;
strings += strlen(strings) + 1;
if (*strings++ == '\0') {
if (*strings == '\0') /* reached end of strings */
break;
n--;
}
}
return strings;
}
+1 -4
View File
@@ -75,10 +75,7 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
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 = mmap_anon(CONFIG_FEATURE_COPYBUF_KB * 1024);
buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
if (buffer == MAP_FAILED) {
use_small_buf:
+4
View File
@@ -8,6 +8,10 @@
*/
#include "libbb.h"
#ifndef LOGIN_NAME_MAX
#define LOGIN_NAME_MAX 256
#endif
/* To avoid problems, the username should consist only of
* letters, digits, underscores, periods, at signs and dashes,
* and not start with a dash (as defined by IEEE Std 1003.1-2001).
+47 -23
View File
@@ -13,13 +13,19 @@
#include "libbb.h"
#include "dump.h"
static const char dot_flags_width_chars[] ALIGN1 = ".#-+ 0123456789";
static const char size_conv_str[] ALIGN1 =
"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG";
static const char int_convs[] ALIGN1 = "diouxX";
#define F_IGNORE 0x01 /* %_A */
#define F_SETREP 0x02 /* rep count set, not default */
#define F_ADDRESS 0x001 /* print offset */
#define F_BPAD 0x002 /* blank pad */
#define F_C 0x004 /* %_c */
#define F_CHAR 0x008 /* %c */
#define F_DBL 0x010 /* %[EefGf] */
#define F_INT 0x020 /* %[di] */
#define F_P 0x040 /* %_p */
#define F_STR 0x080 /* %s */
#define F_U 0x100 /* %_u */
#define F_UINT 0x200 /* %[ouXx] */
#define F_TEXT 0x400 /* no conversions */
typedef struct priv_dumper_t {
dumper_t pub;
@@ -39,6 +45,13 @@ typedef struct priv_dumper_t {
unsigned char *get__savp;
} priv_dumper_t;
static const char dot_flags_width_chars[] ALIGN1 = ".#-+ 0123456789";
static const char size_conv_str[] ALIGN1 =
"\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG";
static const char int_convs[] ALIGN1 = "diouxX";
dumper_t* FAST_FUNC alloc_dumper(void)
{
priv_dumper_t *dumper = xzalloc(sizeof(*dumper));
@@ -48,7 +61,6 @@ dumper_t* FAST_FUNC alloc_dumper(void)
return &dumper->pub;
}
static NOINLINE int bb_dump_size(FS *fs)
{
FU *fu;
@@ -284,7 +296,9 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs)
* repeat it as necessary.
*
* if rep count is greater than 1, no trailing whitespace
* gets output from the last iteration of the format unit.
* gets output from the last iteration of the format unit:
* 2/1 "%02x " prints "XX XX", not "XX XX "
* 2/1 "%02x\n" prints "XX\nXX", not "XX\nXX\n"
*/
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
if (!fu->nextfu
@@ -394,7 +408,6 @@ static unsigned char *get(priv_dumper_t *dumper)
if (dumper->pub.dump_vflag != DUP) {
puts("*");
}
return NULL;
}
memset(dumper->get__curp + nread, 0, need);
dumper->eaddress = dumper->address + nread;
@@ -453,7 +466,7 @@ static void bpad(PR *pr)
for (p2 = ++p1; *p1 && strchr(" -0+#", *p1); ++p1)
if (pr->nospace)
pr->nospace--;
while ((*p2++ = *p1++) != 0)
while ((*p2++ = *p1++) != '\0')
continue;
}
@@ -520,36 +533,43 @@ static void conv_u(PR *pr, unsigned char *p)
static void display(priv_dumper_t* dumper)
{
FS *fs;
FU *fu;
PR *pr;
int cnt;
unsigned char *bp, *savebp;
off_t saveaddress;
unsigned char *bp;
unsigned char savech = '\0';
while ((bp = get(dumper)) != NULL) {
FS *fs;
unsigned char *savebp;
off_t saveaddress;
fs = dumper->pub.fshead;
savebp = bp;
saveaddress = dumper->address;
for (; fs; fs = fs->nextfs, bp = savebp, dumper->address = saveaddress) {
FU *fu;
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
int cnt;
if (fu->flags & F_IGNORE) {
break;
}
for (cnt = fu->reps; cnt; --cnt) {
PR *pr;
for (pr = fu->nextpr; pr; dumper->address += pr->bcnt,
bp += pr->bcnt, pr = pr->nextpr) {
if (dumper->eaddress && dumper->address >= dumper->eaddress
&& !(pr->flags & (F_TEXT | F_BPAD))
if (dumper->eaddress
&& dumper->address >= dumper->eaddress
) {
bpad(pr);
if (dumper->pub.eofstring) {
/* xxd support: requested to not pad incomplete blocks */
fputs(dumper->pub.eofstring, stdout);
return;
}
if (!(pr->flags & (F_TEXT | F_BPAD)))
bpad(pr);
}
if (cnt == 1 && pr->nospace) {
savech = *pr->nospace;
*pr->nospace = '\0';
}
/* PRINT; */
switch (pr->flags) {
case F_ADDRESS:
printf(pr->fmt, (unsigned) dumper->address);
@@ -638,7 +658,9 @@ static void display(priv_dumper_t* dumper)
}
}
}
if (dumper->endfu) {
PR *pr;
/*
* if eaddress not set, error or file size was multiple
* of blocksize, and no partial block ever found.
@@ -695,8 +717,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
{
const char *p;
FS *tfs;
FU *tfu, **nextfupp;
const char *savep;
FU **nextfupp;
/* start new linked list of format units */
tfs = xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */
@@ -713,6 +734,9 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
/* take the format string and break it up into format units */
p = fmt;
for (;;) {
FU *tfu;
const char *savep;
p = skip_whitespace(p);
if (*p == '\0') {
break;
+1 -1
View File
@@ -21,7 +21,7 @@
#include "libbb.h"
static const struct suffix_mult duration_suffixes[] = {
static const struct suffix_mult duration_suffixes[] ALIGN_SUFFIX = {
{ "s", 1 },
{ "m", 60 },
{ "h", 60*60 },
-9
View File
@@ -91,12 +91,3 @@ void FAST_FUNC BB_EXECVP_or_die(char **argv)
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
bb_perror_msg_and_die("can't execute '%s'", argv[0]);
}
/* Typical idiom for applets which exec *optional* PROG [ARGS] */
void FAST_FUNC exec_prog_or_SHELL(char **argv)
{
if (argv[0]) {
BB_EXECVP_or_die(argv);
}
run_shell(getenv("SHELL"), /*login:*/ 1, NULL);
}
+39 -58
View File
@@ -38,35 +38,6 @@ static ALWAYS_INLINE uint64_t rotl64(uint64_t x, unsigned n)
return (x << n) | (x >> (64 - n));
}
/* Feed data through a temporary buffer.
* The internal buffer remembers previous data until it has 64
* bytes worth to pass on.
*/
static void FAST_FUNC common64_hash(md5_ctx_t *ctx, const void *buffer, size_t len)
{
unsigned bufpos = ctx->total64 & 63;
ctx->total64 += len;
while (1) {
unsigned remaining = 64 - bufpos;
if (remaining > len)
remaining = len;
/* Copy data into aligned buffer */
memcpy(ctx->wbuffer + bufpos, buffer, remaining);
len -= remaining;
buffer = (const char *)buffer + remaining;
bufpos += remaining;
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= 64;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
ctx->process_block(ctx);
/*bufpos = 0; - already is */
}
}
/* Process the remaining bytes in the buffer */
static void FAST_FUNC common64_end(md5_ctx_t *ctx, int swap_needed)
{
@@ -140,7 +111,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx)
They are defined in RFC 1321 as
T[i] = (int)(2^32 * fabs(sin(i))), i=1..64
*/
static const uint32_t C_array[] = {
static const uint32_t C_array[] ALIGN4 = {
/* round 1 */
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
@@ -449,7 +420,29 @@ void FAST_FUNC md5_begin(md5_ctx_t *ctx)
/* Used also for sha1 and sha256 */
void FAST_FUNC md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len)
{
common64_hash(ctx, buffer, len);
unsigned bufpos = ctx->total64 & 63;
ctx->total64 += len;
while (1) {
unsigned remaining = 64 - bufpos;
if (remaining > len)
remaining = len;
/* Copy data into aligned buffer */
memcpy(ctx->wbuffer + bufpos, buffer, remaining);
len -= remaining;
buffer = (const char *)buffer + remaining;
bufpos += remaining;
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= 64;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
ctx->process_block(ctx);
/*bufpos = 0; - already is */
}
}
/* Process the remaining bytes in the buffer and put result from CTX
@@ -499,7 +492,7 @@ unsigned FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf)
static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx)
{
static const uint32_t rconsts[] = {
static const uint32_t rconsts[] ALIGN4 = {
0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6
};
int i, j;
@@ -574,7 +567,7 @@ typedef uint64_t sha_K_int;
typedef uint32_t sha_K_int;
# define K(v) (uint32_t)(v >> 32)
#endif
static const sha_K_int sha_K[] = {
static const sha_K_int sha_K[] ALIGN8 = {
K(0x428a2f98d728ae22ULL), K(0x7137449123ef65cdULL),
K(0xb5c0fbcfec4d3b2fULL), K(0xe9b5dba58189dbbcULL),
K(0x3956c25bf348b538ULL), K(0x59f111f1b605d019ULL),
@@ -767,7 +760,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
ctx->process_block = sha1_process_block64;
}
static const uint32_t init256[] = {
static const uint32_t init256[] ALIGN4 = {
0,
0,
0x6a09e667,
@@ -780,7 +773,7 @@ static const uint32_t init256[] = {
0x5be0cd19,
};
#if NEED_SHA512
static const uint32_t init512_lo[] = {
static const uint32_t init512_lo[] ALIGN4 = {
0,
0,
0xf3bcc908,
@@ -816,7 +809,7 @@ void FAST_FUNC sha512_begin(sha512_ctx_t *ctx)
int i;
/* Two extra iterations zero out ctx->total64[2] */
uint64_t *tp = ctx->total64;
for (i = 0; i < 2+8; i++)
for (i = 0; i < 8 + 2; i++)
tp[i] = ((uint64_t)(init256[i]) << 32) + init512_lo[i];
/*ctx->total64[0] = ctx->total64[1] = 0; - already done */
}
@@ -832,22 +825,7 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len)
ctx->total64[0] += len;
if (ctx->total64[0] < len)
ctx->total64[1]++;
# if 0
remaining = 128 - bufpos;
/* Hash whole blocks */
while (len >= remaining) {
memcpy(ctx->wbuffer + bufpos, buffer, remaining);
buffer = (const char *)buffer + remaining;
len -= remaining;
remaining = 128;
bufpos = 0;
sha512_process_block128(ctx);
}
/* Save last, partial blosk */
memcpy(ctx->wbuffer + bufpos, buffer, len);
# else
while (1) {
remaining = 128 - bufpos;
if (remaining > len)
@@ -857,15 +835,16 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len)
len -= remaining;
buffer = (const char *)buffer + remaining;
bufpos += remaining;
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= 128;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
sha512_process_block128(ctx);
/*bufpos = 0; - already is */
}
# endif
}
#endif /* NEED_SHA512 */
@@ -1030,7 +1009,7 @@ static void sha3_process_block72(uint64_t *state)
#if OPTIMIZE_SHA3_FOR_32
/*
static const uint32_t IOTA_CONST_0[NROUNDS] = {
static const uint32_t IOTA_CONST_0[NROUNDS] ALIGN4 = {
0x00000001UL,
0x00000000UL,
0x00000000UL,
@@ -1059,7 +1038,7 @@ static void sha3_process_block72(uint64_t *state)
** 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] = {
static const uint32_t IOTA_CONST_1[NROUNDS] ALIGN4 = {
0x00000000UL,
0x00000089UL,
0x8000008bUL,
@@ -1195,7 +1174,7 @@ static void sha3_process_block72(uint64_t *state)
combine_halves(state);
#else
/* Native 64-bit algorithm */
static const uint16_t IOTA_CONST[NROUNDS] = {
static const uint16_t IOTA_CONST[NROUNDS] ALIGN2 = {
/* 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
@@ -1231,15 +1210,15 @@ static void sha3_process_block72(uint64_t *state)
/* bit for CONST[0] is in msb: 0001 0110 0011 1000 0001 1011 */
const uint32_t IOTA_CONST_bit31 = (uint32_t)(0x16381b00);
static const uint8_t ROT_CONST[24] = {
static const uint8_t ROT_CONST[24] ALIGN1 = {
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,
};
static const uint8_t PI_LANE[24] = {
static const uint8_t PI_LANE[24] ALIGN1 = {
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
};
/*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/
/*static const uint8_t MOD5[10] ALIGN1 = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/
unsigned x;
unsigned round;
@@ -1398,10 +1377,12 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len)
bufpos++;
remaining--;
}
/* Clever way to do "if (bufpos != N) break; ... ; bufpos = 0;" */
bufpos -= ctx->input_block_bytes;
if (bufpos != 0)
break;
/* Buffer is filled up, process it */
sha3_process_block72(ctx->state);
/*bufpos = 0; - already is */
+3 -1
View File
@@ -6,8 +6,10 @@
#include "libbb.h"
uint16_t FAST_FUNC inet_cksum(uint16_t *addr, int nleft)
uint16_t FAST_FUNC inet_cksum(const void *ptr, int nleft)
{
const uint16_t *addr = ptr;
/*
* Our algorithm is simple, using a 32 bit accumulator,
* we add sequential 16 bit words to it, and at the end, fold
+11 -9
View File
@@ -19,15 +19,17 @@ int FAST_FUNC get_linux_version_code(void)
{
struct utsname name;
char *t;
int i, r;
int r;
uname(&name); /* never fails */
t = name.release;
r = 0;
for (i = 0; i < 3; i++) {
t = strtok(t, ".");
r = r * 256 + (t ? atoi(t) : 0);
t = NULL;
}
return r;
t = name.release - 1;
r = 1;
do {
r <<= 8;
if (t) {
r += atoi(++t);
t = strchr(t, '.');
}
} while (r < 0x1000000);
return r - 0x1000000;
}
Loaded 100 of 352 files, more files were not shown because too many files have changed in this diff. Show more