oweals/busybox.git
6 years agohttpd: fix handling of range requests 1_24_stable
Denys Vlasenko [Mon, 18 Sep 2017 11:09:11 +0000 (13:09 +0200)]
httpd: fix handling of range requests

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: fix a bug with "stdio rewind on exit". Closes 9186
Denys Vlasenko [Fri, 19 Aug 2016 18:22:45 +0000 (20:22 +0200)]
hush: fix a bug with "stdio rewind on exit". Closes 9186

With FEATURE_SH_STANDALONE=y, run this in a "sh SCRIPT":

sha256sum /dev/null
echo END

sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s.
By this time, entire script is read, and buffered in a FILE object
from fopen("SCRIPT"). But fgetc() did not consume entire input.
exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'.
(this may be libc-specific).
This change of fd position *is shared with the parent*!

Now parent can read more, and it thinks there is another "echo END".
End result: two "echo END"s are run.

`cmd` and arithmetic also need the fix for this, even without
FEATURE_SH_STANDALONE.

Fix this by _exit()ing instead.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash_test: ignore generated files
Mike Frysinger [Tue, 22 Mar 2016 22:15:24 +0000 (18:15 -0400)]
ash_test: ignore generated files

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit b9b7aa1910907f59f1130667fbe7b870087e97f8)

8 years agoash: simplify EOF/newline handling in list parser
Ron Yorston [Thu, 29 Oct 2015 11:30:55 +0000 (11:30 +0000)]
ash: simplify EOF/newline handling in list parser

Processing of here documents in ash has had a couple of breakages
which are now the subject of tests.  This commit should fix both.

It is based on the following commit in dash git by Herbert Xu:

   <7c245aa> [PARSER] Simplify EOF/newline handling in list parser

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

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit c0e007663d30f83b0e5e074db34dcffaa8915e99)

8 years agoRevert "ash: fix a SEGV case in an invalid heredoc" xxx
Ron Yorston [Thu, 29 Oct 2015 11:30:22 +0000 (11:30 +0000)]
Revert "ash: fix a SEGV case in an invalid heredoc" xxx

This reverts commit 7e66102f762a7d80715f0c7e5925433256b78cee but
leaves the test in place as it's still valid.

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 6bd2fabc52fa76b69a65772878e2e745c0fff3ff)

8 years agoash: add test for issue with here document
Ron Yorston [Thu, 29 Oct 2015 11:29:59 +0000 (11:29 +0000)]
ash: add test for issue with here document

This used to work but doesn't now:

foo () {
cat <<EOF && { echo "$1" ; }
$1
EOF
}

foo "bar"

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 9121510dc659baf6664456796c195460468c850b)

8 years agoash: fix corruption of ${#var} if $var contains UTF-8 characters
Ron Yorston [Fri, 18 Mar 2016 11:29:19 +0000 (11:29 +0000)]
ash: fix corruption of ${#var} if $var contains UTF-8 characters

As reported in bug 8506:

   $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz
   $ echo ${#X}
   abcd26

The result should be 26.

This regression was introduced by:

   <d68d1fb> 2015-05-18 [Ron Yorston]  ash: code shrink around varvalue

The length in characters was being used to discard the contents of
the variable instead of the length in bytes.

URL: https://bugs.busybox.net/8506
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 3e3bfb896e0dd8a54caad9c6264e2452566b4012)

8 years agoash: fix error during recursive processing of here document
Ron Yorston [Thu, 29 Oct 2015 16:44:56 +0000 (16:44 +0000)]
ash: fix error during recursive processing of here document

Save the value of the checkkwd flag to prevent it being clobbered
during recursion.

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

function                                             old     new   delta
readtoken                                            190     203     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 713f07d906d9171953be0c12e2369869855b6ca6)

8 years agoudhcp: fix a SEGV on malformed RFC1035-encoded domain name
Denys Vlasenko [Thu, 10 Mar 2016 10:47:58 +0000 (11:47 +0100)]
udhcp: fix a SEGV on malformed RFC1035-encoded domain name

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit d474ffc68290e0a83651c4432eeabfa62cd51e87)

