oweals/busybox.git
5 years agoash: add bash-compatible EPOCH variables
Ron Yorston [Mon, 15 Apr 2019 09:52:05 +0000 (10:52 +0100)]
ash: add bash-compatible EPOCH variables

Bash 5.0 added the dynamic variable EPOCHSECONDS and EPOCHREALTIME
which return the number of seconds since the Unix Epoch as an
integer or float.  These are useful for logging or tracing.

function                                             old     new   delta
change_epoch                                           -      78     +78
.rodata                                           175167  175235     +68
varinit_data                                         264     312     +48
change_seconds                                         -      24     +24
change_realtime                                        -      24     +24
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/0 up/down: 242/0)             Total: 242 bytes
   text    data     bss     dec     hex filename
 938508    4203    1888  944599   e69d7 busybox_old
 938702    4203    1888  944793   e6a99 busybox_unstripped

v2: Cast tv_sec and tv_usec to unsigned quantities.
    Add brackets to macros.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoash: an unset dynamic variable should not be dynamic
Ron Yorston [Mon, 15 Apr 2019 09:49:35 +0000 (10:49 +0100)]
ash: an unset dynamic variable should not be dynamic

Commit b28d4c346 (ash: [VAR] Move unsetvar functionality into setvareq)
dropped the code that caused dynamic variables to lose their special
properties when unset.  Add it back again.

function                                             old     new   delta
setvareq                                             346     360     +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 14/0)               Total: 14 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohush: add bash-compatible EPOCH variables
Ron Yorston [Mon, 15 Apr 2019 09:48:29 +0000 (10:48 +0100)]
hush: add bash-compatible EPOCH variables

Bash 5.0 added the dynamic variable EPOCHSECONDS and EPOCHREALTIME
which return the number of seconds since the Unix Epoch as an
integer or float.  These are useful for logging or tracing.

function                                             old     new   delta
get_local_var_value                                  207     302     +95
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 95/0)               Total: 95 bytes
   text    data     bss     dec     hex filename
 938702    4203    1888  944793   e6a99 busybox_old
 938797    4203    1888  944888   e6af8 busybox_unstripped

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: extract query string only after proxying check
Denys Vlasenko [Tue, 16 Apr 2019 11:35:56 +0000 (13:35 +0200)]
httpd: extract query string only after proxying check

function                                             old     new   delta
handle_incoming_and_exit                            2398    2370     -28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: make rmt_ip variable local
Denys Vlasenko [Tue, 16 Apr 2019 11:18:12 +0000 (13:18 +0200)]
httpd: make rmt_ip variable local

function                                             old     new   delta
handle_incoming_and_exit                            2385    2398     +13
if_ip_denied_send_HTTP_FORBIDDEN_and_exit             51      54      +3
get_line                                             110     106      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-4)              Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: check denied IPs even before reading 1st query line
Denys Vlasenko [Tue, 16 Apr 2019 10:59:20 +0000 (12:59 +0200)]
httpd: check denied IPs even before reading 1st query line

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: do not decode URL and headers if proxying - send all verbatim
Denys Vlasenko [Tue, 16 Apr 2019 10:45:26 +0000 (12:45 +0200)]
httpd: do not decode URL and headers if proxying - send all verbatim

function                                             old     new   delta
handle_incoming_and_exit                            2566    2385    -181

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: remove duplicate "decode URL escape sequences" code
Denys Vlasenko [Tue, 16 Apr 2019 09:58:28 +0000 (11:58 +0200)]
httpd: remove duplicate "decode URL escape sequences" code

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: put all headers into environment as HTTP_UPPERCASED_HEADER=val
Denys Vlasenko [Tue, 16 Apr 2019 09:37:02 +0000 (11:37 +0200)]
httpd: put all headers into environment as HTTP_UPPERCASED_HEADER=val

Set up environment variables before running the CGI script.
The variables will be named HTTP_<filtered_name> where the <filtered_name>
is the header name capitalized and all characters not matching
[a-z] | [A-Z] | [0-9] replaced with '_'.

function                                             old     new   delta
http_response                                         80      88      +8
http_response_type                                    20      22      +2
send_headers                                         718     715      -3
parse_conf                                          1481    1478      -3
get_line                                             128     110     -18
cgi_io_loop_and_exit                                 599     569     -30
send_cgi_and_exit                                    882     738    -144
handle_incoming_and_exit                            2793    2592    -201
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/6 up/down: 10/-399)          Total: -389 bytes
   text    data     bss     dec     hex filename
 982178     485    7296  989959   f1b07 busybox_old
 981675     485    7296  989456   f1910 busybox_unstripped

Signed-off-by: Alexander Vickberg <wickbergster@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: fix handling of EOF in get_line()
Denys Vlasenko [Tue, 16 Apr 2019 09:07:37 +0000 (11:07 +0200)]
httpd: fix handling of EOF in get_line()

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: add missing {}
Denys Vlasenko [Tue, 16 Apr 2019 08:14:50 +0000 (10:14 +0200)]
httpd: add missing {}

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: do not percent-decode URI if proxying
Denys Vlasenko [Tue, 16 Apr 2019 08:00:06 +0000 (10:00 +0200)]
httpd: do not percent-decode URI if proxying

