Compare commits

...

259 Commits
v1.1 ... master

Author SHA1 Message Date
Stephen Heumann 99224d3946 Address a couple errors identified by ORCA/C 2.2.0 B2.
One of these concerned socket-related structures that aren't really used in hush. The other was a reliance on a GCC-specific feature (arithmetic on void pointers); this code is actually used in hush, although I'm not sure if the error was causing any real problems.
2017-12-31 16:07:51 -06:00
Stephen Heumann fa5c5f6f53 Clean up merge of code in (unused) with-MMU case 2015-10-17 10:17:22 -05:00
Stephen Heumann 16cd3c0619 Merge with BusyBox 1.24.0.
There's really only one bug fix in here that should be significant for GNO hush. The other changes should be inconsequential, AFAIK.
2015-10-17 01:10:35 -05:00
Denys Vlasenko 7ab00a0de9 Bump version to 1.24.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 14:33:03 +02:00
Denys Vlasenko 5de450237c libpwdgrp: do not require that /etc/passwd entries have nonempty home and shell
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 04:06:18 +02:00
Denys Vlasenko 57aeb62f83 randconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 03:15:36 +02:00
Denys Vlasenko c8e5ead03a build system: remove special-casing for extra libs
It is not reliable (tried on three systems, multiple problems).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 03:12:17 +02:00
Denys Vlasenko 2dbbf823ef randconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 23:48:28 +02:00
Denys Vlasenko 85378cded7 hush: code shrink
function                                             old     new   delta
builtin_wait                                         347     328     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 21:47:11 +02:00
Denys Vlasenko 932302666b randconfig fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 16:58:18 +02:00
Denys Vlasenko 69c8c699aa randconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 16:27:55 +02:00
Denys Vlasenko 005c492c40 ash: shrink umask code
function                                             old     new   delta
umaskcmd                                             258     248     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-10 20:17:12 +02:00
Denys Vlasenko 02859aaeb2 use auto_string() where appropriate to kill a few statics
Custom linker script 'busybox_ldscript' found, using it
function                                             old     new   delta
static.str                                             4       -      -4
static.passwd                                          4       0      -4
bb_ask                                               322     311     -11
ether_print                                           63      47     -16
UNSPEC_print                                          82      66     -16
INET_sprint                                           59      38     -21
INET6_sprint                                          54      30     -24
make_human_readable_str                              292     235     -57
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/7 up/down: 0/-153)           Total: -153 bytes
   text	   data	    bss	    dec	    hex	filename
 939880	    992	  17480	 958352	  e9f90	busybox_old
 939736	    992	  17456	 958184	  e9ee8	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 18:16:40 +02:00
Denys Vlasenko e52da5570e libbb: auto_string() for efficient handling of temporary malloced stirngs
Use it in libiproute: get rid of one static string buffer.

function                                             old     new   delta
auto_string                                            -      51     +51
ll_index_to_name                                      10      49     +39
buffer_fill_and_print                                169     178      +9
scan_recursive                                       378     380      +2
decode_one_format                                    732     734      +2
cmdputs                                              334     332      -2
static.cur_saved                                       4       1      -3
static.nbuf                                           16       -     -16
printable_string                                      94      57     -37
ll_idx_n2a                                            53       -     -53
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 4/3 up/down: 103/-111)           Total: -8 bytes
   text	   data	    bss	    dec	    hex	filename
 939880	    992	  17496	 958368	  e9fa0	busybox_old
 939880	    992	  17480	 958352	  e9f90	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 17:59:56 +02:00
Denys Vlasenko 550bf5b4a4 remove global "jmp_buf die_jmp" from !FEATURE_PREFER_APPLETS builds
function                                             old     new   delta
xfunc_has_died                                         -      21     +21
sleep_much                                             -      12     +12
sleep10                                                -       9      +9
die_func                                               -       4      +4
fflush_stdout_and_exit                                35      36      +1
builtin_type                                         121     119      -2
die_sleep                                              4       -      -4
xfunc_die                                             60      24     -36
hush_main                                           1128    1011    -117
die_jmp                                              156       -    -156
------------------------------------------------------------------------------
(add/remove: 4/2 grow/shrink: 1/3 up/down: 47/-315)          Total: -268 bytes
   text	   data	    bss	    dec	    hex	filename
 939992	    992	  17652	 958636	  ea0ac	busybox_old
 939880	    992	  17496	 958368	  e9fa0	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 16:42:57 +02:00
Denys Vlasenko 4cd99e7c6c ash: "you have mail" should ignore first change in mtime
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 16:02:53 +02:00
Denys Vlasenko 2384162f64 ash: simplify "you have mail" code
function                                             old     new   delta
mailtime_hash                                          -       4      +4
redirect                                            1282    1280      -2
mailtime                                              40       -     -40
cmdloop                                              429     378     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 4/-93)             Total: -89 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 15:52:03 +02:00
Denys Vlasenko 4700fb5bea ash: make dowait() a bit more readable. Logic is unchanged
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 15:40:13 +02:00
Denys Vlasenko e1603156ff updated android_ndk_defconfig
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 18:17:31 +02:00
Denys Vlasenko f2bf20f5d5 udhcpc: fix for some Android toolchain breakage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 18:13:57 +02:00
Denys Vlasenko 8403b01217 iproute: more string reuse
text	   data	    bss	    dec	    hex	filename
 936892	    932	  17676	 955500	  e946c	busybox_old
 936843	    932	  17676	 955451	  e943b	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 17:15:08 +02:00
Christoph J. Thompson d1eea8db92 iproute: don't hardcode the path to config files
Allows using an alternate path for config files.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Christoph J. Thompson <cjsthompson@gmail.com>
Signed-off-by: Michael Bestas <mikeioannina@gmail.com>
2015-10-08 17:06:06 +02:00
Denys Vlasenko 413feca279 ip: increased max ID for /etc/iproute2/rt_tables to 1023
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 15:10:10 +02:00
Denys Vlasenko 3d8d5e8ad4 libiproute: use itoa() where appropriate
function                                             old     new   delta
rtnl_rtprot_a2n                                       31      88     +57
print_tunnel                                         647     640      -7
print_route                                         1865    1858      -7
print_linkinfo                                       820     812      -8
print_addrinfo                                      1241    1227     -14
rtnl_rttable_n2a                                      53      38     -15
rtnl_rtscope_n2a                                      53      38     -15
rtnl_rtrealm_n2a                                      53      38     -15
rtnl_dsfield_n2a                                      61      38     -23
rtnl_rtntype_n2a                                     118      89     -29
print_rule                                           724     689     -35
ipaddr_list_or_flush                                1293    1253     -40
rtnl_rtprot_n2a                                       53       -     -53
rtnl_rtprot_initialize                                63       -     -63
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/11 up/down: 57/-324)         Total: -267 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 13:02:28 +02:00
Denys Vlasenko 7f3a2a2256 join some common strings, -400 bytes
function                                             old     new   delta
print_intel_cstates                                  499     511     +12
file_insert                                          355     364      +9
dpkg_main                                           2944    2940      -4
ifenslave_main                                       645     640      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 21/-9)              Total: 12 bytes
   text	   data	    bss	    dec	    hex	filename
 937564	    932	  17676	 956172	  e970c	busybox_old
 937164	    932	  17676	 955772	  e957c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 11:24:44 +02:00
Denys Vlasenko d60752f8c9 build system: -fno-builtin-printf
Benefits are: drops reference to out-of-line putchar(), fixes a few cases
of failed string merge.

function                                             old     new   delta
i2cdump_main                                        1488    1502     +14
sha256_process_block64                               423     433     +10
sendmail_main                                       1183    1185      +2
list_table                                          1114    1116      +2
i2cdetect_main                                      1235    1237      +2
fdisk_main                                          2852    2854      +2
builtin_type                                         119     121      +2
unicode_conv_to_printable2                           325     324      -1
scan_recursive                                       380     378      -2
mkfs_minix_main                                     2687    2684      -3
buffer_fill_and_print                                178     169      -9
putchar                                              152       -    -152
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 7/4 up/down: 34/-167)          Total: -133 bytes
   text    data     bss     dec     hex filename
 937788     932   17676  956396   e97ec busybox_old
 937564     932   17676  956172   e970c busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 22:42:45 +02:00
Denys Vlasenko 8c0708a329 find: support "find . -delete" idiom - do not try rmdir(".")
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 21:01:47 +02:00
Denys Vlasenko 305958dbd4 md5sum: code shrink
For CONFIG_MD5_SMALL=1:
function                                             old     new   delta
md5_process_block64                                  925     881     -44

For CONFIG_MD5_SMALL=0:
function                                             old     new   delta
md5_process_block64                                 1603    1586     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 19:17:01 +02:00
Denys Vlasenko ec046f74a3 ash: use a more typical form of "print four octal digits" format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:57:53 +02:00
Denys Vlasenko 5711a2a4ad libbb: more compact API for bb_parse_mode()
function                                             old     new   delta
make_device                                         2182    2188      +6
parse_command                                       1440    1443      +3
parse_params                                        1497    1499      +2
install_main                                         773     769      -4
mkdir_main                                           168     160      -8
getoptscmd                                           641     632      -9
builtin_umask                                        158     147     -11
bb_parse_mode                                        431     410     -21
umaskcmd                                             286     258     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/6 up/down: 11/-81)            Total: -70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:55:33 +02:00
Denys Vlasenko c1e2e005b4 ash: shrink "umask -S" code
function                                             old     new   delta
umaskcmd                                             279     286      +7
static.permmode                                        3       -      -3
static.permmask                                       18       -     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:32:56 +02:00
Denys Vlasenko 6283f98283 hush: fix umask: umask(022) was setting umask(755)
Based on the patch by Rich Felker <dalias@libc.org>

function                                             old     new   delta
builtin_umask                                        121     161     +40
umaskcmd                                             318     279     -39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 16:56:20 +02:00
Denys Vlasenko 9c5410023a ash: a bunch of trivial simplifications
Also, in a few places made code more reliable wrt large sizeof(int)
and sizeof(arith_t)..

function                                             old     new   delta
sprint_status48                                        -     143    +143
newline_and_flush                                      -      56     +56
showjob                                              365     382     +17
parse_command                                       1440    1443      +3
cmdputs                                              334     332      -2
cmdloop                                              434     429      -5
showjobs                                              70      64      -6
fg_bgcmd                                             296     290      -6
ash_vmsg                                             159     153      -6
ash_main                                            1487    1481      -6
jobscmd                                               94      82     -12
getoptscmd                                           687     632     -55
outcslow                                              56       -     -56
sprint_status                                        156       -    -156
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/8 up/down: 219/-310)          Total: -91 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 15:44:36 +02:00
Denys Vlasenko 2007ef5c3c wget: make it possible to have both SSL helpers configured
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 02:40:53 +02:00
Denys Vlasenko 4271698fea ifplugd: discovered why it needed net/ethernet.h: just for ETH_ALEN
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 02:02:56 +02:00
Denys Vlasenko 78fb6ea63a ssl_helper: tweaks discovered while building 32-bit version
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 02:00:11 +02:00
Denys Vlasenko 1c6c670ed4 wget: make openssl/ssl_helper choice configurable
I got sick of not being able to wget a https file...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 01:39:40 +02:00
Denys Vlasenko 3b650c1e7b qemu testing: extract_od_binary.sh: support huge files (and broken od)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 16:46:29 +02:00
Denys Vlasenko 2b48c38be6 uudecode: tolerate text input with CR+LF line ends
function                                             old     new   delta
read_stduu                                           265     308     +43
uudecode_main                                        313     317      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 15:10:44 +02:00
Denys Vlasenko e6b578761a qemu testing: Do build brctl and ifplugd; force mips32 dialect
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 12:43:04 +02:00
Denys Vlasenko a779c6d63b qemu testing: fix hexdumping of binary
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 12:34:24 +02:00
Denys Vlasenko 5fa6d1a632 Aboriginal linux/musl build fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 11:15:43 +02:00
Denys Vlasenko 12efcf3285 Add qemu_multiarch_testing/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 09:04:04 +02:00
Denys Vlasenko 28b00ce6ff awk: support "length" form of "length()". Closes 8371
function                                             old     new   delta
parse_expr                                           805     848     +43
tokenlist                                            447     448      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-02 02:41:39 +02:00
Denys Vlasenko c919d561ad umount: always use umount2 syscall with specified flags
Make umount -f more compatible with util-linux 2.22.2.

Before:
  * 'umount -f': calls umount syscall,
        if it fails calls umount2 with 'MNT_FORCE'
  * 'mount -f -l': calls umount syscall,
        if it fails calls umount2 with 'MNT_LAZY'. 'MNT_FORCE' dropped
After:
  * 'umount -f': calls umount2 syscall with 'MNT_FORCE'
  * 'mount -f -l': calls umount2 syscall with 'MNT_LAZY' and 'MNT_FORCE'

function                                             old     new   delta
umount                                                45       -     -45
umount_main                                          610     555     -55

Signed-off-by: Anton Bondarenko <anton.bondarenko@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-01 18:50:06 +02:00
Denys Vlasenko c65a7596df adduser: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 21:11:12 +02:00
Bernhard Reutner-Fischer 65db14ec50 adduser: Add -k /path/to/skel
function                                             old     new   delta
.rodata                                           157069  157133     +64
adduser_main                                         921     936     +15
adduser_longopts                                     103     110      +7
packed_usage                                       30230   30236      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 92/0)               Total: 92 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 21:09:18 +02:00
Bartosz Golaszewski 2beb52499e i2c-tools: rename remaining defines
Rename the defines not present in linux UAPI headers to better reflect
their purpose.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 13:15:01 +02:00
Bartosz Golaszewski d9892fa0c3 i2c-tools: remove duplicate definitions
Most applets include linux' user API headers instead of duplicating
the definitions. Make it the case for i2c-tools as well.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 13:15:00 +02:00
Denys Vlasenko 8aa7cf305b sort: fix -kN,M handling (was including last separator into the comparison)
Testcase:

$ printf '%s\n' a/a:a a:b | sort -t: -k1,1
a:b
a/a:a

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-19 22:06:40 +02:00
Tito Ragusa f085344d5c libbb: another unit test for is_suffixed_with
Suggested by Bartosz Golaszewski.

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-15 23:38:01 +02:00
Peter Korsgaard 875297378c modprobe: handle module arguments containing spaces
Modprobe wasn't correctly parsing module arguments containing spaces from
/proc/cmdline - E.G. module.property="some text".

Extend the parsing to correctly handle quoted text.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-09 14:55:07 +02:00
Ron Yorston ca25af9b06 ash: fix slash treatment in expmeta
Commit 549deab caused this sequence of commands:

   mkdir foo
   cd foo
   touch a b
   echo "./"*

to return './*' instead of the expected './a ./b'.  The problem
was caused by the backport of commit 880d952 from dash.  In dash
the issue was fixed by two further commits by Herbert Xu:

<d6d06ff> [EXPAND] Fixed non-leading slash treatment in expmeta
<36f0fa8> [EXPAND] Fix slash treatment in expmeta