8 years agoudhcpc: fix OPTION_6RD parsing (could overflow its malloced buffer)
Denys Vlasenko [Fri, 26 Feb 2016 14:54:56 +0000 (15:54 +0100)]
udhcpc: fix OPTION_6RD parsing (could overflow its malloced buffer)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 352f79acbd759c14399e39baef21fc4ffe180ac2)

8 years agoBump version to 1.24.2 1_24_2
Denys Vlasenko [Thu, 17 Mar 2016 20:38:03 +0000 (21:38 +0100)]
Bump version to 1.24.2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoscripts/trylink: fix static build with glibc again. Closes 8471
Denys Vlasenko [Thu, 17 Mar 2016 20:37:12 +0000 (21:37 +0100)]
scripts/trylink: fix static build with glibc again. Closes 8471

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agotruncate: always set mode when opening file to avoid fortify errors
Ari Sundholm [Mon, 4 Jan 2016 13:40:37 +0000 (15:40 +0200)]
truncate: always set mode when opening file to avoid fortify errors

Busybox crashes due to no mode being given when opening:
$ ./busybox truncate -s 1M foo
*** invalid open64 call: O_CREAT without mode ***: ./busybox terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7f66d921338f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f66d92aac9c]
/lib/x86_64-linux-gnu/libc.so.6(+0xeb6aa)[0x7f66d928b6aa]
./busybox[0x4899f9]
======= Memory map: ========
00400000-004d0000 r-xp 00000000 00:1a 137559                             /home/ari/busybox/busybox
006cf000-006d0000 r--p 000cf000 00:1a 137559                             /home/ari/busybox/busybox
006d0000-006d1000 rw-p 000d0000 00:1a 137559                             /home/ari/busybox/busybox
006d1000-006d4000 rw-p 00000000 00:00 0
014e7000-01508000 rw-p 00000000 00:00 0                                  [heap]
7f66d8f8a000-7f66d8fa0000 r-xp 00000000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d8fa0000-7f66d919f000 ---p 00016000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d919f000-7f66d91a0000 rw-p 00015000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d91a0000-7f66d935b000 r-xp 00000000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d935b000-7f66d955a000 ---p 001bb000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955a000-7f66d955e000 r--p 001ba000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955e000-7f66d9560000 rw-p 001be000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d9560000-7f66d9565000 rw-p 00000000 00:00 0
7f66d9565000-7f66d966a000 r-xp 00000000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d966a000-7f66d9869000 ---p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d9869000-7f66d986a000 r--p 00104000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986a000-7f66d986b000 rw-p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986b000-7f66d988e000 r-xp 00000000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a64000-7f66d9a67000 rw-p 00000000 00:00 0
7f66d9a8a000-7f66d9a8d000 rw-p 00000000 00:00 0
7f66d9a8d000-7f66d9a8e000 r--p 00022000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8e000-7f66d9a8f000 rw-p 00023000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8f000-7f66d9a90000 rw-p 00000000 00:00 0
7ffc47761000-7ffc47782000 rw-p 00000000 00:00 0                          [stack]
7ffc477ab000-7ffc477ad000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)
$

Fix this by simply always setting the mode, as it doesn't hurt even
when O_CREAT is not specified.

This bug is a regression introduced in fc3e40e, as xopen(), which
was originally used, would automatically set the mode.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit e111a1640494fe87fc913f94fae3bb805de0fc99)

8 years ago[g]unzip: fix recent breakage.
Denys Vlasenko [Fri, 30 Oct 2015 22:41:53 +0000 (23:41 +0100)]
[g]unzip: fix recent breakage.

Also, do emit error message we so painstakingly pass from gzip internals

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 6bd3fff51aa74e2ee2d87887b12182a3b09792ef)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
8 years agounzip: test for bad archive SEGVing
Denys Vlasenko [Mon, 26 Oct 2015 18:33:05 +0000 (19:33 +0100)]
unzip: test for bad archive SEGVing