The proxying is documented as follows:

P:/url:[http://]hostname[:port]/new/path

Howeverm urlcopy is not a true copy anymore when it is fdprint'ed
to proxy_fd, this is because percent_decode_in_place() is called
after the copy is created.

This breaks reverse proxying all URIs containing percent
encoded spaces, e.g. - because a decoded URI will be printed out
to proxy_fd instead of the original.

The fix keeps the logic in place to canonicalize the uri first,
before reverse proxying (one could argue that the uri
should be proxied completely unaltered, except for the prefix
rewrite).

function                                             old     new   delta
handle_incoming_and_exit                            2752    2792     +40

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: fix proxy headers passing - full_write() instead of write()
Denys Vlasenko [Sun, 14 Apr 2019 18:46:57 +0000 (20:46 +0200)]
httpd: fix proxy headers passing - full_write() instead of write()

function                                             old     new   delta
handle_incoming_and_exit                            2763    2752     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohttpd: if remote IP is denied, send FORBIDDEN reply earlier
Denys Vlasenko [Sun, 14 Apr 2019 17:57:13 +0000 (19:57 +0200)]
httpd: if remote IP is denied, send FORBIDDEN reply earlier

While at it, fix sighup_handler to not clobber errno.

function                                             old     new   delta
send_HTTP_FORBIDDEN_and_exit_if_denied_ip              -      47     +47
sighup_handler                                        15      30     +15
handle_incoming_and_exit                            2791    2763     -28
checkPermIP                                           48       -     -48
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/1 up/down: 62/-76)            Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoudhcpc6: code shrink
Denys Vlasenko [Sun, 14 Apr 2019 15:01:10 +0000 (17:01 +0200)]
udhcpc6: code shrink

function                                             old     new   delta
d6_read_interface                                    593     582     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoudhcpc6: add a few comments, no code changes.
Denys Vlasenko [Sat, 13 Apr 2019 17:43:15 +0000 (19:43 +0200)]
udhcpc6: add a few comments, no code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoudhcpc6: make it enabled in defconfig
Denys Vlasenko [Sat, 13 Apr 2019 15:32:40 +0000 (17:32 +0200)]
udhcpc6: make it enabled in defconfig

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoexamples/udhcp/simple.script: fix resolv.conf update if it is a dangling symlink
Rolf Eike Beer [Thu, 28 Mar 2019 14:29:29 +0000 (15:29 +0100)]
examples/udhcp/simple.script: fix resolv.conf update if it is a dangling symlink

If /etc/resolv.conf is a symlink to a tmpfs and the actual file does not
already exist, "readlink -f" will not detect it as symlink. Explicitely check
for that condition before and touch the file, making the other code work as
intended.

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoudhcp: add 100 and 101 dhcp options for ipv4
Antoine Girard-Vallée [Fri, 8 Mar 2019 14:24:42 +0000 (09:24 -0500)]
udhcp: add 100 and 101 dhcp options for ipv4

Support for the IEEE timezone string and timezone database strings (100
and 101 options respectively) is added for ipv4, conforming to RFC-4833.

The two options are passed to hook scripts in the variables tzstr and
tzdbstr.

function                                             old     new   delta
dhcp_option_strings                                  280     294     +14
dhcp_optflags                                         76      80      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 18/0)               Total: 18 bytes

Signed-off-by: Antoine Girard-Vallée <antoine.girard-vallee@savoirfairelinux.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agobrctl: add TODO: "showmacs BR"
Denys Vlasenko [Sat, 13 Apr 2019 13:48:31 +0000 (15:48 +0200)]
brctl: add TODO: "showmacs BR"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agobrctl: simplify str_to_jiffies()
Denys Vlasenko [Sat, 13 Apr 2019 12:17:55 +0000 (14:17 +0200)]
brctl: simplify str_to_jiffies()

function                                             old     new   delta
write_uint                                             -      96     +96
brctl_main                                           721     678     -43
write_ulong                                           96       -     -96
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 96/-139)           Total: -43 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agobrctl: convert remaining commands to work via /sys
Denys Vlasenko [Sat, 13 Apr 2019 11:58:06 +0000 (13:58 +0200)]
brctl: convert remaining commands to work via /sys

function                                             old     new   delta
write_ulong                                            -      96     +96
show_bridge                                          310     338     +28
static.ops                                             3       -      -3
arm_ioctl                                             20       -     -20
packed_usage                                       33344   33315     -29
brctl_main                                           885     721    -164
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/2 up/down: 124/-216)          Total: -92 bytes
   text    data     bss     dec     hex filename
 982112     485    7296  989893   f1ac5 busybox_old
 982157     485    7296  989938   f1af2 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agobrctl: make "show" command retrieve data from /sys
Denys Vlasenko [Fri, 12 Apr 2019 16:52:31 +0000 (18:52 +0200)]
brctl: make "show" command retrieve data from /sys

ioctl interface is obsolete and has no 32/64 compat shim,
making "brctl show" fail for 32-bit userspace and 64-bit kernel.

function                                             old     new   delta
show_bridge                                            -     310    +310
read_file                                              -      64     +64
if_indextoname                                       117       -    -117
brctl_main                                          1183     885    -298
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 0/1 up/down: 374/-415)          Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agostat: reduce storage for human-readable filesystem names
Ron Yorston [Mon, 18 Mar 2019 11:14:52 +0000 (11:14 +0000)]
stat: reduce storage for human-readable filesystem names