(See git://git.kernel.org/pub/scm/utils/dash/dash.git)

Apply these fixes to BusyBox ash, thus causing the new test
glob3.tests to succeed.

function                                             old     new   delta
expmeta                                              469     528     +59

Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 22:23:54 +02:00
Denys Vlasenko b5be13ccd9 hush: fix a nommu bug where a part of function body is lost if run in a pipe
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 06:22:10 +02:00
Denys Vlasenko 2156e22853 Makefile.flags: survive a build system which has no pthread
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 04:20:51 +02:00
Denys Vlasenko 26c423d9a8 ash,hush: add a test which fails for ash since commit 549deab
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 03:33:02 +02:00
Denys Vlasenko 66a781acb9 ash: add tests adapted from hush glob tests. glob2.tests currently fails
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 03:27:08 +02:00
Denys Vlasenko 68acc0f835 libbb: make is_suffixed_with() return pointer inside string, not key.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 21:47:33 +02:00
Bartosz Golaszewski 7448b513c8 libbb: add is_suffixed_with() function
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 16:36:43 +02:00
Denys Vlasenko 5b865deb3f ping: fix recently introduced build breakage for non-optimizing builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 16:26:31 +02:00
Bartosz Golaszewski 0a4d0e8fbf libbb: add a comment describing the way is_prefixed_with() works
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 15:04:16 +02:00
Bartosz Golaszewski b432923e29 libbb: add unit tests for is_prefixed_with()
Test corner cases too like looking for an empty prefix etc.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 15:00:24 +02:00
Sören Tempel d862717328 login: don't print motd if .hushlogin exists in users home
function                                             old     new   delta
login_main                                           978     996     +18

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 22:16:48 +02:00
Peter Korsgaard 864d1b7a15 dmesg: add -r option to print raw format even when FEATURE_DMESG_PRETTY is enabled
Similar to the "big" util-linux version. For !DMESG_PRETTY, the option is accepted
(but ignored) as well, for compatibility reasons.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 21:08:02 +02:00
Alex Dowad 65c501a093 ifupdown: 'prio' should have been 'metric' in static_up and static_up6
When a static interface with explicit gateway and metric in /etc/network/interfaces
is enabled using 'ifup', and further, the BusyBox 'ip' applet is enabled, the
following error message appears at the console (and no default route is added):

ip: either "to" is duplicate, or "prio" is garbage

Tracing ifup reveals that it is attempting to run the following shell command:

ip route add default via <GW> dev <DEVICE> prio <METRIC>

'ip' does not understand the 'prio' argument, causing this error. With 'metric',
it works fine.

Signed-off-by: Alex Dowad <alexinbeijing@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:18:36 +02:00
Denys Vlasenko c52cbea2bb libbb: add setsockopt_foo helpers
function                                             old     new   delta
setsockopt_int                                         -      23     +23
do_load                                              918     934     +16
setsockopt_SOL_SOCKET_int                              -      14     +14
setsockopt_keepalive                                   -      10     +10
setsockopt_SOL_SOCKET_1                                -      10     +10
buffer_fill_and_print                                169     178      +9
setsockopt_1                                           -       8      +8
nfsmount                                            3560    3566      +6
redirect                                            1277    1282      +5
tcpudpsvd_main                                      1782    1786      +4
d6_send_kernel_packet                                272     275      +3
i2cget_main                                          380     382      +2
ed_main                                             2544    2545      +1
scan_recursive                                       380     378      -2
nbdclient_main                                       492     490      -2
hash_find                                            235     233      -2
cmdputs                                              334     332      -2
parse_command                                       1443    1440      -3
static.two                                             4       -      -4
ntpd_main                                           1039    1035      -4
const_int_1                                            4       -      -4
const_IPTOS_LOWDELAY                                   4       -      -4
RCVBUF                                                 4       -      -4
ntp_init                                             474     469      -5
change_listen_mode                                   316     310      -6
uevent_main                                          416     409      -7
arping_main                                         1697    1690      -7
telnet_main                                         1612    1603      -9
socket_want_pktinfo                                   42      33      -9
setsockopt_reuseaddr                                  21      10     -11
setsockopt_broadcast                                  21      10     -11
httpd_main                                           772     757     -15
get_remote_transfer_fd                               109      94     -15
make_new_session                                     503     487     -16
ftpd_main                                           2177    2160     -17
read_bunzip                                         1896    1866     -30
common_traceroute_main                              4099    4058     -41
common_ping_main                                    1836    1783     -53
------------------------------------------------------------------------------
(add/remove: 5/4 grow/shrink: 8/21 up/down: 111/-283)        Total: -172 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:00:17 +02:00
Denys Vlasenko 2db782bc7b Merge setsockopt error messages
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:00:17 +02:00
Denys Vlasenko 729b70646c traceroute: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:00:17 +02:00
Bartosz Golaszewski bb2fd67d0b Makefile: add missing libraries to LDLIBS
Static build with CONFIG_PAM fails on Debian Jessie due to undefined
references to libdl and libaudit.

Static build without pam, but with libcrypt required fails as well due
to undefined references to libpthread.

Fix these two cases by adding the missing libraries to LDLIBS when
appropriate.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-17 17:05:55 +02:00
Bartosz Golaszewski 718e228adc unit-tests: remove code depending on WANT_TIMING
Since there is no interest in merging a config option for WANT_TIMING,
remove the parts of code depending on it altogether.

While we're at it: add some newlines to improve readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-17 17:01:49 +02:00
Bartosz Golaszewski d077565bb2 unit-tests: remove unnecesary field from struct bbunit_listelem
In the initial submission struct bbunit_listelem was manipulated by
custom list functions implemented in bbunit.c. Since the tests are now
added to the list by llist_add_to_end(), which allocates the llist_t
objects behind the scenes, there's no need for the *next field.

function                                             old     new   delta
unit_main                                            142     141      -1
bbunit_strrstr_elem                                   24      16      -8
bbunit_obscure_weak_pass_elem                         24      16      -8
bbunit_obscure_strong_pass_elem                       24      16      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-17 17:00:10 +02:00
Denys Vlasenko fb52769f4a arping: make help text clearer
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-16 19:56:16 +02:00
Ron Yorston 26ccd3d062 less: fix botched attempt to use last column
Commit 1ecb996 attempted to make read_lines() use the last column of
the terminal (as re_wrap() did).  There were two problems with this:

- The size of the buffer allocated for lines wasn't increased to allow
  for the extra character.

- The test for width overflow was moved after the point where the
  next character was added to the buffer.  This caused a buffer overflow
  in certain circumstances.

  For example, if the line beyond the end of the display was wider than
  the display read_lines() would initially read the partial line into a
  buffer.  When the user moved down read_lines() would be called again
  to ensure the rest of the line was read.  This would place the next
  character in the partial line before checking for overflow.

  This can be fixed by moving the test for overflow back to where it was
  before commit 1ecb996 and changing the comparison to `>` rather than
  `>=`.

There are two other places where buffers are created without allowing
for width+1 characters.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-16 18:54:49 +02:00
Ron Yorston 72dcbe4df7 ipcalc: fix trivial usage message
Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-15 21:15:27 +02:00
Denys Vlasenko a83e3ae172 zcip: tweak comments and make unsigned division more obvious
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 15:06:38 +02:00
Denys Vlasenko e347583835 zcip: another code shrink
function                                             old     new   delta
send_arp_request                                       -     185    +185
zcip_main                                           1273    1272      -1
pick_nip                                              40       -     -40
arp                                                  185       -    -185
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 0/1 up/down: 185/-226)          Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 14:30:31 +02:00
Denys Vlasenko 99e30be38b zcip: code shrink
function                                             old     new   delta
zcip_main                                           1263    1230     -33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 12:28:21 +02:00
Denys Vlasenko 16aa7a73c4 zcip: simplify code
function                                             old     new   delta
zcip_main                                           1411    1263    -148

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 03:27:56 +02:00
Ron Yorston 64ed5f0d3c uname: make OS name configurable
A mailing list thread in September 2013 discussed changing the string
returned by the non-POSIX 'uname -o' option.  Nothing ever came of this
because there was no agreement as to what the string should be.

Make the string configurable so that people can decide for themselves.

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-03 18:09:18 +02:00
Ron Yorston b27cf31003 less: further tweaks to regular file detection
Test explicitly for REOPEN flags:  update_num_lines is called
unconditionally so (num_lines != NOT_REGULAR_FILE) is also true when
num_lines contains a valid number of lines.

The call to fstat doesn't need to be in #if ENABLE_FEATURE_LESS_FLAGS:
the whole function is already in such a test.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-03 16:41:19 +02:00
Aaro Koskinen ad27a6d326 diff.tests: add testcases for -B and single line changes
Add testcases for -B and single line changes.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:51:15 +02:00
Aaro Koskinen a47fccaa63 diff: fix -B with single line changes
Fix -B with single line changes. They were always ignored regardless
if they were blank or not.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:50:49 +02:00
Denys Vlasenko 9dc526d0f9 less: improve regular file detection in line counting code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:42:20 +02:00
Ron Yorston 1ecb996fd2 less: allow use of last column of terminal
When read_lines tests whether a character will fit on the current
line it checks the *next* character but in case of overflow doesn't
display the *current* one.  This results in the last column of the
terminal never being used.

The test in re_wrap (used when the terminal width changes or line
numbers are enabled/disabled) is different:  it does allow the use
of the final column.

function                                             old     new   delta
read_lines                                           764     770      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 6/0)                 Total: 6 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:09 +02:00
Ron Yorston d542d183e1 less: fix line number confusion
Much of the code refers to lines using indices into the flines
array (which splits lines into portions that fit on the terminal).
In some cases this is wrong and actual line numbers should be
used:

- when lines are being truncated rather than wrapped (-S flag)
- when line numbers have been entered by the user

Also fix a bug in numeric input and improve the display at EOF.

function                                             old     new   delta
goto_lineno                                            -     111    +111
cap_cur_fline                                          -     101    +101
buffer_to_line                                         -      56     +56
buffer_up                                             35      66     +31
less_main                                           2606    2615      +9
goto_match                                           125     127      +2
buffer_down                                           81      56     -25
buffer_line                                           64       -     -64
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 3/1 up/down: 310/-89)           Total: 221 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:08 +02:00
Ron Yorston ad1b4d5882 less: add a function to detect when display is at end of file
Add a function to package the test that detects whether enough has
been read from the file to allow a screenful to be displayed.

Also use this to determine when to display '(END)' in the status
line.  The previous code was incomplete and didn't handle truncated
lines (-S flag) properly.

function                                             old     new   delta
at_end                                                 -      63     +63
status_print                                         111     109      -2
read_lines                                           819     764     -55
getch_nowait                                         319     264     -55
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 63/-112)           Total: -49 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:08 +02:00
Ron Yorston 70b84be9e8 less: rearrange detection of non-regular files
Move the code to detect non-regular files to the point where the
file is being opened.  If num_lines == READING_FILE guarantees
that the file is regular.

Detect when a file becomes unreadable between it first being opened
and the call to update_num_lines.  Mark the file as being non-regular
so we don't try that again.

function                                             old     new   delta
reinitialize                                         197     245     +48
update_num_lines                                     159     127     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-32)             Total: 16 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:07 +02:00
Ron Yorston 159e032bf4 less: move code to count lines into a separate function
function                                             old     new   delta
update_num_lines                                       -     159    +159
m_status_print                                       409     266    -143
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 159/-143)           Total: 16 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:07 +02:00
Ron Yorston ae1a9e899e less: fix numeric input
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 15:33:53 +02:00
Mike Frysinger 670c3f7822 echo: make escape sequences depend on fancy mode
Currently when you disable fancy echo, escape sequences are hardcoded
enabled (e.g. as if you used `echo -e` all the time).  The opposite
behavior is more desirable (always disable -e support) because:
* This seems to contradict the spirit of the kconfig help text (where
  it says enable support for -n/-e flags), although you could say that
  we aren't supporting the -e flag directly as `echo -e` will show the
  -e flag.
* POSIX makes escape sequences optional, and even says they are there
  only on XSI-conformant systems.
* It saves space (~100 bytes on x86_64).
* It makes things faster!
* It makes it behave more like bash where you need an explicit -e flag
  in order for escape sequences to be interpreted.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 03:47:49 +02:00
Linus Walleij 52f2f37477 fbset: fix rgba parsing
In commit b5c7220e7b
"fbset: respect rgba configuration lines in fb.modes"
I somehow managed to swap the offset/length markers around.
The man page for fb.modes says it should be offset/length
not length/offset as I was accidentally parsing it.

As my fb.modes file was also reversed I didn't notice
until I tried someone elses fb.modes file. Mea culpa.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-30 03:05:46 +02:00
Arthur Gautier c29021e2a5 udhcpc: dns labels can actually start with a number
While RFC1035 recommends a label not to start with a number, there is
actually no such limitation in dns. One may buy a domain name like
0x1.net and use it.

This commit remove this check and allow a user to use such domains.

Signed-off-by: Arthur Gautier <baloo@gandi.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-30 03:03:58 +02:00
Ron Yorston 193ba408a4 less: improvements to verbose status messages
Make verbose status messages (-m/-M flags) behave more like the
real `less` command:

- fix display of line numbers so they're correct whether lines are
  being truncated (-S flag) or wrapped.
- don't display total lines or percentage when lines are read from
  stdin:  we don't have that information until we reach EOF.  When
  we do reach EOF the additional information is displayed.
- when lines are read from a file count the total number of lines
  so that we can display percentages.  Counting lines is avoided
  until the information is actually needed.  If the user pages to
  EOF the separate read pass can be avoided entirely.

Fixes Bug 7586

function                                             old     new   delta
m_status_print                                       195     382    +187
safe_lineno                                            -      35     +35
reinitialize                                         172     182     +10
read_lines                                           675     685     +10
buffer_fill_and_print                                178     169      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 242/-9)            Total: 233 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-21 22:28:09 +02:00
Denys Vlasenko 35ae2ccb40 sync: add support for -d -f FILE
Based on the patch by Ari Sundholm <ari@tuxera.com>