function                                             old     new   delta
huft_build                                          1296    1300      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 1de25a6e87e0e627aa34298105a3d17c60a1f44e)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
8 years agoApply post-1.24.0 patches, bump version to 1.24.1 1_24_1
Denys Vlasenko [Sat, 24 Oct 2015 00:29:00 +0000 (02:29 +0200)]
Apply post-1.24.0 patches, bump version to 1.24.1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoBump version to 1.24.0 1_24_0
Denys Vlasenko [Mon, 12 Oct 2015 12:33:03 +0000 (14:33 +0200)]
Bump version to 1.24.0

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibpwdgrp: do not require that /etc/passwd entries have nonempty home and shell
Denys Vlasenko [Mon, 12 Oct 2015 02:06:18 +0000 (04:06 +0200)]
libpwdgrp: do not require that /etc/passwd entries have nonempty home and shell

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agorandconfig fixes
Denys Vlasenko [Mon, 12 Oct 2015 01:15:36 +0000 (03:15 +0200)]
randconfig fixes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agobuild system: remove special-casing for extra libs
Denys Vlasenko [Mon, 12 Oct 2015 01:12:17 +0000 (03:12 +0200)]
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>
8 years agorandconfig fixes
Denys Vlasenko [Sun, 11 Oct 2015 21:43:29 +0000 (23:43 +0200)]
randconfig fixes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agohush: code shrink
Denys Vlasenko [Sun, 11 Oct 2015 19:47:11 +0000 (21:47 +0200)]
hush: code shrink

function                                             old     new   delta
builtin_wait                                         347     328     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agorandconfig fix
Denys Vlasenko [Sun, 11 Oct 2015 14:58:18 +0000 (16:58 +0200)]
randconfig fix

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agorandconfig fixes
Denys Vlasenko [Sun, 11 Oct 2015 14:27:55 +0000 (16:27 +0200)]
randconfig fixes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: shrink umask code
Denys Vlasenko [Sat, 10 Oct 2015 18:17:12 +0000 (20:17 +0200)]
ash: shrink umask code