function                                             old     new   delta
static.humanname                                       -     236    +236
static.fstype                                          -     140    +140
print_statfs                                         339     341      +2
static.humantypes                                    288       -    -288
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/0 up/down: 378/-288)           Total: 90 bytes
   text    data     bss     dec     hex filename
 982183     485    7296  989964   f1b0c busybox_old
 982152     485    7296  989933   f1aed busybox_unstripped

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoipaddress: remove unused variable no_link
Bernhard Reutner-Fischer [Sun, 7 Apr 2019 16:09:37 +0000 (18:09 +0200)]
ipaddress: remove unused variable no_link

ipaddress.c: In function ‘ipaddr_list_or_flush’:
ipaddress.c:427:6: warning: variable ‘no_link’ set but not used [-Wunused-but-set-variable]

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
5 years agoservice examples: if iface do not exist, retry upping it
Denys Vlasenko [Fri, 5 Apr 2019 16:38:12 +0000 (18:38 +0200)]
service examples: if iface do not exist, retry upping it

I've had a case of a machine where eth0 was appearing a bit later
after the boot, and appearing _downed_. ifplugd then fails to detect
"link up". Thus, depending on how service startup
("ip link set dev eth0 up") races with driver initialization,
ethernet randomly fails to initialize on boot.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agochrt: fix for SCHED_RESET_ON_FORK bit
Denys Vlasenko [Fri, 5 Apr 2019 14:59:07 +0000 (16:59 +0200)]
chrt: fix for SCHED_RESET_ON_FORK bit

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agochrt: do not segfault if policy number is unknown
Denys Vlasenko [Fri, 5 Apr 2019 10:03:48 +0000 (12:03 +0200)]
chrt: do not segfault if policy number is unknown

While at it, improve help text

function                                             old     new   delta
packed_usage                                       33319   33344     +25
policy_name                                            -      22     +22
show_min_max                                          59      64      +5
chrt_main                                            432     429      -3
policies                                              72       -     -72
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/1 up/down: 52/-75)            Total: -23 bytes
   text    data     bss     dec     hex filename
 982150     485    7296  989931   f1aeb busybox_old
 982183     485    7296  989964   f1b0c busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agotelnetd: whitespace fix
Denys Vlasenko [Thu, 4 Apr 2019 14:54:14 +0000 (16:54 +0200)]
telnetd: whitespace fix

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agotelnetd: better AYT handling
Denys Vlasenko [Thu, 4 Apr 2019 14:00:23 +0000 (16:00 +0200)]
telnetd: better AYT handling

function                                             old     new   delta
telnetd_main                                        1792    1837     +45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agotelnetd: Added support for AYT IAC command.
Martin Lewis [Thu, 4 Apr 2019 11:29:32 +0000 (13:29 +0200)]
telnetd: Added support for AYT IAC command.

Fixed a TODO in AYT IAC handling by replying back with a NOP.

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agotop: provide cmdline argument '-H' to enable thread scanning by default
Thomas De Schampheleire [Tue, 26 Mar 2019 12:10:21 +0000 (13:10 +0100)]
top: provide cmdline argument '-H' to enable thread scanning by default

In particular useful when you want to evaluate the threads in batch mode:
    top -Hbn1

function                                             old     new   delta
top_main                                             928     941     +13
packed_usage                                       33317   33319      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 15/0)               Total: 15 bytes

Signed-off-by: Philippe Belet <philippe.belet@nokia.com>
Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: revert change in how "end of file list" is deteced - fixes 'q' in bare "vi"
Denys Vlasenko [Wed, 3 Apr 2019 14:35:23 +0000 (16:35 +0200)]
vi: revert change in how "end of file list" is deteced - fixes 'q' in bare "vi"

function                                             old     new   delta
vi_main                                              273     272      -1
colon                                               2853    2852      -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-2)               Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: code shrink
Denys Vlasenko [Wed, 3 Apr 2019 14:30:50 +0000 (16:30 +0200)]
vi: code shrink

function                                             old     new   delta
new_screen                                            84      75      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: avoid build failure in non-default case
Ron Yorston [Wed, 3 Apr 2019 07:56:30 +0000 (08:56 +0100)]
vi: avoid build failure in non-default case

If vi is built with FEATURE_VI_USE_SIGNALS disabled and
FEATURE_VI_WIN_RESIZE enabled new_screen() is used without a
declaration.  Move the function to avoid this.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agofsync,sync: merge into one source module
Denys Vlasenko [Tue, 2 Apr 2019 12:54:56 +0000 (14:54 +0200)]
fsync,sync: merge into one source module

With FEATURE_SYNC_FANCY not set:

function                                             old     new   delta
fsync_main                                           130     123      -7

With FEATURE_SYNC_FANCY set, should be much larger code size savings.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agofsync,sync: make them similar
Denys Vlasenko [Tue, 2 Apr 2019 12:39:56 +0000 (14:39 +0200)]
fsync,sync: make them similar

sync: add O_NOCTTY
fsync: drop O_NOATIME, add O_NONBLOCK, set exitcode to 1 if fsync() fails,
    update --help message to be similar to sync.