function                                             old     new   delta
sync_main                                             20     163    +143
packed_usage                                       30653   30673     +20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 163/0)             Total: 163 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-21 19:50:48 +02:00
Denys Vlasenko ce193f809b Remove old_e2fsprogs/*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 23:12:51 +02:00
Ron Yorston d840c5d139 libbb: add a function to make a copy of a region of memory
Introduce a library routine to package the idiom:

    p = xmalloc(b, n);
    memcpy(p, b, n);

and use it where possible.  The example in traceroute used xzalloc
but it didn't need to.

function                                             old     new   delta
xmemdup                                                -      32     +32
last_main                                            834     826      -8
make_device                                         2321    2311     -10
common_traceroute_main                              3698    3685     -13
readtoken1                                          3182    3168     -14
procps_scan                                         1222    1206     -16
forkchild                                            655     638     -17
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/6 up/down: 32/-78)            Total: -46 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 23:05:20 +02:00
Ron Yorston 78cfa00154 less: correctly account for tabs when rewrapping lines
Lines are rewrapped when the terminal width changes or line numbers
are enabled/disabled.  The current calculation always adds eight to
the line length for a tab whereas it should only add enough to move
to the next tab stop.

This doesn't affect the display of lines, which is handled elsewhere
and gets tab stops right, but it does cause lines to be wrapped at
the wrong position.

Signed-off-by:  Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 22:50:25 +02:00
Ron Yorston f06386ad4f less: fix display of line numbers
Line numbers are displayed incorrectly on lines that have a search
pattern highlighted.  The problem can be fixed by moving the call to
lineno_str in print_found above the while loop that alters the value
of the line pointer.  However, a more substantial rewrite results in
savings.

function                                             old     new   delta
buffer_print                                         688     697      +9
.rodata                                           156077  156045     -32
lineno_str                                            85       -     -85
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 9/-117)           Total: -108 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 22:48:05 +02:00
Ron Yorston 51aa861843 less: document -S flag and make it independently configurable
The -S flag, to cause long lines to be truncated, was enabled by
FEATURE_LESS_DASHCMD.  This is non-obvious and -S is useful even
if the '-' command isn't enabled.

function                                             old     new   delta
.rodata                                           156045  156077     +32
packed_usage                                       30223   30244     +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 53/0)               Total: 53 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 22:34:13 +02:00
Ron Yorston 072fc60f29 ash: use alloca to get rid of setjmp
Now that the only thing protected by setjmp/longjmp is the saved string,
we can allocate it on the stack to get rid of the jump.

Based on commit bd35d8e from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken1                                          3182    3116     -66
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-66)             Total: -66 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 04:02:45 +02:00
Denys Vlasenko f54a487bb4 fix file mode
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:52:32 +02:00
Ron Yorston 0e056f7e9e ash: remove parsebackquote flag
Commit 503a0b8 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu says:

  >The parsebackquote flag is only used in a test where it always has the
  >value zero.  So we can remove it altogether.

The first statement is incorrect:  parsebackquote is non-zero when
backquotes (as opposed to $(...)) are used for command substitution.
It is possible for the test to be executed with parsebackquote != 0 in
that case.

The test is question checks whether quotes have been closed, raising
the error "unterminated quoted string" if they haven't.  There seems
to be no good reason to allow unclosed quotes within backquotes.  Bash,
hush and dash (after commit 503a0b8) all treat the following as an error:

   XX=`"pwd`

whereas BusyBox ash doesn't.  It just ignores the unclosed quote and
executes pwd.

So, parsebackquote should be removed but not for the reason stated.

function                                             old     new   delta
parsebackquote                                         1       -      -1
readtoken1                                          3222    3182     -40
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-41)             Total: -41 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:50:27 +02:00
Maninder Singh 97f2f7ca7f Removes stray empty line from code
This patch removes stray empty line from busybox code
reported by script find_stray_empty_lines

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:25:46 +02:00
Clayton Shotwell b7ee7e1e13 applets: Add installation of individual binaries
Adding support to install individual binaries if the option is
enabled. This also installs the shared libbusybox.so.* library.

Signed-off-by: Clayton Shotwell <clshotwe@rockwellcollins.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 19:10:03 +02:00
Denys Vlasenko c9091d8947 ps: fix SEGV on narrow screens. closes 8176
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 19:07:24 +02:00
Denys Vlasenko db31c637fa ipaddress: better formatting, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 18:36:06 +02:00
Michael Tokarev 6a7cd3d4ab ip addr: support change and replace commands
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 18:26:41 +02:00
Maninder Singh 7db312ad26 fix whitespaces
reported by script :- scripts/fix_ws.sh

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:19:47 +02:00
Maninder Singh 0fabedf085 fix if(p)/free(p) construct
No need of explicit NULL check before free.

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:19:43 +02:00
Bartosz Golaszewski d90899206d i2cdetect: use break instead of goto in list_i2c_busses_and_exit()
Since there are now more statements in the if block after the while loop
in list_i2c_busses_and_exit(), there's no need for a label.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:47 +02:00
Bartosz Golaszewski aeb11a9496 i2cdump: code rework
Split i2cdump_main() into shorter functions. Simplify the code a bit.
Make block an array of ints so that we can store negative results of
read functions (fixes a bug found by Denys Vlasenko).

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:47 +02:00
Bartosz Golaszewski 2204472497 i2cdetect: add a check for (mode == DETECT_MODE_AUTO)
We should only warn the user about addresses to be skipped if
(mode == DETECT_MODE_AUTO).

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:47 +02:00
Bartosz Golaszewski e545bf6723 i2cdetect: don't scan non-regular addresses without the '-a' option
Addresses 0x00-0x02 shouldn't be scanned by default. This patch makes
'first' default to 0x03 and only enables lower addresses if '-a' option
is passed

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:46 +02:00
Bartosz Golaszewski 314742747d i2cdetect: don't die on addresses already in use by drivers
We can't use i2c_set_slave_addr() in i2cdetect, as we have to check for
EBUSY after calling ioctl(I2C_SLAVE) and print 'UU' on busy addresses
instead of bailing-out.

While we're at it: reorder definitions of local vars in i2cdetect_main().

function                                             old     new   delta
i2cdetect_main                                       703     744     +41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 41/0)               Total: 41 bytes
   text	   data	    bss	    dec	    hex	filename
 826097	   4164	   9584	 839845	  cd0a5	busybox_old
 826145	   4164	   9584	 839893	  cd0d5	busybox_unstripped

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:34 +02:00
Junling Zheng d291c2fdd5 chown: fix help text
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 02:32:23 +02:00
Ari Sundholm fc3e40ee81 truncate: do not die when a file doesn't exist and no-create flag is on
Additionally, open(2) failures do not make the program die immediately.
This makes the behavior of the program match coreutils more closely.

function                                             old     new   delta
truncate_main                                        161     221     +60

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 15:17:03 +02:00
Denys Vlasenko 7f4a49a96c Print one less newline at the end of bb_show_usage()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 14:30:52 +02:00
Maninder Singh 97c6491b4e typo fixes
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 13:46:36 +02:00
Denys Vlasenko c4603fb09a dc: fix "dc p" prinitng bogus data
function                                             old     new   delta
check_under                                            -      20     +20
print_no_pop                                          27      32      +5
pop                                                   33      24      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 25/-9)              Total: 16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 13:31:25 +02:00
Denys Vlasenko b878121e76 tc: fix print_rate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-24 18:01:53 +02:00
Denys Vlasenko 9a595bb36d hush: add recent ash tests to hush testsuite too (they all pass for hush)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 10:23:16 +02:00
Ron Yorston 523006798c testsuite: add some tests for ash
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 10:13:21 +02:00
Ron Yorston 417622cc2e ash: fix breakage of ${v/pat/str}
The commit

   ash: move parse-time quote flag detection to run-time

breaks pattern substitution in parameter expansion.  Fix this and
revise the code so that the different handling of the pattern and
the replacement string takes place in rmescapes rather than the
separate function parse_sub_pattern.

function                                             old     new   delta
rmescapes                                            227     273     +46
static.qchars                                          3       4      +1
subevalvar                                          1177    1157     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 47/-20)             Total: 27 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:59:14 +02:00
Ron Yorston 549deab5ab ash: move parse-time quote flag detection to run-time
Because the parser does not recursively parse parameter expansion
with respect to quotes, we can't accurately determine quote status at
parse time.  This patch works around this by moving the quote detection
to run-time where we do interpret it recursively.

Test case:
   foo=\\ echo "<${foo#[\\]}>"
Old result:
   <\>
New result:
   <>

Do not quote back slashes in parameter expansions outside quotes.

Test case:
   a=/b/c/*
   b=\\
   echo ${a%$b*}
Old result:
   /b/c/*
New result:
   /b/c/

Based on commits 880d952, 7cfd8be, 0d7d660 and a7c21a6 from
git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu

function                                             old     new   delta
argstr                                              1164    1193     +29
memtodest                                            147     174     +27
subevalvar                                          1153    1177     +24
redirect                                            1279    1282      +3
dolatstr                                               5       7      +2
static.spclchars                                      10       9      -1
expandarg                                            962     960      -2
evalcase                                             273     271      -2
evalcommand                                         1204    1197      -7
rmescapes                                            236     227      -9
preglob                                               27       8     -19
evalvar                                              604     582     -22
cmdputs                                              389     334     -55
readtoken1                                          3163    3061    -102
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/9 up/down: 85/-219)          Total: -134 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:57:51 +02:00
Ron Yorston ad88bdee0c ash: remove arithmetic expansion collapsing at parse time
Collapsing arithmetic expansion is incorrect when the inner arithmetic
expansion is a part of a parameter expansion.

Test case:
   unset a
   echo $((3 + ${a:=$((4 + 5))}))
   echo $a
Old result:
   12
   (4 + 5)
New result:
   12
   9

Based on commit bb777a6 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
readtoken1                                          3180    3163     -17

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:56:16 +02:00
Ron Yorston 7e4ed267b6 ash: remove superfluous code in arithmetic mode
Based on commits 1a74845, cfc3d6a and ff13779 from
git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu

function                                             old     new   delta
evalcommand                                         1197    1204      +7
localcmd                                             327     325      -2
readtoken1                                          3200    3180     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 7/-22)             Total: -15 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:54:43 +02:00
Ron Yorston 3df47f9cbb ash: do not expand tilde in parameter expansion within quotes
Test case:
   unset a
   echo "${a:-~root}"
Old result:
   /root
New result:
   ~root

Based on commit 170f44d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
evalvar                                              598     604      +6
parse_command                                       1440    1443      +3
localcmd                                             325     327      +2
readtoken1                                          3199    3200      +1
argstr                                              1180    1164     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 12/-16)             Total: -4 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:53:26 +02:00
Ron Yorston eb6b48ba74 ash: perform tilde expansion in all parameter expansion words
Previously tilde expansion was not carried out for =?#% expansion words.

Test case:
   a=~root:~root
   echo ${a#~root}
Old result:
   /root:/root
New result:
   :/root

Based on commit dd721f71 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
subevalvar                                          1152    1153      +1

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:51:35 +02:00
Ron Yorston d68d1fbd6c ash: code shrink around varvalue
Based on commit c989d72 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
strtodest                                              -      40     +40
memtodest                                            123     147     +24
parse_command                                       1443    1440      -3
readtoken1                                          3205    3199      -6
argstr                                              1203    1180     -23
varvalue                                             788     660    -128
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/4 up/down: 64/-160)           Total: -96 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:49:28 +02:00
Denys Vlasenko e0a4e107aa ash: explain what "local -" does
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-13 02:20:14 +02:00
Eugene Rudoy 1285aa62f9 ash: consider "local -" case while iterating over local variables in mklocal.
fixes segfault introduced in 0a0acb55db with functions using "local -".
test-case: f() { local -; local x; }; f

note: with this change applied multiple 'local -'s still cause multiple entries to be added to the localvars list.
this problem will be addressed in a separate commit.

Signed-off-by: Eugene Rudoy <gene.devel@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-13 02:09:53 +02:00
Daniel Thompson a818777d42 libbb: Enable support for !CONFIG_MULTIUSER
Linux recently gained a new config option, CONFIG_MULTIUSER, that makes
support for non-root users optional. This results in a number of syscalls
being disabled: setuid, setregid, setgid, setreuid, setresuid, getresuid,
setresgid, getresgid, setgroups, getgroups, setfsuid, setfsgid, capget,
capset.

Currently a number of busybox applets, including login, struggle to run
when CONFIG_MULTIUSER is disabled. Even the root user is unable to login:
  login: can't set groups: Functi

This patch adds code to make change_identity() a nop on single user
systems. It works by recognising the signature errno value (ENOSYS, due
to the system calls being disabled) and, to avoid security risks, only
deploys when the current uid and target uid is the same.

After the patch is applied any attempt to switch to a non-root user will
fail. Thus a badly configured userspace (for example, one that tries to
start a daemon as a non-root user when the kernel cannot support this)
will report errors as one would expect.

Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-12 23:59:57 +02:00
Bartosz Golaszewski 7ca5c51cc8 i2c-tools: only try /dev/i2c/* if opening /dev/i2c-* fails with ENOENT
Trying to access /dev/i2c/* on every error after opening /dev/i2c-* can
mislead users who e.g. don't have root access. Instead of bailing-out
with "permission denied" we currently print "no such file or directory".

Fix it by trying open("/dev/i2c/%d") only if we got ENOENT.

Upstream i2cdetect tries to get any info it can from /sys and /proc even
when invoked by an unprivileged user, but we don't want to add unnecessary
bloat.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 17:26:27 +02:00
Bartosz Golaszewski b2cca32a37 i2c-tools: fix 'i2cdetect -l'
Calling 'i2cdetect -l' only displays usage and exits. Fix it by
correctly parsing command-line arguments.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 17:24:03 +02:00
Thiago Jung Bauermann 17b16223f3 bzcat.tests: Run both .gz and .bz2 tests, and add .Z tests
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 17:19:22 +02:00
Denys Vlasenko bdb540e04f tar: do not try to decode GNU extended headers as pax headers
function                                             old     new   delta
get_header_tar                                      1736    1692     -44

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 16:55:16 +02:00
Matt Whitlock 778efe37ee Conditionalize Bionic workarounds on __ANDROID_API__
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 19:33:32 +02:00
Matt Whitlock f23e3ec529 Bionic lacks mempcpy; enable existing workaround
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:57:44 +02:00
Thiago Jung Bauermann b4059f6309 libarchive: auto-detect .Z files as well
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:40:12 +02:00
Denys Vlasenko c77a58fb2d typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:24:33 +02:00
Andrew Fuller 4d8ddb810d vi: basic undo feature shouldn't depend on yankmark
Currently basic undo functionality with the 'u' key depends on
FEATURE_VI_YANKMARK. These two features are separate, so we can remove this
dependency.

Signed-off-by: Andrew Fuller <abf@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:18:25 +02:00
Aaro Koskinen bbd53216f8 gzip: add support for compression levels 4-9
function                                             old     new   delta
gzip_main                                            192     282     +90
static.gzip_level_config                               -      24     +24
packed_usage                                       30439   30459     +20
fill_window                                          216     220      +4
pack_gzip                                           1789    1729     -60
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 138/-60)            Total: 78 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-26 14:22:37 +02:00
Matt Whitlock 93b98ff572 Bionic lacks tcdrain; provide a workaround
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-26 13:14:50 +02:00
Matt Whitlock cee59053dc Bionic lacks ttyname_r; provide a workaround
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-25 21:32:48 +02:00
Denys Vlasenko de5edadee2 special-case {true,false,test} --help
This also removes their help texts.

function                                             old     new   delta
run_applet_no_and_exit                               442     452     +10
packed_usage                                       30713   30625     -88

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-21 16:00:41 +02:00
Bernhard Reutner-Fischer 7d86384b24 include: Fallback to UTMP unless there is UTMPX support
Fixes compilation against uClibc-0.9.30 for instance

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-20 15:24:30 +02:00
Ron Yorston 61d6ae244a libbb: remove unnecessary argument to nonblock_immune_read
The loop_on_EINTR argument to nonblock_immune_read is always set to 1.

function                                             old     new   delta
xmalloc_reads                                        200     195      -5
pgetc                                                488     483      -5
argstr                                              1313    1308      -5
nonblock_immune_read                                 123      86     -37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-52)             Total: -52 bytes

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-20 13:41:32 +02:00
Denys Vlasenko ad795510d9 mdev: if a "future" mdev.seq is seen, do not overwrite it with ours
This was seen to happen if two mdevs are run in parallel,
mdev.seq is empty, and the "newer" one manages to write it first.

function                                             old     new   delta
mdev_main                                           1366    1388     +22
atoll                                                  -      20     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-19 18:55:12 +02:00
Denys Vlasenko bd77e9d609 mdev: improve logging
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-19 18:54:49 +02:00
Denys Vlasenko 73327a048b hush: document buggy handling of duplicate "local"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-18 19:38:13 +02:00
Denys Vlasenko 0a0acb55db ash: fix handling of duplicate "local"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-18 19:36:38 +02:00
Denys Vlasenko 63f4d32c98 sed: implement ",+N" range end
function                                             old     new   delta
add_cmd                                             1115    1173     +58
process_files                                       2226    2253     +27
sed_main                                             696     702      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 91/0)               Total: 91 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-17 14:24:55 +02:00
Denys Vlasenko 71a5b67ba0 uevent: new applet
This applet listens on netlink socket with kernel's uevent messages.
Run-tested.

function                                             old     new   delta
uevent_main                                            -     416    +416
packed_usage                                       30671   30713     +42
applet_names                                        2531    2538      +7
applet_main                                         1468    1472      +4
RCVBUF                                                 -       4      +4
applet_nameofs                                       734     736      +2
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 4/0 up/down: 475/0)             Total: 475 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-16 12:44:02 +02:00
Felix Fietkau f7466e4776 find: fix regression in status processing for path arguments
Regression added in commit 14158b4127
"find: add optional support for '-exec ... {} +'"

This commit causes find to exit on the first path argument that was not
found, which breaks existing scripts and is incompatible to other
implementations.

Instead of exiting on the first failure, return EXIT_FAILURE at the end
if any error occurred.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-14 16:45:23 +02:00
Alfonso Ranieri a90490fb69 volume_id: fix a buglet introduced by is_prefixed_with() conversion
Signed-off-by: Alfonso Ranieri <alforan@tin.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-14 14:32:39 +02:00
Denys Vlasenko e0ddb65cb2 build system: make CONFIG_EXTRA_LDFLAGS go to LDFLAGS, not EXTRA_LDFLAGS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-14 14:15:15 +02:00
Aaro Koskinen 7b729edd33 update copyright years
Copyright years seem to be out of date, e.g. coreutils/truncate.c
has Copyright (C) 2015.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-02 23:03:56 +02:00
Bernhard Reutner-Fischer 86a7f18f21 *: Switch to POSIX utmpx API
UTMP is SVID legacy, UTMPX is mandated by POSIX.

Glibc and uClibc have identical layout of UTMP and UTMPX, both of these
libc treat _PATH_UTMPX as _PATH_UTMP so from a user-perspective nothing
changes except the names of the API entrypoints.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-02 23:03:46 +02:00
Denys Vlasenko 1186894f77 update example ntp.script
Handle an interesting corner case when NTP server is reachable...
but on a different IP now.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-31 22:00:55 +02:00
Denys Vlasenko 9472e8a86f ftpd: change_identity() must be after chroot()
Otherwise chroot() doesn't work for non-root

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-31 21:46:26 +02:00
Denys Vlasenko 379e8e81af typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-26 10:49:02 +01:00
Denys Vlasenko 1850d5ec0e truncate: new applet
Add the actual new source file :(

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 18:00:32 +01:00
Vladislav Grishenko 4d15068d83 zcip: fix wrong comparison of source IP with our IP
Commit "zcip: fix link-local IP conflict detection" has introduced
wrong comparsion of source IP with our IP. This leads to a new IP
being picked unnecessarily on every incoming ARP packet.

Signed-off-by: Vladislav Grishenko <themiron@mail.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:59:34 +01:00
Ari Sundholm 911db16229 truncate: new applet
function                                             old     new   delta
truncate_main                                          -     161    +161
cwbkMG_suffixes                                        -     128    +128
packed_usage                                       30443   30459     +16
applet_names                                        2512    2521      +9
applet_main                                         1456    1460      +4
parse_command                                       1460    1463      +3
applet_nameofs                                       728     730      +2
applet_install_loc                                   182     183      +1
dd_suffixes                                          112       -    -112
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 10/3 up/down: 337/-133)         Total: 204 bytes

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:56:38 +01:00
Ari Sundholm 8893023ba2 dd: move suffix struct to xatonum.c
This way it can be used by other applets without duplication.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:41:04 +01:00
Phil Sutter 92edab1aa6 logread: implement dumpfollow mode of operation
This is basically a combination of the default (dump mode) and -f
(follow mode). Specifying -F makes logread first dump the log buffer and
then immediately start following it.

function                                             old     new   delta
packed_usage                                       30412   30443     +31
logread_main                                         491     497      +6

Signed-off-by: Phil Sutter <phil.sutter@viprinet.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:37:20 +01:00
Denys Vlasenko 6d8ea1d50e ifupdown: shrink a message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:08:51 +01:00
Frank Bergmann 6ca03f2dd8 ifupdown: correct ifstate update during 'ifup -a'. Closes 6212
When 'if -a' runs into an failure on an interface all further
interfaces won't be correctly updated in ifstate. This patch
inserts a new variable that only tracks the current interfaces
failure so that the write to ifstate can rely on this and not
the one for the functions return value.

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

Signed-off-by: Frank Bergmann <frank.frajasalo@googlemail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:04:27 +01:00
Ron Yorston 75a76269ba ash: do not split the result of tilde expansion
A tilde expansion generates a valid pathname. Splitting it using IFS
either leaves it unchanged or changes it to something unintended.

Example:
   IFS=m HOME=/tmp; printf "%s\n" ~

Based on this commit authored by Jilles Tjoelker:

   http://git.kernel.org/cgit/utils/dash/dash.git/commit/?id=834629283f6c629a4da05ef60bae9445c954a19a

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 16:55:44 +01:00
Mike Frysinger 6798564b9e trylink: respect compiler settings when probing features
The CPPFLAGS/CFLAGS settings might have features that matter, so make
sure we utilize them when testing the compiler.

URL: https://bugs.gentoo.org/471118
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-03-16 17:47:01 -04:00
Mike Frysinger 4a08e82d44 trylink: use mktemp instead of hardcoding paths
This way we respect standard tempdir env vars and are guaranteed to
be unique.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-03-16 17:46:17 -04:00
Denys Vlasenko 49acc1a761 vi: make BACKSPACE and DELETE join lines at start/end of line
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 21:15:34 +01:00
Ron Yorston 8ec1ff350c Use chomp to remove newlines
function                                             old     new   delta
unix_do_one                                          548     540      -8
process_timer_stats                                  508     500      -8
process_irq_counts                                   532     524      -8
lpd_main                                             839     831      -8
hwclock_main                                         502     494      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-50)             Total: -40 bytes

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 20:18:51 +01:00
Ron Yorston 53e9c51ade od: fix printing of high-bit chars
Example: echo £ | od -c

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 20:11:48 +01:00
Denys Vlasenko 8dff01d06a libbb: introduce and use is_prefixed_with()
function                                             old     new   delta
is_prefixed_with                                       -      18     +18
complete_username                                     78      77      -1
man_main                                             737     735      -2
fsck_device                                          429     427      -2
unpack_ar_archive                                     80      76      -4
strip_unsafe_prefix                                  105     101      -4
singlemount                                         1054    1050      -4
rtc_adjtime_is_utc                                    90      86      -4
resolve_mount_spec                                    88      84      -4
parse_one_line                                      1029    1025      -4
parse_conf                                          1460    1456      -4
may_wakeup                                            83      79      -4
loadkmap_main                                        219     215      -4
get_irqs_from_stat                                   103      99      -4
get_header_cpio                                      913     909      -4
findfs_main                                           79      75      -4
fbsplash_main                                       1230    1226      -4
load_crontab                                         776     771      -5
expand_vars_to_list                                 1151    1146      -5
date_main                                            881     876      -5
skip_dev_pfx                                          30      24      -6
make_device                                         2199    2193      -6
complete_cmd_dir_file                                773     767      -6
run_applet_and_exit                                  715     708      -7
uudecode_main                                        321     313      -8
pwdx_main                                            197     189      -8
execute                                              568     560      -8
i2cdetect_main                                      1186    1176     -10
procps_scan                                         1242    1230     -12
procps_read_smaps                                   1017    1005     -12
process_module                                       746     734     -12
patch_main                                          1903    1891     -12
nfsmount                                            3572    3560     -12
stack_machine                                        126     112     -14
process_timer_stats                                  449     435     -14
match_fstype                                         111      97     -14
do_ipaddr                                           1344    1330     -14
open_list_and_close                                  359     343     -16
get_header_tar                                      1795    1779     -16
prepend_new_eth_table                                340     323     -17
fsck_main                                           1811    1794     -17
find_iface_state                                      56      38     -18
dnsd_main                                           1321    1303     -18
base_device                                          179     158     -21
find_keyword                                         104      82     -22
handle_incoming_and_exit                            2785    2762     -23
parse_and_put_prompt                                 774     746     -28
modinfo                                              347     317     -30
find_action                                          204     171     -33
update_passwd                                       1470    1436     -34
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/49 up/down: 18/-540)         Total: -522 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 17:48:34 +01:00
Denys Vlasenko 936c8809ca deluser: also remove user from /etc/group
function                                             old     new   delta
update_passwd                                       1270    1470    +200
deluser_main                                         310     332     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 15:30:46 +01:00
Alexander Korolkov 748fb60f27 arping: fix iface name in error messages
arping: interface eth0 not found: No such device
                  ^^^^

This is because error template is formed before parsing command line arguments,
so it always uses default interface name "eth0".

Signed-off-by: Alexander Korolkov <alexander.korolkov@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 13:05:33 +01:00
Denys Vlasenko fe8b5802ba patch: segfault fix. Closes 7916
Fix segfault on this case (malformed --- line):

    -- dwarves.orig 2015-02-25 01:45:27.753000000 +0000
    +++ dwarves     2015-02-25 01:46:08.199000000 +0000
    @@ -1,7 +1,7 @@
     Bashful
     Doc
     Dopey
    -Grouchy
    +Grumpy
     Happy
     Sleepy
     Sneezy

function                                             old     new   delta
patch_main                                          1903    1957     +54

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-11 18:01:34 +01:00
Isaac Dunham 7b434a67dc mount: -T OTHERTAB support
function                                             old     new   delta
mount_main                                          1221    1241     +20
packed_usage                                       30616   30610      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Isaac Dunham <ibid.ag@gmail.com>
2015-03-11 16:07:24 +01:00
Denys Vlasenko 3c31b092ac ntpd: tweak help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-05 14:04:44 +01:00
Denys Vlasenko 2ec4f44225 inetd: fix order of array index check and array access
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-03 13:10:30 +01:00
Denys Vlasenko 3aef814c0b ntpd: chnage help text about -l to say that it doesn't disable client code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 20:59:13 +01:00
Denys Vlasenko 7db2a7c20e runsvdir: if pid==1, also intercept SIGINT for -s SCRIPT
function                                             old     new   delta
runsvdir_main                                       1057    1064      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 17:39:13 +01:00
Denys Vlasenko dac8d80f77 runsvdir: do not block SIGCHLD around poll/sleep
There is no reason to do so. We do not even have SIGCHLD handler.

function                                             old     new   delta
runsvdir_main                                       1077    1057     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 17:38:55 +01:00
Denys Vlasenko fa535f3e48 runsvdir: (almost) close a signal race
We could lose a signal while processing previous one

function                                             old     new   delta
runsvdir_main                                       1088    1077     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 17:37:31 +01:00
Serj Kalichev 1eafd44947 acpid: fix logging
Without this patch acpid can't log the events at all. Moreover it tries
to truncate log file every time.

Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-23 15:26:47 +01:00
Denys Vlasenko c5beaa08eb ls: heed compiler warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-23 15:25:58 +01:00
Denys Vlasenko a88db5c1a9 modinfo: fix fallout from basename removal
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-21 17:08:35 +01:00
Tito Ragusa cb6a112f09 libpwdgrp: fix thinko in getpwnam
function                                             old     new   delta
parse_file                                             -      64     +64
getXXnam_r                                           162     138     -24
getXXnam                                              90      50     -40
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 64/-64)              Total: 0 bytes

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-19 22:03:56 +01:00
Bernhard Reutner-Fischer d7bfee1edb wget: fix --header to not append duplicate headers
function                                             old     new   delta
wget_main                                           2551    2715    +164
wget_user_headers                                      -      62     +62
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 226/0)             Total: 226 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-18 20:41:02 +01:00
Denys Vlasenko 54e9585e10 trivial code shrink
function                                             old     new   delta
rdate_main                                           246     251      +5
show_entry                                           291     287      -4
daytime_stream                                        44      39      -5
packed_usage                                       30176   30168      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-17)             Total: -12 bytes
   text	   data	    bss	    dec	    hex	filename
 929453	    932	  17684	 948069	  e7765	busybox_old
 929411	    932	  17684	 948027	  e773b	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-18 13:47:46 +01:00
Denys Vlasenko 0cb981c5e2 ls: trivial code shrink
function                                             old     new   delta
display_single                                       914     893     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-18 11:29:07 +01:00
Bernhard Reutner-Fischer 70e30e8eec dc: tweak parsing
https://bugs.debian.org/538685
dc requires whitespace between language elements.

We were requiring
1 2 + p
instead of the abbreviated
1 2+p
(for example).

function                                             old     new   delta
stack_machine                                         97     126     +29
dc_main                                              117      79     -38
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 29/-38)             Total: -9 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-16 17:12:04 +01:00
Denys Vlasenko 8e92df15b5 ls: fix year 9999 bug :)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-16 15:36:25 +01:00
Denys Vlasenko 402afe1cc6 modprobe-small: fix thinko in previous commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-13 11:53:33 +01:00
Denys Vlasenko 1fd844267c modprobe-small: if concurrent module load did not succeed, wait
usecase:
two sd cards are being mounted in parallel at same time on dual core. example
modules which are getting loaded is  nls_cp437. While one module is being
loaded , it makes state in /proc/modules as 'coming' and then starts doing its
module init function (in our case - registering nls). meanwhile on other core,
if modprobe returns that is has already been loaded, then it will continue
and search for the nls list which is not yet finished from first module init.
This fails resulting in not mounting sd card.

function                                             old     new   delta
process_module                                       667     746     +79

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-12 17:05:14 +01:00
Bartosz Golaszewski 622a7aab2c i2cget, i2cset, i2cdetect, i2cdump: new applets
Add a minimal implementation of i2cget, i2cset, i2cdump and i2cdetect
tools. Supports most features of upstream i2c-tools.

function                                             old     new   delta
i2cdump_main                                           -    1444   +1444
i2cset_main                                            -    1239   +1239
i2cdetect_main                                         -     611    +611
list_i2c_busses_and_exit                               -     532    +532
packed_usage                                       29975   30438    +463
i2cget_main                                            -     380    +380
check_read_funcs                                       -     140    +140
i2c_funcs_tab                                          -     128    +128
confirm_action                                         -     100    +100
i2c_dev_open                                           -      57     +57
i2c_smbus_access                                       -      44     +44
confirm_or_abort                                       -      43     +43
check_funcs_test_end                                   -      39     +39
i2c_smbus_read_word_data                               -      38     +38
i2c_smbus_read_byte_data                               -      38     +38
i2c_smbus_read_byte                                    -      37     +37
i2c_set_slave_addr                                     -      32     +32
applet_names                                        2480    2512     +32
adap_descs                                             -      32     +32
i2c_set_pec                                            -      29     +29
get_funcs_matrix                                       -      21     +21
i2c_parse_data_addr                                    -      18     +18
i2c_parse_bus_addr                                     -      18     +18
i2c_bus_lookup                                         -      18     +18
i2c_smbus_write_byte                                   -      17     +17
applet_main                                         1440    1456     +16
will_skip                                              -      14     +14
no_support                                             -      11     +11
applet_nameofs                                       720     728      +8
applet_install_loc                                   180     182      +2
------------------------------------------------------------------------------
(add/remove: 26/0 grow/shrink: 5/0 up/down: 5601/0)          Total: 5601 bytes

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-10 03:16:25 +01:00
Denys Vlasenko 8c06bc6ba1 unzip: prevent attacks via malicious filenames
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-10 01:30:43 +01:00
Denys Vlasenko 23cfaab47d libpwdgrp: use getpwent() instead of getpwent_r()
function                                             old     new   delta
massage_data_for_non_r_func                            -      90     +90
bb_internal_getpwent                                   -      69     +69
getXXnam_r                                            94     162     +68
fill_bounds                                          131     128      -3
deluser_main                                         355     310     -45
complete_username                                    123      78     -45
getXXnam                                             163      90     -73
massage_data_for_r_func                              103       -    -103
bb_internal_getpwent_r                               121       -    -121
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/5 up/down: 227/-407)         Total: -163 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 21:21:02 +01:00
Denys Vlasenko 68c048fb23 modprobe-small: fix and simplify rmmod
"rmmod OUT_OF_TREE_MODULE" was not working, because module is not in depmod file.

In general, rmmod doesn't need scanning, it simply unloads every argv[i].

function                                             old     new   delta
rmmod                                                  -      63     +63
modprobe_main                                        449     465     +16
process_module                                       705     667     -38
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 79/-38)             Total: 41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 20:44:46 +01:00
Kevin Wallace 782ee2aa0e libbb/loop: don't try to re-use existing loop device
loopinfo.lo_file_name is not enough to uniquely identify a file on a system with
multiple mount namespaces.  We could conceivably change this to dedup on
(lo_rdevice, lo_inode), but, as the comment above the deleted code notes, this
whole approach of reusing devices is racy anyway, so it seems better to stop
doing it entirely.

Signed-off-by: Kevin Wallace <k@igneous.io>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 19:13:57 +01:00
Denys Vlasenko a03195941b examples/mdev_fat.conf: document that newer mdev exposes path
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 18:14:39 +01:00
Ari Sundholm f22a838aed dd: add optional support for status=noxfer/none
While at it, added 'B' number suffixes, upstream compat

function                                             old     new   delta
dd_main                                             1469    1543     +74
dd_suffixes                                           88     112     +24
packed_usage                                       30156   30176     +20
dd_output_status                                     372     388     +16
static.status_words                                    -      13     +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/0 up/down: 147/0)             Total: 147 bytes

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 01:41:22 +01:00
Denys Vlasenko 7e66102f76 ash: fix a SEGV case in an invalid heredoc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-05 21:00:17 +01:00
Denys Vlasenko a14fa79592 deluser: implement --remove-home
function                                             old     new   delta
deluser_main                                         308     355     +47
packed_usage                                       30149   30156      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 54/0)               Total: 54 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-05 18:35:52 +01:00
Denys Vlasenko 3c5d133c7d fstrim: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-04 15:19:38 +01:00
Denys Vlasenko a75dcd4353 route: fix bogus read error when route table is empty
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-04 10:40:10 +01:00
Denys Vlasenko 09020b1aa8 route: improve -A inet6
Upstream route command shows non-up routes, it shows reject and nonexthop flags.
And we had "ref" and "use" values mixed up...

function                                             old     new   delta
flagvals                                              32      44     +12
flagchars                                              9      12      +3
INET_setroute                                        767     768      +1
INET6_setroute                                       495     496      +1
set_flags                                             43      39      -4
flags_ipvx                                            16       8      -8
route_main                                           632     623      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/3 up/down: 17/-21)             Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 19:32:44 +01:00
Denys Vlasenko b62d4d9d57 gzip: trivial code shrink -5 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 15:25:17 +01:00
Denys Vlasenko a977778893 ifconfig: fix double free fatal error in INET_sprint
Based on the patch by Zheng Junling <zhengjunling@huawei.com>
and Chen Gang <cg.chen@huawei.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 12:11:30 +01:00
Denys Vlasenko 8e74adab01 libbb: make INET[6]_rresolve use sockaddr2{host,dotted}_noport
function                                             old     new   delta
INET_rresolve                                        274     214     -60
INET6_rresolve                                       168      85     -83

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 12:07:40 +01:00
Denys Vlasenko f7f70bf1b3 gzip: speed up and shrink put_16bit()
function                                             old     new   delta
put_16bit                                            104      98      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-02 16:07:07 +01:00
Rich Felker 7f7ade1964 gzip: do not store timestamp in gzip header
Storing the original file's modification time in the output file is
harmful (precludes deterministic results) and unlike official gzip,
the busybox version provides no way to suppress this behavior; the -n
option is silently ignored. Rather than trying to make -n work, this
patch just removes the timestamp-storing functionality. It should be
considered deprecated anyway; it's not Y2038-safe and gunzip ignores
it by default.

Per RFC 1952, 0 is the correct value to store to indicate that there
is no timestamp.

Signed-off-by: Rich Felker <dalias@libc.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-02 16:01:16 +01:00
Denys Vlasenko 5104645cf8 platform.h: enable mempcpy for FreeBSD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-02 03:51:47 +01:00
Micke Prag 07fa09a952 ubiattach: add option -O
Some images do not have the default VID offset. The option -O must
be used to attach such images.

Signed-off-by: Micke Prag <micke.prag@telldus.se>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-30 18:33:24 +01:00
Martin Kaiser 1cbe93cf4e telnetd: we only need CONFIG_UNIX98_PTYS from the Linux kernel
(re-sending this as it got ignored completey and the format of the
previous mail was probably not correct - please let me know if there's
anything else I can do to get this trivial fix applied)

for telnetd to work, we only need CONFIG_UNIX98_PTYS to be enabled
in the Linux kernel - DEVPTS_FS has been obsolete for some time

Signed-off-by: Martin Kaiser <lists@kaiser.cx>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-30 17:12:38 +01:00
Denys Vlasenko 08f9ffc3f7 dpkg: update supported compression methods
Based on a patch by Ron Yorston <rmy@tigress.co.uk>

function                                             old     new   delta
get_header_tar_xz                                      -      60     +60
filter_accept_list_reassign                          128     188     +60
unpack_package                                       585     621     +36
init_archive_deb_control                              52      76     +24
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 180/0)             Total: 180 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-30 15:15:38 +01:00
Denys Vlasenko 8c05a74f7e platform.h: mempcpy needs <string.h>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-29 16:41:48 +01:00
Denys Vlasenko ff3f3accc6 ntpd: get rid of G.initial_poll_complete
This speeds up syncing - now happens only just
two replies from a peer. Especially useful for "ntpd -q".
Shouldn't have ill effects: if we chose a bad peer,
we will discover it later and switch to another one.

The code is even smaller this way.

Suggested by Miroslav Lichvar <mlichvar@redhat.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-29 16:31:36 +01:00
Denys Vlasenko 936c401077 dhcpd: fix an improper widening conversion
We wanted to detect when tv_sec = unsigned1 - unsigned2
underflows by looking at tv_sec's sign. But if tv_sec
is long and it is wider than unsigned, we get unsigned -> long
conversion which is in this case never negative.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-27 21:59:40 +01:00
Denys Vlasenko 64b744997e ftpd: prevent zombies. closes 7832
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-26 15:45:48 +01:00
Denys Vlasenko 50a6d86520 platform.h: add compat mempcpy
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-25 22:08:46 +01:00
Denys Vlasenko cc70b6f8b6 depmod: simple memory optimization
function                                             old     new   delta
filename2modname                                      67      86     +19
parse_module                                         374     351     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-24 22:30:30 +01:00
Denys Vlasenko 86031a5ffd trim extra newlines in help texts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-24 19:46:45 +01:00
Natanael Copa 9de69c024c modprobe: fix modprobe -r and parsing of /etc/modprobe.d
This fixes a regression introduced with commit 78854520 (modprobe:
revert checking for /, stop doing basename() on modprobe args,
2015-01-01) that broke modprobe options stored in /etc/modprobe.conf and
/etc/modprobe.d/*.conf.

This also fixes modprobe -r

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-19 19:15:24 +01:00
Denys Vlasenko 76b2262b9b modprobe: fix "modprobe devname:snd/timer" case (alias with a slash)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-15 03:04:23 +01:00
Denys Vlasenko e998b08f11 modprobe: fix recent breakage: modules.dep reading code needs to strip dirname
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-15 02:49:59 +01:00
Denys Vlasenko 1b6715345f modprobe-small: code shrink
function                                             old     new   delta
pathname_matches_modname                              80      42     -38

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-11 17:46:56 +01:00
Denys Vlasenko 3c75b1c34e modprobe-small: fix recent breakage: modprobe -r was using full path
"modprobe -r MODNAME", after it found the full module pathname,
should strip dirpath before trying to remove the module.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-11 17:40:30 +01:00
Denys Vlasenko 39f017293a diff: fix a bug in diffing against stdin. Closes 7784
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-11 16:41:54 +01:00
Ron Yorston 70f4320b40 vi: fix reading of file after last line
If the :r command is used to read a file after the last line of the
buffer the last line of the buffer and the first line of the file
are joined.  An extra blank line appears at the end of the buffer.

   file 1
   file 1
   file 1file 2
   file 2
   file 2

	~
	~

The insertion point is normally at the start of the line following the
specified line.  When the specified line is the last one the next_line
function baulks at moving to the non-existent following line.

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 18:23:29 +01:00
Ron Yorston e5213cee38 vi: failure to open file is not an error when initialising buffer
Commit 32afd3a introduced these regressions on the master branch:

Starting vi with no filename on the command line gives the status message
"'(null)' Bad address" instead of "- No file 1/1 100%".

Starting vi with a non-existent file on the command line gives the status
message "'new.txt' No such file or directory" instead of "- new.txt 1/1 100%"

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 17:00:48 +01:00
Denys Vlasenko 08364dab75 depmod: fix recent breakage in modules.dep generation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 14:39:01 +01:00
Tito Ragusa e5cae08f12 libpwdgrp: line counting in error meesages is broken, remove it
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-06 01:22:36 +01:00
René Rhéaume e76957708b swaponoff: add support for -e
Signed-off-by: René Rhéaume <rene.rheaume@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 20:35:00 +01:00
Denys Vlasenko 1ec49732e2 mpstat: code shrink
function                                             old     new   delta
get_uptime                                           134     129      -5
get_irqs_from_stat                                   110     103      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 18:39:23 +01:00
Guillermo Rodriguez 75a1403f26 free: handle "cached" value too
function                                             old     new   delta
free_main                                            356     481    +125

Signed-off-by: Guillermo Rodriguez <guille.rodriguez@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 18:34:53 +01:00
Denys Vlasenko da9212667c libbb: code shrink by factoring out common update_utmp_DEAD_PROCESS
function                                             old     new   delta
update_utmp_DEAD_PROCESS                               -      17     +17
telnetd_main                                        1685    1674     -11
mark_terminated                                       56      45     -11
handle_sigchld                                        74      63     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 15:37:58 +01:00
Denys Vlasenko 08b90a9d10 deleting unused ntpd_simple.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 15:12:37 +01:00
Denys Vlasenko c5d4a04e45 libpwdgrp: fixes suggested by Tito, comment tweaks
function                                             old     new   delta
bb_internal_getpwent_r                               100     121     +21
parse_common                                         202     203      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 15:09:04 +01:00
Adam Tkac 4bf88d9094 ntpd: relicense ntpd applet to ISC-style license
OpenNTPd is licensed under ISC-style license so it's good idea to keep
ntpd applet under same license to avoid mess, instead of having
our changes to be under GPL.

Names of original code's authors are added.

Signed-off-by: Adam Tkac <vonsch@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-04 17:46:08 +01:00
Denys Vlasenko db4d1051ca libpwdgrp: another code shrink
function                                             old     new   delta
massage_data_for_r_func                                -     110    +110
bb_internal_getpwent_r                               173     100     -73
getXXnam_r                                           176      95     -81
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 110/-154)          Total: -44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-04 02:34:52 +01:00
Denys Vlasenko 5acf1346b4 libpwdgrp: code shrink
function                                             old     new   delta
parse_common                                         206     205      -1
getgrouplist_internal                                229     225      -4
bb_internal_getpwent_r                               182     173      -9
getXXnam                                             232     222     -10
getXXnam_r                                           216     176     -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-64)             Total: -64 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-04 02:02:39 +01:00
Denys Vlasenko 12fc869560 libpwdgrp: getgrXXX: empty string is not a member name, do not store it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 21:16:18 +01:00
Denys Vlasenko 402451aa19 fix a SEGV in previous commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 21:11:27 +01:00
Denys Vlasenko f9936676bb libpwdgrp: fix counting of commas in group list
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 21:03:39 +01:00
Denys Vlasenko 134c53098b libpwdgrp: store getXXnam result in a single malloc block
This saves a bit of memory but more importantly, allows to create
xmalloc_getpwnam() API where result can be deleted simply using free().

function                                             old     new   delta
getXXnam                                             134     173     +39
parse_common                                         188     212     +24
convert_to_struct                                    277     290     +13
get_S                                                 90      88      -2
tokenize                                             129     126      -3
bb_internal_getpwent_r                               175     172      -3
getXXnam_r                                           208     198     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/4 up/down: 76/-18)             Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 20:47:47 +01:00
Denys Vlasenko 20c0a16334 libpwdgrp: make db->def[] one byte shorter
In the future I will need another uint8_t, want to fit it
w/o using another word on 32 bits.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 19:12:49 +01:00
Denys Vlasenko 5e62a3d016 libpwdgrp: use a better estimate of max struct size
Previous code's trick with bitwise OR was giving this on 32-bit x86:

sizeof(struct passwd):28
sizeof(struct group):16
sizeof(struct spwd):36
sizeof(struct_result):60

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 17:53:49 +01:00
Denys Vlasenko 9dca6acaac libpwdgrp: reinstate Tito's optional atexit freeing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 16:09:05 +01:00
Denys Vlasenko 8d547aca75 libpwdgrp: fix a memory leak in getXXnam (we did not save address of string buf)
function                                             old     new   delta
convert_to_struct                                    261     269      +8
const_sp_db                                           20      24      +4
const_pw_db                                           20      24      +4
const_gr_db                                           20      24      +4
tokenize                                             144     147      +3
parse_common                                         185     188      +3
get_S                                                 82      85      +3
bb_internal_getpwent_r                               188     185      -3
gr_off                                                 4       -      -4
getXXnam                                             171     165      -6
pw_off                                                 7       -      -7
getgrouplist_internal                                237     229      -8
getXXnam_r                                           215     207      -8
sp_off                                                 9       -      -9
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 7/4 up/down: 29/-45)            Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 15:54:04 +01:00
Denys Vlasenko 31d6734457 libpwdgrp: tweak comments, replace one xmalloc with xzalloc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 15:15:47 +01:00
Denys Vlasenko 908b6e5dfd libpwdgrp: use FAST_FUNC to make "matching ABI" optimization more likely to succeed
See bb_internal_get*nam_r size reduction:

function                                             old     new   delta
bb_internal_getpwent_r                               167     176      +9
getXXnam_r                                           204     206      +2
sulogin_main                                         326     325      -1
su_main                                              471     470      -1
read_line_input                                     3832    3831      -1
print_stat                                           865     864      -1
prepare_socket_fd                                    283     282      -1
load_crontab                                         777     776      -1
fork_job                                             456     455      -1
do_shm                                               884     883      -1
do_sem                                               637     636      -1
do_msg                                               783     782      -1
complete_username                                    124     123      -1
bb_internal_getgrouplist                              71      70      -1
xgetpwuid                                             27      25      -2
xgetpwnam                                             27      25      -2
xgetgrnam                                             27      25      -2
xgetgrgid                                             27      25      -2
uid2uname                                             18      16      -2
login_main                                           980     978      -2
gid2group                                             18      16      -2
get_shell_name                                        54      52      -2
change_identity                                       50      48      -2
bb_internal_initgroups                                50      48      -2
argstr                                              1261    1259      -2
print_perms                                          177     174      -3
inetd_main                                          2077    2074      -3
run_applet_no_and_exit                               446     442      -4
fileaction_setowngrp                                  89      85      -4
deluser_main                                         312     308      -4
bb_internal_getpwuid                                  19      15      -4
bb_internal_getpwnam                                  11       7      -4
bb_internal_getgrnam                                  14      10      -4
bb_internal_getgrgid                                  19      15      -4
adduser_main                                         865     861      -4
passwd_main                                          989     984      -5
get_passwd                                            97      92      -5
data_extract_all                                     887     882      -5
check_user_passwd                                    490     485      -5
get_groups                                            81      75      -6
ftpd_main                                           2178    2171      -7
bb_internal_getspnam_r                                42      18     -24
bb_internal_getpwnam_r                                39      15     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/41 up/down: 11/-153)         Total: -142 bytes
   text	   data	    bss	    dec	    hex	filename
 923167	    928	  17676	 941771	  e5ecb	busybox_old
 923023	    928	  17676	 941627	  e5e3b	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-02 22:31:07 +01:00
Tito Ragusa 1da09cfacf libpwdgrp: rewritten to use malloced implementation
This removed buffer size limitations.

function                                             old     new   delta
convert_to_struct                                      -     269    +269
getXXnam_r                                             -     204    +204
parse_common                                           -     185    +185
getXXnam                                               -     164    +164
tokenize                                               -     126    +126
bb_internal_getpwent_r                               102     167     +65
get_S                                                 30      88     +58
getgrouplist_internal                                195     240     +45
const_sp_db                                            -      20     +20
const_pw_db                                            -      20     +20
const_gr_db                                            -      20     +20
bb_internal_endpwent                                  27      36      +9
bb_internal_endgrent                                  27      36      +9
decode_one_format                                    726     734      +8
bb_internal_setpwent                                  17      24      +7
volume_id_probe_iso9660                              319     322      +3
scriptreplay_main                                    204     207      +3
mkfs_minix_main                                     2684    2687      +3
id_main                                              478     480      +2
hash_find                                            233     235      +2
pstree_main                                          321     322      +1
gr_off                                                 3       4      +1
expand_one_var                                      1579    1578      -1
pwf                                                    4       -      -4
grf                                                    4       -      -4
pack_gzip                                           1787    1780      -7
addattr32                                             67      56     -11
buffer_fill_and_print                                191     178     -13
dpkg_main                                           2944    2927     -17
bb_internal_setgrent                                  17       -     -17
bb_internal_getpwuid                                  38      19     -19
bb_internal_getgrgid                                  44      19     -25
bb_internal_getpwnam                                  38      11     -27
bb_internal_getgrnam                                  44      14     -30
bb_internal_fgetpwent_r                               51       -     -51
bb_internal_fgetgrent_r                               51       -     -51
bb_internal_getspnam_r                               121      42     -79
bb_internal_getpwnam_r                               121      39     -82
bb_internal_getgrent_r                               102       -    -102
bb__parsepwent                                       110       -    -110
bb_internal_getpwuid_r                               113       -    -113
bb_internal_getgrgid_r                               113       -    -113
bb__parsespent                                       120       -    -120
bb_internal_getgrnam_r                               121       -    -121
bb__pgsreader                                        213       -    -213
bb__parsegrent                                       226       -    -226
------------------------------------------------------------------------------
(add/remove: 8/13 grow/shrink: 14/11 up/down: 1224/-1556)    Total: -332 bytes
   text	   data	    bss	    dec	    hex	filename
 923471	    928	  17684	 942083	  e6003	busybox_old
 923167	    928	  17676	 941771	  e5ecb	busybox_unstripped

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-02 21:37:59 +01:00
Denys Vlasenko 78854520eb modprobe: revert checking for /, stop doing basename() on modprobe args
function                                             old     new   delta
process_module                                       726     719      -7
filename2modname                                      81      67     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-21)             Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-01 19:02:40 +01:00
Bartosz Golaszewski 6c19d35f68 Makefile: fix cscope target
This target doesn't work with current directory layout. Just make cscope
index all .c and .h files.

While we're at it: add cscope output files to .gitignore.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-31 21:29:05 +01:00
Denys Vlasenko c76236fd7d ash: fix a SEGV in ${#1}
function                                             old     new   delta
varvalue                                             760     805     +45
evalvar                                              648     603     -45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-29 00:04:18 +01:00
John Schroeder 8074a6ca4d udhcpd: account for script delay in lease
Prevent nasty surprises if script runs longer than lease time / 2.

Signed-off-by: John Schroeder <jschroed@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-25 21:12:51 +01:00
Denys Vlasenko b9965077e5 Start 1.24.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-24 02:06:02 +01:00
51 changed files with 419 additions and 170 deletions

8
.gitignore vendored
View File

@ -40,3 +40,11 @@ core
/busybox.links
/runtest-tempdir-links
/testsuite/echo-ne
#
# cscope output
#
cscope.files
cscope.in.out
cscope.out
cscope.po.out

View File

@ -48,7 +48,7 @@ SRCS = \
libbb/messages.c \
libbb/appletlib.c \
libbb/bb.basename.c \
libbb/mempcpy.c \
libbb/auto.string.c \
libbb/vfork.and.run.c \
libbb/poll.c \
libbb/get.exec.path.c \

View File

@ -35,7 +35,6 @@ LIBBB_B_SRC = \
libbb/escape.seq.c \
libbb/messages.c \
libbb/bb.basename.c \
libbb/mempcpy.c \
libbb/get.exec.path.c \
libbb/exec.gno.c
@ -54,7 +53,8 @@ LIBBB_C_SRC = \
libbb/parse.mode.c \
libbb/poll.c \
libbb/pgrp.c \
libbb/qsort.c
libbb/qsort.c \
libbb/auto.string.c
LIBBB_D_SRC = \
libbb/xfuncs.printf.c \

View File

@ -39,14 +39,9 @@
//config: help
//config: Enable 64-bit support in test.
/* "test --help" does not print help (POSIX compat), only "[ --help" does.
* We display "<applet> EXPRESSION ]" here (not "<applet> EXPRESSION")
* Unfortunately, it screws up generated BusyBox.html. TODO. */
//usage:#define test_trivial_usage
//usage: "EXPRESSION ]"
//usage:#define test_full_usage "\n\n"
//usage: "Check file types, compare values etc. Return a 0/1 exit code\n"
//usage: "depending on logical value of EXPRESSION"
/* "test --help" is special-cased to ignore --help */
//usage:#define test_trivial_usage NOUSAGE_STR
//usage:#define test_full_usage ""
//usage:
//usage:#define test_example_usage
//usage: "$ test 1 -eq 2\n"