function                                             old     new   delta
umaskcmd                                             258     248     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agouse auto_string() where appropriate to kill a few statics
Denys Vlasenko [Fri, 9 Oct 2015 16:16:40 +0000 (18:16 +0200)]
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>
8 years agolibbb: auto_string() for efficient handling of temporary malloced stirngs
Denys Vlasenko [Fri, 9 Oct 2015 15:59:56 +0000 (17:59 +0200)]
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>
8 years agoremove global "jmp_buf die_jmp" from !FEATURE_PREFER_APPLETS builds
Denys Vlasenko [Fri, 9 Oct 2015 14:42:57 +0000 (16:42 +0200)]
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>
8 years agoash: "you have mail" should ignore first change in mtime
Denys Vlasenko [Fri, 9 Oct 2015 14:02:53 +0000 (16:02 +0200)]
ash: "you have mail" should ignore first change in mtime

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: simplify "you have mail" code
Denys Vlasenko [Fri, 9 Oct 2015 13:52:03 +0000 (15:52 +0200)]
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>
8 years agoash: make dowait() a bit more readable. Logic is unchanged
Denys Vlasenko [Fri, 9 Oct 2015 13:40:13 +0000 (15:40 +0200)]
ash: make dowait() a bit more readable. Logic is unchanged

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoupdated android_ndk_defconfig
Denys Vlasenko [Thu, 8 Oct 2015 16:17:31 +0000 (18:17 +0200)]
updated android_ndk_defconfig

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoudhcpc: fix for some Android toolchain breakage
Denys Vlasenko [Thu, 8 Oct 2015 16:13:57 +0000 (18:13 +0200)]
udhcpc: fix for some Android toolchain breakage

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoiproute: more string reuse
Denys Vlasenko [Thu, 8 Oct 2015 15:15:08 +0000 (17:15 +0200)]
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>
8 years agoiproute: don't hardcode the path to config files
Christoph J. Thompson [Thu, 8 Oct 2015 15:06:06 +0000 (17:06 +0200)]
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>
8 years agoip: increased max ID for /etc/iproute2/rt_tables to 1023
Denys Vlasenko [Thu, 8 Oct 2015 13:10:10 +0000 (15:10 +0200)]
ip: increased max ID for  /etc/iproute2/rt_tables to 1023

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibiproute: use itoa() where appropriate
Denys Vlasenko [Thu, 8 Oct 2015 11:02:28 +0000 (13:02 +0200)]
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>
8 years agojoin some common strings, -400 bytes
Denys Vlasenko [Thu, 8 Oct 2015 09:24:44 +0000 (11:24 +0200)]
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>
8 years agobuild system: -fno-builtin-printf
Denys Vlasenko [Wed, 7 Oct 2015 20:42:45 +0000 (22:42 +0200)]
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>
8 years agofind: support "find . -delete" idiom - do not try rmdir(".")
Denys Vlasenko [Wed, 7 Oct 2015 19:01:47 +0000 (21:01 +0200)]
find: support "find . -delete" idiom - do not try rmdir(".")

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agomd5sum: code shrink
Denys Vlasenko [Wed, 7 Oct 2015 17:17:01 +0000 (19:17 +0200)]
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>
8 years agoash: use a more typical form of "print four octal digits" format
Denys Vlasenko [Wed, 7 Oct 2015 15:57:53 +0000 (17:57 +0200)]
ash: use a more typical form of "print four octal digits" format

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb: more compact API for bb_parse_mode()
Denys Vlasenko [Wed, 7 Oct 2015 15:55:33 +0000 (17:55 +0200)]
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>
8 years agoash: shrink "umask -S" code
Denys Vlasenko [Wed, 7 Oct 2015 15:32:56 +0000 (17:32 +0200)]
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>
8 years agohush: fix umask: umask(022) was setting umask(755)
Denys Vlasenko [Wed, 7 Oct 2015 14:56:20 +0000 (16:56 +0200)]
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>
8 years agoash: a bunch of trivial simplifications
Denys Vlasenko [Wed, 7 Oct 2015 13:44:36 +0000 (15:44 +0200)]
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>
8 years agowget: make it possible to have both SSL helpers configured
Denys Vlasenko [Wed, 7 Oct 2015 00:40:53 +0000 (02:40 +0200)]
wget: make it possible to have both SSL helpers configured

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoifplugd: discovered why it needed net/ethernet.h: just for ETH_ALEN
Denys Vlasenko [Wed, 7 Oct 2015 00:02:56 +0000 (02:02 +0200)]
ifplugd: discovered why it needed net/ethernet.h: just for ETH_ALEN

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agossl_helper: tweaks discovered while building 32-bit version
Denys Vlasenko [Wed, 7 Oct 2015 00:00:11 +0000 (02:00 +0200)]
ssl_helper: tweaks discovered while building 32-bit version

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agowget: make openssl/ssl_helper choice configurable
Denys Vlasenko [Tue, 6 Oct 2015 23:39:40 +0000 (01:39 +0200)]
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>
8 years agoqemu testing: extract_od_binary.sh: support huge files (and broken od)
Denys Vlasenko [Mon, 5 Oct 2015 14:46:29 +0000 (16:46 +0200)]
qemu testing: extract_od_binary.sh: support huge files (and broken od)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agouudecode: tolerate text input with CR+LF line ends
Denys Vlasenko [Mon, 5 Oct 2015 13:10:44 +0000 (15:10 +0200)]
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>
8 years agoqemu testing: Do build brctl and ifplugd; force mips32 dialect
Denys Vlasenko [Mon, 5 Oct 2015 10:43:04 +0000 (12:43 +0200)]
qemu testing: Do build brctl and ifplugd; force mips32 dialect

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoqemu testing: fix hexdumping of binary
Denys Vlasenko [Mon, 5 Oct 2015 10:34:24 +0000 (12:34 +0200)]
qemu testing: fix hexdumping of binary

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoAboriginal linux/musl build fixes
Denys Vlasenko [Mon, 5 Oct 2015 09:15:43 +0000 (11:15 +0200)]
Aboriginal linux/musl build fixes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoAdd qemu_multiarch_testing/
Denys Vlasenko [Mon, 5 Oct 2015 07:04:04 +0000 (09:04 +0200)]
Add qemu_multiarch_testing/

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoawk: support "length" form of "length()". Closes 8371
Denys Vlasenko [Fri, 2 Oct 2015 00:41:39 +0000 (02:41 +0200)]
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>
8 years agoumount: always use umount2 syscall with specified flags
Denys Vlasenko [Thu, 1 Oct 2015 16:50:06 +0000 (18:50 +0200)]
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>
8 years agoadduser: fix help text
Denys Vlasenko [Mon, 21 Sep 2015 19:11:12 +0000 (21:11 +0200)]
adduser: fix help text

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoadduser: Add -k /path/to/skel
Bernhard Reutner-Fischer [Mon, 25 May 2015 21:25:19 +0000 (23:25 +0200)]
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>
8 years agoi2c-tools: rename remaining defines
Bartosz Golaszewski [Fri, 4 Sep 2015 08:38:48 +0000 (10:38 +0200)]
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>
8 years agoi2c-tools: remove duplicate definitions
Bartosz Golaszewski [Fri, 4 Sep 2015 08:35:22 +0000 (10:35 +0200)]
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>
8 years agosort: fix -kN,M handling (was including last separator into the comparison)
Denys Vlasenko [Sat, 19 Sep 2015 20:06:40 +0000 (22:06 +0200)]
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>
8 years agolibbb: another unit test for is_suffixed_with
Tito Ragusa [Tue, 15 Sep 2015 21:38:01 +0000 (23:38 +0200)]
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>
8 years agomodprobe: handle module arguments containing spaces
Peter Korsgaard [Wed, 9 Sep 2015 12:55:07 +0000 (14:55 +0200)]
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>
8 years agoash: fix slash treatment in expmeta
Ron Yorston [Fri, 4 Sep 2015 09:32:41 +0000 (10:32 +0100)]
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>
8 years agohush: fix a nommu bug where a part of function body is lost if run in a pipe
Denys Vlasenko [Fri, 4 Sep 2015 04:22:10 +0000 (06:22 +0200)]
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>
8 years agoMakefile.flags: survive a build system which has no pthread
Denys Vlasenko [Fri, 4 Sep 2015 02:20:51 +0000 (04:20 +0200)]
Makefile.flags: survive a build system which has no pthread

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash,hush: add a test which fails for ash since commit 549deab
Denys Vlasenko [Fri, 4 Sep 2015 01:33:02 +0000 (03:33 +0200)]
ash,hush: add a test which fails for ash since commit 549deab

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoash: add tests adapted from hush glob tests. glob2.tests currently fails
Denys Vlasenko [Fri, 4 Sep 2015 01:27:08 +0000 (03:27 +0200)]
ash: add tests adapted from hush glob tests. glob2.tests currently fails

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb: make is_suffixed_with() return pointer inside string, not key.
Denys Vlasenko [Tue, 25 Aug 2015 19:47:33 +0000 (21:47 +0200)]
libbb: make is_suffixed_with() return pointer inside string, not key.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb: add is_suffixed_with() function
Bartosz Golaszewski [Tue, 25 Aug 2015 14:36:43 +0000 (16:36 +0200)]
libbb: add is_suffixed_with() function

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoping: fix recently introduced build breakage for non-optimizing builds
Denys Vlasenko [Tue, 25 Aug 2015 14:26:31 +0000 (16:26 +0200)]
ping: fix recently introduced build breakage for non-optimizing builds

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agolibbb: add a comment describing the way is_prefixed_with() works
Bartosz Golaszewski [Tue, 25 Aug 2015 11:10:00 +0000 (13:10 +0200)]
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>
8 years agolibbb: add unit tests for is_prefixed_with()
Bartosz Golaszewski [Tue, 25 Aug 2015 11:09:59 +0000 (13:09 +0200)]
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>
8 years agologin: don't print motd if .hushlogin exists in users home
Sören Tempel [Mon, 24 Aug 2015 20:16:48 +0000 (22:16 +0200)]
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>
8 years agodmesg: add -r option to print raw format even when FEATURE_DMESG_PRETTY is enabled
Peter Korsgaard [Mon, 24 Aug 2015 13:54:49 +0000 (15:54 +0200)]
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>
8 years agoifupdown: 'prio' should have been 'metric' in static_up and static_up6
Alex Dowad [Fri, 7 Aug 2015 09:53:26 +0000 (11:53 +0200)]
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>
8 years agolibbb: add setsockopt_foo helpers
Denys Vlasenko [Mon, 24 Aug 2015 17:48:03 +0000 (19:48 +0200)]
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>
8 years agoMerge setsockopt error messages
Denys Vlasenko [Mon, 24 Aug 2015 17:08:14 +0000 (19:08 +0200)]
Merge setsockopt error messages

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agotraceroute: fix help text
Denys Vlasenko [Mon, 24 Aug 2015 16:56:46 +0000 (18:56 +0200)]
traceroute: fix help text

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoMakefile: add missing libraries to LDLIBS
Bartosz Golaszewski [Fri, 14 Aug 2015 06:50:00 +0000 (08:50 +0200)]
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>
8 years agounit-tests: remove code depending on WANT_TIMING
Bartosz Golaszewski [Thu, 13 Aug 2015 13:57:22 +0000 (15:57 +0200)]
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>
8 years agounit-tests: remove unnecesary field from struct bbunit_listelem
Bartosz Golaszewski [Thu, 13 Aug 2015 13:57:21 +0000 (15:57 +0200)]
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>
8 years agoarping: make help text clearer
Denys Vlasenko [Sun, 16 Aug 2015 17:56:16 +0000 (19:56 +0200)]
arping: make help text clearer

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoless: fix botched attempt to use last column
Ron Yorston [Tue, 4 Aug 2015 16:10:37 +0000 (17:10 +0100)]
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>
8 years agoipcalc: fix trivial usage message
Ron Yorston [Sun, 12 Jul 2015 20:19:28 +0000 (21:19 +0100)]
ipcalc: fix trivial usage message

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agozcip: tweak comments and make unsigned division more obvious
Denys Vlasenko [Tue, 4 Aug 2015 13:06:38 +0000 (15:06 +0200)]
zcip: tweak comments and make unsigned division more obvious

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agozcip: another code shrink
Denys Vlasenko [Tue, 4 Aug 2015 12:30:31 +0000 (14:30 +0200)]
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>
8 years agozcip: code shrink
Denys Vlasenko [Tue, 4 Aug 2015 10:28:21 +0000 (12:28 +0200)]
zcip: code shrink