both: reformat code to minimize "diff -u sync.c fsync.c":
    in particular, they use same open() flags now

function                                             old     new   delta
fsync_main                                           126     130      +4
packed_usage                                       33316   33317      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 5/0)                 Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoash: distinguish 'wait -n' from other bashisms
Ron Yorston [Sun, 31 Mar 2019 08:27:09 +0000 (09:27 +0100)]
ash: distinguish 'wait -n' from other bashisms

Add a specific define to indicate which bash compatibility code
implements 'wait -n'.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: rename save_argc -> cmdline_filecnt
Denys Vlasenko [Tue, 2 Apr 2019 10:45:30 +0000 (12:45 +0200)]
vi: rename save_argc -> cmdline_filecnt

function                                             old     new   delta
vi_main                                              272     273      +1
colon                                               2852    2853      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: restore capability to remember insertion cmds for "."
Denys Vlasenko [Tue, 2 Apr 2019 09:50:25 +0000 (11:50 +0200)]
vi: restore capability to remember insertion cmds for "."

function                                             old     new   delta
modifying_cmds                                        17      22      +5
get_one_char                                         103      98      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-5)                Total: 0 bytes
   text    data     bss     dec     hex filename
 982121     485    7296  989902   f1ace busybox_old
 982094     485    7296  989875   f1ab3 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: code shrink
Denys Vlasenko [Mon, 1 Apr 2019 15:17:02 +0000 (17:17 +0200)]
vi: code shrink

function                                             old     new   delta
get_input_line                                       172     175      +3
char_insert                                          444     447      +3
rawmode                                               36      24     -12
edit_file                                            644     626     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 6/-30)             Total: -24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: convert more /**/ comments to //
Denys Vlasenko [Mon, 1 Apr 2019 14:38:06 +0000 (16:38 +0200)]
vi: convert more /**/ comments to //

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: code shrink
Denys Vlasenko [Mon, 1 Apr 2019 14:15:51 +0000 (16:15 +0200)]
vi: code shrink

function                                             old     new   delta
get_one_char                                         108     103      -5
edit_file                                            651     644      -7
do_cmd                                              4696    4688      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-20)             Total: -20 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: use vsnprintf to format status line
Denys Vlasenko [Mon, 1 Apr 2019 13:41:05 +0000 (15:41 +0200)]
vi: use vsnprintf to format status line

This is the last use of "vsprintf" in busybox:

function                                             old     new   delta
status_line_bold                                      72      77      +5
status_line                                           40      45      +5
vsprintf                                              23       -     -23
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/0 up/down: 10/-23)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: rearrange functions, no logic changes
Denys Vlasenko [Mon, 1 Apr 2019 12:18:02 +0000 (14:18 +0200)]
vi: rearrange functions, no logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: rearrange functions, no logic changes
Denys Vlasenko [Mon, 1 Apr 2019 12:08:00 +0000 (14:08 +0200)]
vi: rearrange functions, no logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: rearrange functions, no logic changes
Denys Vlasenko [Mon, 1 Apr 2019 12:02:37 +0000 (14:02 +0200)]
vi: rearrange functions, no logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: rearrange functions, no logic changes
Denys Vlasenko [Mon, 1 Apr 2019 11:59:38 +0000 (13:59 +0200)]
vi: rearrange functions, no logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: rearrange functions, no logic changes
Denys Vlasenko [Mon, 1 Apr 2019 11:55:27 +0000 (13:55 +0200)]
vi: rearrange functions, no logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: fix ^Z not always working as intended
Denys Vlasenko [Mon, 1 Apr 2019 10:29:27 +0000 (12:29 +0200)]
vi: fix ^Z not always working as intended

function                                             old     new   delta
tstp_handler                                          64      71      +7
text_yank                                             54      56      +2
vi_main                                              280     272      -8
do_cmd                                              4705    4696      -9
colon                                               2861    2852      -9
cont_handler                                          66       -     -66
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/3 up/down: 9/-92)             Total: -83 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: install SIGINT handler _after_ restart setjmp is initialized
Denys Vlasenko [Mon, 1 Apr 2019 09:58:11 +0000 (11:58 +0200)]
vi: install SIGINT handler _after_ restart setjmp is initialized

While at it, sanitized comment style, deleted wrong ones, renamed signal
handlers to <sig>_handler(), slightly optimized "cursor home+clear screen".

function                                             old     new   delta
cont_handler                                           -      66     +66
tstp_handler                                           -      64     +64
winch_handler                                          -      60     +60
int_handler                                            -      32     +32
edit_file                                            648     651      +3
redraw                                                52      43      -9
catch_sig                                             32       -     -32
winch_sig                                             60       -     -60
suspend_sig                                           64       -     -64
cont_sig                                              66       -     -66
------------------------------------------------------------------------------
(add/remove: 4/4 grow/shrink: 1/1 up/down: 225/-231)           Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoblockdev: code shrink
Denys Vlasenko [Sat, 30 Mar 2019 19:07:21 +0000 (20:07 +0100)]
blockdev: code shrink