View File

@ -164,21 +164,13 @@
#define ENABLE_FEATURE_CLEAN_UP 0
#define IF_FEATURE_CLEAN_UP(x)
#define IF_NOT_FEATURE_CLEAN_UP(x) x
#define CONFIG_FEATURE_UTMP 1
#define ENABLE_FEATURE_UTMP 1
#ifdef MAKE_SUID
# define IF_FEATURE_UTMP(x) x "CONFIG_FEATURE_UTMP"
#else
# define IF_FEATURE_UTMP(x) x
#endif
#undef CONFIG_FEATURE_UTMP
#define ENABLE_FEATURE_UTMP 0
#define IF_FEATURE_UTMP(x)
#define IF_NOT_FEATURE_UTMP(x)
#define CONFIG_FEATURE_WTMP 1
#define ENABLE_FEATURE_WTMP 1
#ifdef MAKE_SUID
# define IF_FEATURE_WTMP(x) x "CONFIG_FEATURE_WTMP"
#else
# define IF_FEATURE_WTMP(x) x
#endif
#undef CONFIG_FEATURE_WTMP
#define ENABLE_FEATURE_WTMP 0
#define IF_FEATURE_WTMP(x)
#define IF_NOT_FEATURE_WTMP(x)
#define CONFIG_FEATURE_PIDFILE 1
#define ENABLE_FEATURE_PIDFILE 1