function                                             old     new   delta
zcip_main                                           1263    1230     -33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agozcip: simplify code
Denys Vlasenko [Tue, 4 Aug 2015 01:27:56 +0000 (03:27 +0200)]
zcip: simplify code

function                                             old     new   delta
zcip_main                                           1411    1263    -148

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agouname: make OS name configurable
Ron Yorston [Sun, 12 Jul 2015 15:06:37 +0000 (16:06 +0100)]
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>
8 years agoless: further tweaks to regular file detection
Ron Yorston [Fri, 31 Jul 2015 16:33:24 +0000 (17:33 +0100)]
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>
8 years agodiff.tests: add testcases for -B and single line changes
Aaro Koskinen [Thu, 30 Jul 2015 20:13:26 +0000 (23:13 +0300)]
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>
8 years agodiff: fix -B with single line changes
Aaro Koskinen [Thu, 30 Jul 2015 20:13:25 +0000 (23:13 +0300)]
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>
8 years agoless: improve regular file detection in line counting code
Denys Vlasenko [Fri, 31 Jul 2015 14:42:20 +0000 (16:42 +0200)]
less: improve regular file detection in line counting code

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 years agoless: allow use of last column of terminal
Ron Yorston [Fri, 24 Jul 2015 13:29:45 +0000 (14:29 +0100)]
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>
8 years agoless: fix line number confusion
Ron Yorston [Fri, 24 Jul 2015 13:29:13 +0000 (14:29 +0100)]
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>
8 years agoless: add a function to detect when display is at end of file
Ron Yorston [Fri, 24 Jul 2015 13:28:50 +0000 (14:28 +0100)]
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>
8 years agoless: rearrange detection of non-regular files
Ron Yorston [Fri, 24 Jul 2015 13:28:08 +0000 (14:28 +0100)]
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>