function                                             old     new   delta
bdcmd_names                                            -      82     +82
bdcmd_ioctl                                            -      44     +44
bdcmd_flags                                            -      11     +11
blockdev_main                                        273     258     -15
bdcommands                                           176       -    -176
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 0/1 up/down: 137/-191)          Total: -54 bytes
   text    data     bss     dec     hex filename
 982326     485    7296  990107   f1b9b busybox_old
 982272     485    7296  990053   f1b65 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoip: Fix ip -o link
Stefan Sørensen [Sat, 30 Mar 2019 17:24:46 +0000 (18:24 +0100)]
ip: Fix ip -o link

Commit db169f253854db572c0c2b7e3d74ebbe6afdb97f breaks the "ip -o link"
command, no output is displayed.. Fix by only excluding the link info if
in oneline mode and if the address family is not AF_PACKET.

function                                             old     new   delta
ipaddr_list_or_flush                                1232    1202     -30

Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: allow manual screen update if SIGWINCH isn't supported
Ron Yorston [Wed, 20 Mar 2019 11:00:28 +0000 (11:00 +0000)]
vi: allow manual screen update if SIGWINCH isn't supported

On platforms that don't support SIGWINCH vi can be configured
with FEATURE_VI_USE_SIGNALS disabled and FEATURE_VI_WIN_RESIZE
enabled.  This allows the user to force an update with ^L when
the screen is resized.

However, because the SIGWINCH handler hasn't run the virtual
screen buffer won't have been updated and the display becomes
corrupted.  Fix this by calling new_screen() if necessary.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoman: add "/usr/share/man" as another default MANPATH, fix col override
Denys Vlasenko [Sat, 30 Mar 2019 16:27:09 +0000 (17:27 +0100)]
man: add "/usr/share/man" as another default MANPATH, fix col override

function                                             old     new   delta
static.mpl                                             -      12     +12
packed_usage                                       33307   33316      +9
man_main                                             857     851      -6
add_MANPATH                                          148     138     -10
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 21/-16)              Total: 5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agolibbb: mark scripted_main() as externally visible
Ron Yorston [Sat, 30 Mar 2019 07:47:12 +0000 (07:47 +0000)]
libbb: mark scripted_main() as externally visible

Building with individual binaries enabled fails when embedded
script applets are included:

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

Mark scripted_main() as externally visible.

Reported-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: code shrink, proper printf formatting for strlen()
Denys Vlasenko [Fri, 29 Mar 2019 13:40:01 +0000 (14:40 +0100)]
vi: code shrink, proper printf formatting for strlen()

function                                             old     new   delta
yank_delete                                           98      99      +1
what_reg                                              34      33      -1
text_yank                                             56      54      -2
end_cmd_q                                             17      14      -3
do_cmd                                              4718    4705     -13
colon                                               2875    2861     -14
edit_file                                            668     648     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 1/-53)             Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohush: fix "wait -n" to wait for a _job_, not a _process_
Denys Vlasenko [Wed, 27 Mar 2019 17:34:10 +0000 (18:34 +0100)]
hush: fix "wait -n" to wait for a _job_, not a _process_

function                                             old     new   delta
checkjobs                                            163     183     +20
process_wait_result                                  449     463     +14
leave_var_nest_level                                  98     107      +9
enter_var_nest_level                                  32      38      +6
set_vars_and_save_old                                147     150      +3
builtin_local                                         53      56      +3
builtin_wait                                         322     323      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 56/0)               Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoash: add "wait -n" bashism
Denys Vlasenko [Wed, 27 Mar 2019 14:51:42 +0000 (15:51 +0100)]
ash: add "wait -n" bashism

function                                             old     new   delta
waitcmd                                              205     288     +83
dowait                                               405     444     +39
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 122/0)             Total: 122 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agontpd: do not create pid file if not backgrounded
Denys Vlasenko [Wed, 27 Mar 2019 12:37:40 +0000 (13:37 +0100)]
ntpd: do not create pid file if not backgrounded

function                                             old     new   delta
ntp_init                                             995    1021     +26
ntpd_main                                           1267    1257     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 26/-10)             Total: 16 bytes

Reported by Alfonso Ranieri <alforan@tin.it>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agohush: add "wait -n" bashism
Denys Vlasenko [Tue, 26 Mar 2019 17:34:06 +0000 (18:34 +0100)]
hush: add "wait -n" bashism

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoman: don't skip default path which appears in config file
Ron Yorston [Fri, 22 Mar 2019 16:25:32 +0000 (16:25 +0000)]
man: don't skip default path which appears in config file

If the MANPATH environment variable isn't set a provisional default
path of /usr/man is placed in man_path_list.  This is only used if a
configuration file doesn't contain an alternative path.

If a configuration file lists the default path first:

   MANPATH /usr/man:/usr/share/man

add_MANPATH() sees that the default entry is already present and skips
it.  As a result man_path_list only contains the second and subsequent
components of the configured MANPATH.

In such cases the path should not be skipped.

function                                             old     new   delta
add_MANPATH                                          170     183     +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>
5 years agots: do call localtime() when neither -s nor -i specified
Denys Vlasenko [Tue, 26 Mar 2019 10:51:21 +0000 (11:51 +0100)]
ts: do call localtime() when neither -s nor -i specified

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agots: use gettimeofday - we don't use nanoseconds here
Denys Vlasenko [Tue, 26 Mar 2019 10:44:48 +0000 (11:44 +0100)]
ts: use gettimeofday - we don't use nanoseconds here