View File

@ -5,7 +5,7 @@
#ifndef BUSYBOX_H
#define BUSYBOX_H 1
#define BB_VER "1.23.1 (GNO hush 1.1)"
#define BB_VER "1.24.0 (GNO hush 1.2-dev)"
#include "libbb.h"
/* BB_DIR_foo and BB_SUID_bar constants: */

View File

@ -104,7 +104,30 @@
# include <selinux/av_permissions.h>
#endif
#if ENABLE_FEATURE_UTMP
# include <utmp.h>
# if defined __UCLIBC__ && ( \
(UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 32) \
&& UCLIBC_VERSION < KERNEL_VERSION(0, 9, 34) \
&& defined __UCLIBC_HAS_UTMPX__ \
) || ( \
UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 34) \
) \
)
# include <utmpx.h>
# elif defined __UCLIBC__
# include <utmp.h>
# define utmpx utmp
# define setutxent setutent
# define endutxent endutent
# define getutxent getutent
# define getutxid getutid
# define getutxline getutline
# define pututxline pututline
# define utmpxname utmpname
# define updwtmpx updwtmp
# define _PATH_UTMPX _PATH_UTMP
# else
# include <utmpx.h>
# endif
#endif
#if ENABLE_LOCALE_SUPPORT
# include <locale.h>
@ -396,6 +419,8 @@ const char *bb_basename(const char *name) FAST_FUNC;
/* NB: can violate const-ness (similarly to strchr) */
char *last_char_is(const char *s, int c) FAST_FUNC;
const char* endofname(const char *name) FAST_FUNC;
char *is_prefixed_with(const char *string, const char *key) FAST_FUNC;
char *is_suffixed_with(const char *string, const char *key) FAST_FUNC;
int ndelay_on(int fd) FAST_FUNC;
int ndelay_off(int fd) FAST_FUNC;
@ -433,8 +458,6 @@ char *xrealloc_getcwd_or_warn(char *cwd) FAST_FUNC;
char *xmalloc_follow_symlinks(const char *path) FAST_FUNC RETURNS_MALLOC;
void *mempcpy(void *dst, const void *src, size_t len);
void bb_signals(long int sigs, sig_t f) FAST_FUNC;
/* syscalls like read() will be interrupted with EINTR: */
@ -512,6 +535,11 @@ void xlisten(int s, int backlog) FAST_FUNC;
void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC;
ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
socklen_t tolen) FAST_FUNC;
int setsockopt_int(int fd, int level, int optname, int optval) FAST_FUNC;
int setsockopt_1(int fd, int level, int optname) FAST_FUNC;
int setsockopt_SOL_SOCKET_int(int fd, int optname, int optval) FAST_FUNC;
int setsockopt_SOL_SOCKET_1(int fd, int optname) FAST_FUNC;
/* SO_REUSEADDR allows a server to rebind to an address that is already
* "in use" by old connections to e.g. previous server instance which is
* killed or crashed. Without it bind will fail until all such connections
@ -519,6 +547,7 @@ ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
* regardless of SO_REUSEADDR (unlike some other flavors of Unix).
* Turn it on before you call bind(). */
void setsockopt_reuseaddr(int fd) FAST_FUNC; /* On Linux this never fails. */
int setsockopt_keepalive(int fd) FAST_FUNC;
int setsockopt_broadcast(int fd) FAST_FUNC;
int setsockopt_bindtodevice(int fd, const char *iface) FAST_FUNC;
/* NB: returns port in host byte order */
@ -527,7 +556,6 @@ typedef struct len_and_sockaddr {
socklen_t len;
union {
struct sockaddr sa;
struct sockaddr_in sin;
#if ENABLE_FEATURE_IPV6
struct sockaddr_in6 sin6;
#endif
@ -613,6 +641,7 @@ uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
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 overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
@ -625,6 +654,7 @@ void bb_putchar_binary(int ch) FAST_FUNC;
/* Note: does not use stdio, writes to fd 2 directly */
int bb_putchar_stderr(char ch) FAST_FUNC;
char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC;
char *auto_string(char *str) FAST_FUNC;
// gcc-4.1.1 still isn't good enough at optimizing it
// (+200 bytes compared to macro)
//static ALWAYS_INLINE
@ -677,7 +707,7 @@ void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) F
extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count, int loop_on_EINTR) FAST_FUNC;
extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
// NB: will return short read on error, not -1,
// if some data was read before error occurred
extern ssize_t full_read(int fd, void *buf, size_t count) FAST_FUNC;
@ -808,6 +838,8 @@ struct suffix_mult {
};
extern const struct suffix_mult bkm_suffixes[];
#define km_suffixes (bkm_suffixes + 1)
extern const struct suffix_mult cwbkMG_suffixes[];
#define kMG_suffixes (cwbkMG_suffixes + 3)
#include "xatonum.h"
/* Specialized: */
@ -870,9 +902,11 @@ int ingroup(uid_t u, gid_t g);
#if ENABLE_FEATURE_UTMP
void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid);
#else
# define write_new_utmp(pid, new_type, tty_name, username, hostname) ((void)0)
# define update_utmp(pid, new_type, tty_name, username, hostname) ((void)0)
# define update_utmp_DEAD_PROCESS(pid) ((void)0)
#endif
@ -1007,9 +1041,8 @@ enum {
};
extern const char *msg_eol;
extern smallint logmode;
extern int die_sleep;
extern uint8_t xfunc_error_retval;
extern jmp_buf die_jmp;
extern void (*die_func)(void);
extern void xfunc_die(void) NORETURN FAST_FUNC;
extern void bb_show_usage(void) NORETURN FAST_FUNC;
extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
@ -1123,7 +1156,8 @@ char *bb_ask_stdin(const char * prompt) FAST_FUNC;
char *bb_ask(const int fd, int timeout, const char * prompt) FAST_FUNC;
int bb_ask_confirmation(void) FAST_FUNC;
int bb_parse_mode(const char* s, mode_t* theMode) FAST_FUNC;
/* Returns -1 if input is invalid. current_mode is a base for e.g. "u+rw" */
int bb_parse_mode(const char* s, unsigned cur_mode) FAST_FUNC;
/*
* Config file parser
@ -1543,7 +1577,7 @@ extern const char bb_path_wtmp_file[] ALIGN1;
#endif
extern const int const_int_0;
extern const int const_int_1;
//extern const int const_int_1;
/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
@ -1675,7 +1709,6 @@ void _exit_wrapper(int status) NORETURN;
typedef void (*bbunit_testfunc)(void);
struct bbunit_listelem {
struct bbunit_listelem* next;
const char* name;
bbunit_testfunc testfunc;
};

View File

@ -161,6 +161,43 @@ typedef unsigned long uintptr_t;
#endif
/* ---- Unaligned access ------------------------------------ */
typedef int bb__aliased_int FIX_ALIASING;
typedef long bb__aliased_long FIX_ALIASING;
typedef uint16_t bb__aliased_uint16_t FIX_ALIASING;
typedef uint32_t bb__aliased_uint32_t FIX_ALIASING;
/* NB: unaligned parameter should be a pointer, aligned one -
* a lvalue. This makes it more likely to not swap them by mistake
*/
#if defined(i386) || defined(__x86_64__) || defined(__powerpc__)
# define BB_UNALIGNED_MEMACCESS_OK 1
# define move_from_unaligned_int(v, intp) ((v) = *(bb__aliased_int*)(intp))
# define move_from_unaligned_long(v, longp) ((v) = *(bb__aliased_long*)(longp))
# define move_from_unaligned16(v, u16p) ((v) = *(bb__aliased_uint16_t*)(u16p))
# define move_from_unaligned32(v, u32p) ((v) = *(bb__aliased_uint32_t*)(u32p))
# define move_to_unaligned16(u16p, v) (*(bb__aliased_uint16_t*)(u16p) = (v))
# define move_to_unaligned32(u32p, v) (*(bb__aliased_uint32_t*)(u32p) = (v))
/* #elif ... - add your favorite arch today! */
#else
# define BB_UNALIGNED_MEMACCESS_OK 0
/* performs reasonably well (gcc usually inlines memcpy here) */
# define move_from_unaligned_int(v, intp) (memcpy(&(v), (intp), sizeof(int)))
# define move_from_unaligned_long(v, longp) (memcpy(&(v), (longp), sizeof(long)))
# define move_from_unaligned16(v, u16p) (memcpy(&(v), (u16p), 2))
# define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4))
# define move_to_unaligned16(u16p, v) do { \
uint16_t __t = (v); \
memcpy((u16p), &__t, 2); \
} while (0)
# define move_to_unaligned32(u32p, v) do { \
uint32_t __t = (v); \
memcpy((u32p), &__t, 4); \
} while (0)
#endif
/* ---- Size-saving "small" ints (arch-dependent) ----------- */
#if defined(i386) || defined(__x86_64__) || defined(__mips__) || defined(__cris__)
@ -290,10 +327,12 @@ typedef unsigned smalluint;
#define HAVE_DPRINTF 1
#define HAVE_MEMRCHR 1
#define HAVE_MKDTEMP 1
#define HAVE_TTYNAME_R 1
#define HAVE_PTSNAME_R 1
#define HAVE_SETBIT 1
#define HAVE_SIGHANDLER_T 1
#define HAVE_STPCPY 1
#define HAVE_MEMPCPY 1
#define HAVE_STRCASESTR 1
#define HAVE_STRCHRNUL 1
#define HAVE_STRSEP 1
@ -371,9 +410,12 @@ typedef unsigned smalluint;
#if defined(__APPLE__)
# undef HAVE_STRCHRNUL
# undef HAVE_MEMPCPY
#endif
#if defined(__FreeBSD__)
/* users say mempcpy is not present in FreeBSD 9.x */
# undef HAVE_MEMPCPY
# undef HAVE_CLEARENV
# undef HAVE_FDATASYNC
# undef HAVE_MNTENT_H
@ -398,9 +440,17 @@ typedef unsigned smalluint;
#endif
#if defined(ANDROID) || defined(__ANDROID__)
# undef HAVE_DPRINTF
# undef HAVE_GETLINE
# undef HAVE_STPCPY
# if __ANDROID_API__ < 8
# undef HAVE_DPRINTF
# else
# define dprintf fdprintf
# endif
# if __ANDROID_API__ < 21
# undef HAVE_TTYNAME_R
# undef HAVE_GETLINE
# undef HAVE_STPCPY
# endif
# undef HAVE_MEMPCPY
# undef HAVE_STRCHRNUL
# undef HAVE_STRVERSCMP
# undef HAVE_UNLOCKED_LINE_OPS
@ -408,6 +458,7 @@ typedef unsigned smalluint;
#endif
#if defined(__GNO__)
# undef HAVE_MEMPCPY
# undef HAVE_CLEARENV
# undef HAVE_FDATASYNC
# undef HAVE_DPRINTF
@ -446,6 +497,11 @@ extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC;
extern char *mkdtemp(char *template) FAST_FUNC;
#endif
#ifndef HAVE_TTYNAME_R
#define ttyname_r bb_ttyname_r
extern int ttyname_r(int fd, char *buf, size_t buflen);
#endif
#ifndef HAVE_SETBIT
# define setbit(a, b) ((a)[(b) >> 3] |= 1 << ((b) & 7))
# define clrbit(a, b) ((a)[(b) >> 3] &= ~(1 << ((b) & 7)))
@ -463,6 +519,18 @@ typedef void (*sighandler_t)(int, int);
extern char *stpcpy(char *p, const char *to_add) FAST_FUNC;
#endif
#ifndef HAVE_MEMPCPY
#include <string.h>
/* In case we are wrong about !HAVE_MEMPCPY, and toolchain _does_ have
* mempcpy(), avoid colliding with it:
*/
#define mempcpy bb__mempcpy
static ALWAYS_INLINE void *mempcpy(void *dest, const void *src, size_t len)
{
return (char *)memcpy(dest, src, len) + len;
}
#endif
#ifndef HAVE_STRCASESTR
extern char *strcasestr(const char *s, const char *pattern) FAST_FUNC;
#endif

23
libbb/auto.string.c Normal file
View File

@ -0,0 +1,23 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 2015 Denys Vlasenko
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//kbuild:lib-y += auto_string.o
#include "libbb.h"
char* FAST_FUNC auto_string(char *str)
{
static char *saved[4];
static uint8_t cur_saved; /* = 0 */
free(saved[cur_saved]);
saved[cur_saved] = str;
cur_saved = (cur_saved + 1) & (ARRAY_SIZE(saved)-1);
return str;
}

View File

@ -5,6 +5,49 @@
#include "libbb.h"
/*
* Return NULL if string is not prefixed with key. Return pointer to the
* first character in string after the prefix key. If key is an empty string,
* return pointer to the beginning of string.
*/
char* FAST_FUNC is_prefixed_with(const char *string, const char *key)
{
#if 0 /* Two passes over key - probably slower */
int len = strlen(key);
if (strncmp(string, key, len) == 0)
return string + len;
return NULL;
#else /* Open-coded */
while (*key != '\0') {
if (*key != *string)
return NULL;
key++;
string++;
}
return (char*)string;
#endif
}
/*
* Return NULL if string is not suffixed with key. Return pointer to the
* beginning of prefix key in string. If key is an empty string return pointer
* to the end of string.
*/
char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
{
size_t key_len = strlen(key);
ssize_t len_diff = strlen(string) - key_len;
if (len_diff >= 0) {
string += len_diff;
if (strcmp(string, key) == 0) {
return (char*)string;
}
}
return NULL;
}
/* returns the array index of the string */
/* (index of first match is returned, or -1) */
int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key)
@ -39,10 +82,9 @@ int FAST_FUNC index_in_strings(const char *strings, const char *key)
int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
{
int i;
int len = strlen(key);
if (len) {
if (key[0]) {
for (i = 0; string_array[i] != 0; i++) {
if (strncmp(string_array[i], key, len) == 0) {
if (is_prefixed_with(string_array[i], key)) {
return i;
}
}
@ -93,3 +135,37 @@ smallint FAST_FUNC yesno(const char *str)
return ret / 3;
}
#endif
#if ENABLE_UNIT_TEST
BBUNIT_DEFINE_TEST(is_prefixed_with)
{
BBUNIT_ASSERT_STREQ(" bar", is_prefixed_with("foo bar", "foo"));
BBUNIT_ASSERT_STREQ("bar", is_prefixed_with("foo bar", "foo "));
BBUNIT_ASSERT_STREQ("", is_prefixed_with("foo", "foo"));
BBUNIT_ASSERT_STREQ("foo", is_prefixed_with("foo", ""));
BBUNIT_ASSERT_STREQ("", is_prefixed_with("", ""));
BBUNIT_ASSERT_NULL(is_prefixed_with("foo", "bar foo"));
BBUNIT_ASSERT_NULL(is_prefixed_with("foo foo", "bar"));
BBUNIT_ASSERT_NULL(is_prefixed_with("", "foo"));
BBUNIT_ENDTEST;
}
BBUNIT_DEFINE_TEST(is_suffixed_with)
{
BBUNIT_ASSERT_STREQ("bar", is_suffixed_with("foo bar", "bar"));
BBUNIT_ASSERT_STREQ("foo", is_suffixed_with("foo", "foo"));
BBUNIT_ASSERT_STREQ("", is_suffixed_with("foo", ""));
BBUNIT_ASSERT_STREQ("", is_suffixed_with("", ""));
BBUNIT_ASSERT_STREQ("foo", is_suffixed_with("barfoofoo", "foo"));
BBUNIT_ASSERT_NULL(is_suffixed_with("foo", "bar foo"));
BBUNIT_ASSERT_NULL(is_suffixed_with("foo foo", "bar"));
BBUNIT_ASSERT_NULL(is_suffixed_with("", "foo"));
BBUNIT_ENDTEST;
}
#endif /* ENABLE_UNIT_TEST */

View File

@ -819,36 +819,25 @@ static char *username_path_completion(char *ud)
return tilde_name;
}
#define LINE_BUFF_SIZE 256
/* ~use<tab> - find all users with this prefix.
* Return the length of the prefix used for matching.
*/
static NOINLINE unsigned complete_username(const char *ud)
{
/* Using _r function to avoid pulling in static buffers */
char *line_buff;
struct passwd pwd;
struct passwd *result;
struct passwd *pw;
unsigned userlen;
ud++; /* skip ~ */
userlen = strlen(ud);
line_buff = malloc(LINE_BUFF_SIZE);
if (!line_buff)
goto ret;
setpwent();
while (!getpwent_r(&pwd, line_buff, LINE_BUFF_SIZE, &result)) {
/* Null usernames should result in all users as possible completions. */
if (/*!userlen || */ strncmp(ud, pwd.pw_name, userlen) == 0) {
add_match(xasprintf("~%s/", pwd.pw_name));
while ((pw = getpwent()) != NULL) { /* Null usernames should result in all users as possible completions. */
if (/* !ud[0] || */ is_prefixed_with(pw->pw_name, ud)) {
add_match(xasprintf("~%s/", pw->pw_name));
}
}
endpwent();
endpwent(); /* don't keep password file open */
free(line_buff);
ret:
return 1 + userlen;
}
# endif /* FEATURE_USERNAME_COMPLETION */
@ -960,7 +949,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
if (!pfind[0] && DOT_OR_DOTDOT(name_found))
continue;
/* match? */
if (strncmp(name_found, pfind, pf_len) != 0)
if (!is_prefixed_with(name_found, pfind))
continue; /* no */
found = concat_path_file(paths[i], name_found);
@ -2069,15 +2058,16 @@ static void parse_and_put_prompt(const char *prmt_ptr)
cwd_buf = xrealloc_getcwd_or_warn(NULL);
if (!cwd_buf)
cwd_buf = (char *)bb_msg_unknown;
else {
else if (home_pwd_buf[0]) {
char *after_home_user;
/* /home/user[/something] -> ~[/something] */
l = strlen(home_pwd_buf);
if (l != 0
&& strncmp(home_pwd_buf, cwd_buf, l) == 0
&& (cwd_buf[l] == '/' || cwd_buf[l] == '\0')
after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf);
if (after_home_user
&& (*after_home_user == '/' || *after_home_user == '\0')
) {
cwd_buf[0] = '~';
overlapping_strcpy(cwd_buf + 1, cwd_buf + l);
overlapping_strcpy(cwd_buf + 1, after_home_user);
}
}
}

View File

@ -1,26 +0,0 @@
/* Copy memory area and return pointer after last written byte.
Adapted from Gnulib (as of Dec 15, 2014).
Copyright (C) 2003, 2007, 2009-2014 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
#include <string.h>
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
last written byte. */
void *
mempcpy (void *dest, const void *src, size_t n)
{
return (char *) memcpy (dest, src, n) + n;
}

View File

@ -42,7 +42,7 @@ const char bb_PATH_root_path[] ALIGN1 =
"PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH;
const int const_int_1 = 1;
//const int const_int_1 = 1;
/* explicitly = 0, otherwise gcc may make it a common variable
* and it will end up in bss */
const int const_int_0 = 0;

View File

@ -15,7 +15,7 @@
#define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
int FAST_FUNC bb_parse_mode(const char *s, unsigned current_mode)
{
static const mode_t who_mask[] = {
S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO, /* a */
@ -46,13 +46,12 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
tmp = strtoul(s, &e, 8);
if (*e || (tmp > 07777U)) { /* Check range and trailing chars. */
return 0;
return -1;
}
*current_mode = tmp;
return 1;
return tmp;
}
new_mode = *current_mode;
new_mode = current_mode;
/* Note: we allow empty clauses, and hence empty modes.
* We treat an empty mode as no change to perms. */
@ -71,7 +70,7 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
if (*p == *s) {
wholist |= who_mask[(int)(p-who_chars)];
if (!*++s) {
return 0;
return -1;
}
goto WHO_LIST;
}
@ -80,7 +79,7 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
do { /* Process action list. */
if ((*s != '+') && (*s != '-')) {
if (*s != '=') {
return 0;
return -1;
}
/* Since op is '=', clear all bits corresponding to the
* wholist, or all file bits if wholist is empty. */
@ -145,6 +144,5 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
} while (*s && (*s != ','));
}
*current_mode = new_mode;
return 1;
return new_mode;
}

View File

@ -209,3 +209,22 @@ ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream)
return len;
}
#endif
#ifndef HAVE_TTYNAME_R
int ttyname_r(int fd, char *buf, size_t buflen)
{
int r;
char path[sizeof("/proc/self/fd/%d") + sizeof(int)*3];
if (!isatty(fd))
return errno == EINVAL ? ENOTTY : errno;
sprintf(path, "/proc/self/fd/%d", fd);
r = readlink(path, buf, buflen);
if (r < 0)
return errno;
if (r >= buflen)
return ERANGE;
buf[r] = '\0';
return 0;
}
#endif

View File

@ -11,9 +11,6 @@
const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str)
{
static char *saved[4];
static unsigned cur_saved; /* = 0 */
char *dst;
const char *s;
@ -56,10 +53,5 @@ const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str)
}
}
#endif
free(saved[cur_saved]);
saved[cur_saved] = dst;
cur_saved = (cur_saved + 1) & (ARRAY_SIZE(saved)-1);
return dst;
return auto_string(dst);
}