function                                             old     new   delta
ts_main                                              398     376     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agots: replace overlapping strcpy with shorter code
Denys Vlasenko [Tue, 26 Mar 2019 10:41:35 +0000 (11:41 +0100)]
ts: replace overlapping strcpy with shorter code

function                                             old     new   delta
ts_main                                              401     398      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agots: fix incorrect (copy-pasted) copyright attribution
Denys Vlasenko [Tue, 26 Mar 2019 10:12:15 +0000 (11:12 +0100)]
ts: fix incorrect (copy-pasted) copyright attribution

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agots: new applet
Denys Vlasenko [Tue, 26 Mar 2019 10:02:31 +0000 (11:02 +0100)]
ts: new applet

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agodo not duplicate CONFIG_PID_FILE_PATH and ".pid" strings
Denys Vlasenko [Sun, 17 Mar 2019 18:47:52 +0000 (19:47 +0100)]
do not duplicate CONFIG_PID_FILE_PATH and ".pid" strings

   text    data     bss     dec     hex filename
 981737     485    7296  989518   f194e busybox_old
 981704     485    7296  989485   f192d busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoFix off by one error in FAT16 <=> FAT32 detection
Thomas Frauendorfer [Tue, 5 Mar 2019 16:04:34 +0000 (17:04 +0100)]
Fix off by one error in FAT16 <=> FAT32 detection

cluster_count is compared against FAT16_MAX, which is defined as 0xfff4
That is the maximum number of cluster a FAT16 can have.

For reference also check the  hardware whitepaper from Microsoft
FAT: General Overview of On-Disk Format, version 1.03 page 15

Signed-off-by: Thomas Frauendorfer <tf@miray.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agowatch: support fractional -n SEC
Denys Vlasenko [Tue, 12 Mar 2019 17:56:51 +0000 (18:56 +0100)]
watch: support fractional -n SEC

function                                             old     new   delta
watch_main                                           212     232     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoxargs: mention -E STR in --help
Denys Vlasenko [Sun, 10 Mar 2019 13:29:03 +0000 (14:29 +0100)]
xargs: mention -E STR in --help

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoscripts/echo.c: resolve implicit declaration of function 'dup2'
Nicolas Hüppelshäuser [Tue, 5 Mar 2019 10:54:23 +0000 (11:54 +0100)]
scripts/echo.c: resolve implicit declaration of function 'dup2'

Signed-off-by: Nicolas Hüppelshäuser <nicolas.hueppelshaeuser@emlix.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agotop: tweak --help
Denys Vlasenko [Wed, 27 Feb 2019 15:45:39 +0000 (16:45 +0100)]
top: tweak --help

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoudhcpc: don't exit after backgrounding on -n -b
Andrey Mazo [Fri, 22 Feb 2019 21:46:19 +0000 (16:46 -0500)]
udhcpc: don't exit after backgrounding on -n -b

Currently, running "udhcpc -n -b" causes udhcpc to go to background and
then exit after some time unless a lease is obtained.

It's not very useful to do so
as the calling process doesn't know
if the lease was obtained or not anyway.

The code actually tries to favor "-b" over "-n",
but doesn't clear "-n" flag while clearing "-b" after backgrounding.

So, clear "-n" flag after going into background.
This effectively makes "-b" override "-n" completely
and "-n -b" behave the same as "-b".

This allows to override default "-n" option, passed to udhcpc by ifupdown,
without recompiling busybox.

URL: https://bugs.busybox.net/11691

Signed-off-by: Andrey Mazo <ahippo@yandex.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoudhcpc: tweak --help
Denys Vlasenko [Wed, 27 Feb 2019 07:17:07 +0000 (08:17 +0100)]
udhcpc: tweak --help

function                                             old     new   delta
packed_usage                                       33324   33315      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoash: eval: avoid leaking memory associated with redirections. Closes 7748
Ron Yorston [Mon, 25 Feb 2019 08:29:38 +0000 (08:29 +0000)]
ash: eval: avoid leaking memory associated with redirections. Closes 7748

The following constructs result in ever-increasing memory usage:

   while true; do { true; } </dev/null; done
   while true; do ( true; ) </dev/null; done

For comparison, bash displays static memory usage in both cases.

This has been fixed in dash by commit 2bc6caa.  The maintainer
writes:

   I have simplified evaltree so that it simply sets the stack mark
   unconditionally.  This allows us to remove the stack marks in the
   functions called by evaltree.

Closes BusyBox bug 7748.

function                                             old     new   delta
evaltree                                             606     632     +26
evalcommand                                         1724    1696     -28
evalcase                                             382     351     -31
evalfor                                              230     196     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 26/-93)            Total: -67 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agodu: don't count duplicate arguments. Closes 5288
Ron Yorston [Sat, 16 Feb 2019 10:22:31 +0000 (10:22 +0000)]
du: don't count duplicate arguments. Closes 5288

Since coreutils 8.6 (2010-10-15) du no longer counts duplicate arguments.

Revert the relevant part of commit 618a3027ed (du: fix "du /dir /dir"
case).

function                                             old     new   delta
du_main                                              302     297      -5
reset_ino_dev_hashtable                               78       -     -78
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-83)             Total: -83 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agontpd: increase SLEW_THRESHOLD from 0.125 to 0.5
Denys Vlasenko [Fri, 15 Feb 2019 13:32:08 +0000 (14:32 +0100)]
ntpd: increase SLEW_THRESHOLD from 0.125 to 0.5

Linux kernel supports it since ~2006

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agodd: add 'oflag=append'
Rostislav Skudnov [Wed, 6 Feb 2019 11:57:15 +0000 (11:57 +0000)]
dd: add 'oflag=append'

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoi2c_tools.c: i2ctransfer
Nikolaus Voss [Mon, 11 Feb 2019 10:30:52 +0000 (11:30 +0100)]
i2c_tools.c: i2ctransfer

Call i2c_set_slave_addr() unconditionally as busy checking
is skipped depending on force argument.
Clarify usage texts for -f and -a flags.

Signed-off-by: Nikolaus Voss <nv@vosn.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: further fixes to undo after autoindent
Ron Yorston [Mon, 11 Feb 2019 08:29:15 +0000 (08:29 +0000)]
vi: further fixes to undo after autoindent

Commit bb983f30e (vi: fix faulty undo after autoinsert) has a
number of problems:

- The commit message refers to 'autoinsert' when it really means
  'autoindent'.

- The indentation of undo_push_insert() was incorrect.

- Most seriously the commit only fixed the problem for cases where
  the indentation was exactly one character.  This is because undo_push()
  only allows single characters to be queued for UNDO_INS_QUEUED.

  Lifting this restriction allows the example given in the previous
  commit message (with a three character indent) to work.

function                                             old     new   delta
undo_push                                            406     435     +29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 29/0)               Total: 29 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoi2ctransfer: new applet
Nikolaus Voss [Sun, 10 Feb 2019 18:56:41 +0000 (19:56 +0100)]
i2ctransfer: new applet

i2ctransfer sends and receives user defined i2c messages

v2: apply Xabier's comments: add -a option, don't decrement argc,
    use bb_show_usage() and xzalloc()
v3: fix possible out of bound access to msgs[nmsgs]

Reviewed-by: Xabier Oneca -- xOneca <xoneca@gmail.com>
Signed-off-by: Nikolaus Voss <nikolaus.voss@loewensteinmedical.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agosysctl: fix compatibility with procps sysctl
Aaro Koskinen [Fri, 8 Feb 2019 15:30:24 +0000 (16:30 +0100)]
sysctl: fix compatibility with procps sysctl

Busybox sysctl is incompatible with procps when '.' appears in
directory name, mostly happens with VLANs.

        busybox syntax (since 2008): net.ipv4.conf.eth0.100.mc_forwarding
         procps syntax (since 2002): net.ipv4.conf.eth0/100.mc_forwarding
                 (supported by both: net/ipv4/conf/eth0.100/mc_forwarding)

Use procps syntax for output; for input, allow both.

function                                             old     new   delta
sysctl_dots_to_slashes                                86     143     +57
sysctl_act_on_setting                                443     453     +10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 67/0)               Total: 67 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agosysctl: do slash/dot conversions only on name, not value part
Denys Vlasenko [Fri, 8 Feb 2019 15:02:39 +0000 (16:02 +0100)]
sysctl: do slash/dot conversions only on name, not value part

function                                             old     new   delta
sysctl_dots_to_slashes                                71      86     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agosysctl: on EIO ("sysctl net.ipv6.conf.all.stable_secret") set nonzero exitcode
Denys Vlasenko [Fri, 8 Feb 2019 13:59:06 +0000 (14:59 +0100)]
sysctl: on EIO ("sysctl net.ipv6.conf.all.stable_secret") set nonzero exitcode

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agosysctl: avoid stat() on every item if in -w mode
Denys Vlasenko [Fri, 8 Feb 2019 13:27:21 +0000 (14:27 +0100)]
sysctl: avoid stat() on every item if in -w mode

function                                             old     new   delta
sysctl_act_recursive                                 163     167      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agosysctl: allow setting empty values
Denys Vlasenko [Fri, 8 Feb 2019 13:02:59 +0000 (14:02 +0100)]
sysctl: allow setting empty values

function                                             old     new   delta
sysctl_act_on_setting                                451     445      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: fix replacement of single character with CR
Ron Yorston [Sun, 3 Feb 2019 14:01:58 +0000 (14:01 +0000)]
vi: fix replacement of single character with CR

Currently if the 'r' command is followed by a carriage return a
literal CR replaces the current character.

Fix this so that:

- a new line is inserted
- the autoindent setting is respected
- the cursor is placed at the start of the new line

function                                             old     new   delta
do_cmd                                              5052    5060      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agovi: fix faulty undo after autoinsert
Ron Yorston [Sun, 3 Feb 2019 10:13:17 +0000 (10:13 +0000)]
vi: fix faulty undo after autoinsert

Enable autoinsert and enter the following with an indent of three
spaces:

   line 1
   line 2

Using 'u' to undo the last insert results in:

   line1e 2

The insertion of the indent hasn't been properly recorded.

Since recording insertions is a common operation add a convenience
function, undo_push_insert(), to handle this and use it to record
the autoindent correctly.