View File

@ -33,7 +33,7 @@ char* FAST_FUNC skip_non_whitespace(const char *s)
char* FAST_FUNC skip_dev_pfx(const char *tty_name)
{
if (strncmp(tty_name, "/dev/", 5) == 0)
if (is_prefixed_with(tty_name, "/dev/"))
tty_name += 5;
return (char*)tty_name;
}

View File

@ -70,3 +70,24 @@ const struct suffix_mult bkm_suffixes[] = {
{ "m", 1024*1024 },
{ "", 0 }
};
const struct suffix_mult cwbkMG_suffixes[] = {
{ "c", 1 },
{ "w", 2 },
{ "b", 512 },
{ "kB", 1000 },
{ "kD", 1000 },
{ "k", 1024 },
{ "KB", 1000 }, /* compat with coreutils dd */
{ "KD", 1000 }, /* compat with coreutils dd */
{ "K", 1024 }, /* compat with coreutils dd */
{ "MB", 1000000 },
{ "MD", 1000000 },
{ "M", 1024*1024 },
{ "GB", 1000000000 },
{ "GD", 1000000000 },
{ "G", 1024*1024*1024 },
/* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
/* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
{ "", 0 }
};

View File

@ -7,35 +7,17 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
/* Keeping it separate allows to NOT suck in stdio for VERY small applets.
/* Keeping it separate allows to NOT pull in stdio for VERY small applets.
* Try building busybox with only "true" enabled... */
#include "libbb.h"
int die_sleep;
#if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH
jmp_buf die_jmp;
#endif
void (*die_func)(void);
void FAST_FUNC xfunc_die(void)
{
if (die_sleep) {
if ((ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH)
&& die_sleep < 0
) {
/* Special case. We arrive here if NOFORK applet
* calls xfunc, which then decides to die.
* We don't die, but jump instead back to caller.
* NOFORK applets still cannot carelessly call xfuncs:
* p = xmalloc(10);
* q = xmalloc(10); // BUG! if this dies, we leak p!
*/
/* -2222 means "zero" (longjmp can't pass 0)
* run_nofork_applet() catches -2222. */
longjmp(die_jmp, xfunc_error_retval ? xfunc_error_retval : -2222);
}
sleep(die_sleep);
}
if (die_func)
die_func();
if (!is_forked_child())
exit(xfunc_error_retval);
else

View File

@ -318,7 +318,6 @@ off_t FAST_FUNC fdlength(int fd)
else bottom = pos;
// If we can't, it's smaller.
} else {
if (bottom == top) {
if (!top) return 0;

View File

@ -112,6 +112,11 @@ char* FAST_FUNC xstrndup(const char *s, int n)
return memcpy(t, s, n);
}
void* FAST_FUNC xmemdup(const void *s, int n)
{
return memcpy(xmalloc(n), s, n);
}
// Die if we can't open a file and return a FILE* to it.
// Notice we haven't got xfread(), This is for use with fscanf() and friends.
FILE* FAST_FUNC xfopen(const char *path, const char *mode)

View File

@ -472,7 +472,7 @@ enum {
MAYBE_ASSIGNMENT = 0,
DEFINITELY_ASSIGNMENT = 1,
NOT_ASSIGNMENT = 2,
/* Not an assigment, but next word may be: "if v=xyz cmd;" */
/* Not an assignment, but next word may be: "if v=xyz cmd;" */
WORD_IS_KEYWORD = 3
};
/* Used for initialization: o_string foo = NULL_O_STRING; */
@ -1683,10 +1683,11 @@ static sighandler_t install_sighandler(int sig, sighandler_t handler)
#if ENABLE_HUSH_JOB
static void xfunc_has_died(void);
/* After [v]fork, in child: do not restore tty pgrp on xfunc death */
# define disable_restore_tty_pgrp_on_exit() (die_sleep = 0)
# define disable_restore_tty_pgrp_on_exit() (die_func = NULL)
/* After [v]fork, in parent: restore tty pgrp on xfunc death */
# define enable_restore_tty_pgrp_on_exit() (die_sleep = -1)
# define enable_restore_tty_pgrp_on_exit() (die_func = xfunc_has_died)
/* Restores tty foreground process group, and exits.
* May be called as signal handler for fatal signal
@ -1820,6 +1821,15 @@ static void hush_exit(int exitcode)
#endif
}
static void xfunc_has_died(void) NORETURN;
static void xfunc_has_died(void)
{
/* xfunc has failed! die die die */
/* no EXIT traps, this is an escape hatch! */
G.exiting = 1;
hush_exit(xfunc_error_retval);
}
//TODO: return a mask of ALL handled sigs?
static int check_and_run_traps(void)
@ -3415,11 +3425,29 @@ static int reserved_word(o_string *word, struct parse_context *ctx)
old->command->group = ctx->list_head;
old->command->cmd_type = CMD_NORMAL;
# if !BB_MMU
o_addstr(&old->as_string, ctx->as_string.data);
o_free_unsafe(&ctx->as_string);
old->command->group_as_string = xstrdup(old->as_string.data);
debug_printf_parse(("pop, remembering as:'%s'\n",
old->command->group_as_string));
/* At this point, the compound command's string is in
* ctx->as_string... except for the leading keyword!
* Consider this example: "echo a | if true; then echo a; fi"
* ctx->as_string will contain "true; then echo a; fi",
* with "if " remaining in old->as_string!
*/
{
char *str;
int len = old->as_string.length;
/* Concatenate halves */
o_addstr(&old->as_string, ctx->as_string.data);
o_free_unsafe(&ctx->as_string);
/* Find where leading keyword starts in first half */
str = old->as_string.data + len;
if (str > old->as_string.data)
str--; /* skip whitespace after keyword */
while (str > old->as_string.data && isalpha(str[-1]))
str--;
/* Ugh, we're done with this horrid hack */
old->command->group_as_string = xstrdup(str);
debug_printf_parse(("pop, remembering as:'%s'\n",
old->command->group_as_string));
}
# endif
*ctx = *old; /* physical copy */
free(old);
@ -4518,7 +4546,7 @@ static struct pipe *parse_stream(char **pstring,
pi = NULL;
}
#if !BB_MMU
debug_printf_parse(("as_string '%s'\n", ctx.as_string.data));
debug_printf_parse(("as_string1 '%s'\n", ctx.as_string.data));
if (pstring)
*pstring = ctx.as_string.data;
else
@ -4669,7 +4697,7 @@ static struct pipe *parse_stream(char **pstring,
) {
o_free(&dest);
#if !BB_MMU
debug_printf_parse(("as_string '%s'\n", ctx.as_string.data));
debug_printf_parse(("as_string2 '%s'\n", ctx.as_string.data));
if (pstring)
*pstring = ctx.as_string.data;
else
@ -4909,9 +4937,6 @@ static struct pipe *parse_stream(char **pstring,
* with redirect_opt_num(), but bash doesn't do it.
* "echo foo 2| cat" yields "foo 2". */
done_command(&ctx);
#if !BB_MMU
o_reset_to_empty_unquoted(&ctx.as_string);
#endif
}
goto new_cmd;
case '(':
@ -5660,7 +5685,6 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
!!(output->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)));
}
break;
} /* switch (char after <SPECIAL_VAR_SYMBOL>) */
if (val && val[0]) {
@ -6291,7 +6315,7 @@ static void xforked_child(void *args_struct) {
* Our solution: ONLY bare $(trap) or `trap` is special.
*/
args->s = skip_whitespace(args->s);
if (strncmp(args->s, "trap", 4) == 0
if (is_prefixed_with(args->s, "trap")
&& skip_whitespace(args->s + 4)[0] == '\0'
) {
static const char *const argv[] = { NULL, NULL };
@ -7226,7 +7250,7 @@ static int checkjobs(struct pipe *fg_pipe)
int sig = WTERMSIG(status);
if (i == fg_pipe->num_cmds-1)
/* TODO: use strsignal() instead for bash compat? but that's bloat... */
printf("%s\n", sig == SIGINT || sig == SIGPIPE ? "" : get_signame(sig));
puts(sig == SIGINT || sig == SIGPIPE ? "" : get_signame(sig));
/* TODO: if (WCOREDUMP(status)) + " (core dumped)"; */
/* TODO: MIPS has 128 sigs (1..128), what if sig==128 here?
* Maybe we need to use sig | 128? */
@ -8601,12 +8625,7 @@ int hush_main(int argc, char **argv)
/* Initialize some more globals to non-zero values */
cmdedit_update_prompt();
if (setjmp(die_jmp)) {
/* xfunc has failed! die die die */
/* no EXIT traps, this is an escape hatch! */
G.exiting = 1;
hush_exit(xfunc_error_retval);
}
die_func = xfunc_has_died;
/* Shell is non-interactive at first. We need to call
* install_special_sighandlers() if we are going to execute "sh <script>",
@ -8902,9 +8921,7 @@ int hush_main(int argc, char **argv)
install_special_sighandlers();
}
# endif
/* -1 is special - makes xfuncs longjmp, not exit
* (we reset die_sleep = 0 whereever we [v]fork) */
enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */
enable_restore_tty_pgrp_on_exit();
# if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0
{
@ -9765,24 +9782,29 @@ static int FAST_FUNC builtin_umask(char **argv)
int rc;
mode_t mask;
rc = 1;
mask = umask(0);
argv = skip_dash_dash(argv);
if (argv[0]) {
mode_t old_mask = mask;
mask ^= 0777;
rc = bb_parse_mode(argv[0], &mask);
mask ^= 0777;
if (rc == 0) {
/* numeric umasks are taken as-is */
/* symbolic umasks are inverted: "umask a=rx" calls umask(222) */
if (!isdigit(argv[0][0]))
mask ^= 0777;
mask = bb_parse_mode(argv[0], mask);
if (!isdigit(argv[0][0]))
mask ^= 0777;
if ((unsigned)mask > 0777) {
mask = old_mask;
/* bash messages:
* bash: umask: 'q': invalid symbolic mode operator
* bash: umask: 999: octal number out of range
*/
bb_error_msg("%s: invalid mode '%s'", "umask", argv[0]);
rc = 0;
}
} else {
rc = 1;
/* Mimic bash */
printf("%04o\n", (unsigned) mask);
/* fall through and restore mask which we set to 0 */
@ -9927,12 +9949,9 @@ static int FAST_FUNC builtin_wait(char **argv)
return EXIT_FAILURE;
}
if (waitpid(pid, &status, 0) == pid) {
ret = WEXITSTATUS(status);
if (WIFSIGNALED(status))
ret = 128 + WTERMSIG(status);
else if (WIFEXITED(status))
ret = WEXITSTATUS(status);
else /* wtf? */
ret = EXIT_FAILURE;
} else {
bb_perror_msg("wait %s", *argv);
ret = 127;

View File

@ -0,0 +1,5 @@
1
1
0

View File

@ -0,0 +1 @@
x=0; f() { local x=1; echo $x; local x; echo $x; unset x; echo $x; local x; echo $x; }; f; echo $x

View File

@ -0,0 +1,2 @@
glob3.tests
./glob3.tests

View File

@ -0,0 +1,2 @@
echo "glob3.test"*
echo "./glob3.test"*

View File

@ -0,0 +1,2 @@
Ok
0

View File

@ -0,0 +1,15 @@
#!/bin/sh
func()
{
while read p; do echo "$p"; done
}
pipe_to_func()
{
# We had a NOMMU bug which caused "echo Ok |" part ot be lost
echo Ok | func
}
pipe_to_func | cat
echo $?

View File

@ -0,0 +1 @@
/b/c/

View File

@ -0,0 +1,3 @@
a=/b/c/*
b=\\
echo ${a%$b*}

View File

@ -0,0 +1,2 @@
12
9

View File

@ -0,0 +1,3 @@
unset a
echo $((3 + ${a:=$((4 + 5))}))
echo $a

View File

@ -0,0 +1 @@
a_\_z_c

View File

@ -0,0 +1,2 @@
v="a\bc"
echo ${v/\\b/_\\_\z_}

View File

@ -0,0 +1 @@
ax/yc

View File

@ -0,0 +1,2 @@
v="abc"
echo ${v/b/x/y}

View File

@ -0,0 +1 @@
axcabc

View File

@ -0,0 +1,2 @@
v="abcabc"
echo ${v/b/x}

View File

@ -0,0 +1 @@
axcaxc

View File

@ -0,0 +1,2 @@
v="abcabc"
echo ${v//b/x}

View File

@ -0,0 +1 @@
axc

View File

@ -0,0 +1,2 @@
v="ab/c"
echo ${v/b\//x}

View File

@ -0,0 +1 @@
<>

View File

@ -0,0 +1 @@
foo=\\ echo "<${foo#[\\]}>"

View File

@ -0,0 +1 @@
~root

View File

@ -0,0 +1,2 @@
unset a
echo "${a:-~root}"

View File

@ -419,7 +419,7 @@ static void printlim(unsigned opts, const struct rlimit *limit,
val = limit->rlim_cur;
if (val == RLIM_INFINITY)
printf("unlimited\n");
puts("unlimited");
else {
val >>= l->factor_shift;
printf("%llu\n", (long long) val);
@ -530,7 +530,6 @@ shell_builtin_ulimit(char **argv)
/* bad option. getopt already complained. */
break;
}
} /* while (there are options) */
return 0;