function                                             old     new   delta
undo_push_insert                                       -      36     +36
string_insert                                        133     129      -4
char_insert                                          518     473     -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 36/-49)            Total: -13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agochcon: Fix typo in ACTION_RECURSE
Rostislav Skudnov [Wed, 6 Feb 2019 11:57:29 +0000 (11:57 +0000)]
chcon: Fix typo in ACTION_RECURSE

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agodhcp service example: rewrite "private network to mask" as case statement
Denys Vlasenko [Fri, 8 Feb 2019 09:37:05 +0000 (10:37 +0100)]
dhcp service example: rewrite "private network to mask" as case statement

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agodhcp service example: cater for servers hot giving subnet and/or router
Denys Vlasenko [Tue, 5 Feb 2019 16:48:24 +0000 (17:48 +0100)]
dhcp service example: cater for servers hot giving subnet and/or router

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agolineedit: fix SEGV in isk, hexedit, ed, closes 11661
Denys Vlasenko [Mon, 4 Feb 2019 15:16:30 +0000 (16:16 +0100)]
lineedit: fix SEGV in isk, hexedit, ed, closes 11661

fdisk, hexedit and ed calls read_line_edit in libbb/lineedit.c with NULL
as first argument. On line 2373 of lineedit.c of busybox version 1.29.3,
state->hist_file is referenced without checking the state->flag.

This causes segmentation fault on fdisk, hexedit and ed on ARM Cortex-A9.
It somehow works on x86_64.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoservice examples: do not respawn supplicant too often
Denys Vlasenko [Sat, 2 Feb 2019 18:06:19 +0000 (19:06 +0100)]
service examples: do not respawn supplicant too often

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agogrep: short-circuit -v to bail out on first match
Ari Sundholm [Mon, 28 Jan 2019 17:41:12 +0000 (19:41 +0200)]
grep: short-circuit -v to bail out on first match

A small optimization. There is no need to try matching the current
input line against any further patterns if a match was already
found and -v is specified.

function                                             old     new   delta
grep_file                                           1463    1440     -23

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Niko Vähäsarja <niko@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agogrep: fix -x -v with certain pattern orders
Ari Sundholm [Tue, 29 Jan 2019 13:42:57 +0000 (14:42 +0100)]
grep: fix -x -v with certain pattern orders

We found out that busybox -x -v is a bit broken:

ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e 'aa.*' -e '.*bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e 'aa.*' -e '.*bb.*'
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e '.*aa.*' -e 'bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e '.*aa.*' -e 'bb.*'
  aa bb cc

Last one is wrong.

This patch fixes the issue by making sure that the variable 'found'
never makes a transition from 1 to 0, as this would mean that
grep previously found a match on this input line.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Niko Vähäsarja <niko@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agobc: implement pass-by-reference code from upstream
Denys Vlasenko [Fri, 25 Jan 2019 13:24:03 +0000 (14:24 +0100)]
bc: implement pass-by-reference code from upstream

function                                             old     new   delta
zxc_program_popResultAndCopyToVar                    298     493    +195
bc_vec_pushIndex                                       -      75     +75
zxc_vm_process                                       859     928     +69
xc_program_dereference                                 -      66     +66
bc_vec_npush                                           -      65     +65
zbc_num_s                                            239     249     +10
zxc_program_num                                     1024    1032      +8
zbc_num_divmod                                       150     156      +6
xc_program_search                                    143     146      +3
zxc_program_assign                                   392     389      -3
zdc_program_execStr                                  520     517      -3
xc_program_pushVar                                   198     195      -3
zxc_program_exec                                    4101    4092      -9
zbc_program_call                                     318     308     -10
zbc_func_insert                                      120     104     -16
zbc_parse_stmt_possibly_auto                        1460    1439     -21
bc_vec_push                                           53      12     -41
xc_parse_pushIndex                                    61      18     -43
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 6/9 up/down: 497/-149)          Total: 348 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agologin: close PAM session on errors as well, not only on success
Denys Vlasenko [Tue, 22 Jan 2019 16:00:14 +0000 (17:00 +0100)]
login: close PAM session on errors as well, not only on success

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
5 years agoip link: Fix vlan proto, closes 8261 and 11638
Bernhard Reutner-Fischer [Tue, 22 Jan 2019 10:11:15 +0000 (11:11 +0100)]
ip link: Fix vlan proto, closes 8261 and 11638

The proto has to be passed in network byte-order.
While at it allow for
 ip link add link eth0 name eth0.2.24 type vlan proto 802.1ad id 24
 ip link del link eth0 name eth0.2.24 type vlan proto 802.1ad id 24
The del was lacking a dev_str and thus errored out. Fix by using
name/dev counterpart as fallback.

The proto identifier 802.1Q was not recognized, just it's lowercase
variant, fix that too.

function                                             old     new   delta
do_add_or_delete                                    1275    1376    +101
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 101/0)             Total: 101 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
5 years agoip link: fix mismatched enums in vlan_parse_opt(), closes 11631
Denys Vlasenko [Tue, 22 Jan 2019 09:07:50 +0000 (10:07 +0100)]
ip link: fix mismatched enums in vlan_parse_opt(), closes 11631

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>