oweals/busybox.git
7 years agorandomconfig fixes
Denys Vlasenko [Mon, 12 Dec 2016 08:26:16 +0000 (09:26 +0100)]
randomconfig fixes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agorandomconfig fixes
Denys Vlasenko [Sat, 10 Dec 2016 19:57:00 +0000 (20:57 +0100)]
randomconfig fixes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoselinux: drop deprecated headers
Mike Frysinger [Fri, 9 Dec 2016 23:30:30 +0000 (18:30 -0500)]
selinux: drop deprecated headers

The selinux guys want you to get class values at runtime by converting
textual names into constants.  Drop the deprecated headers and switch
to the new format.

This API has been around for years, so there shouldn't be an issue
with backwards compatibility.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
7 years agosetfiles: fix build failure after common_bufsiz change
Mike Frysinger [Fri, 9 Dec 2016 23:14:12 +0000 (18:14 -0500)]
setfiles: fix build failure after common_bufsiz change

Commit 47cfbf32fd66563f8c4e09ad6cced6abfbe2fad5 ("*: add most of the
required setup_common_bufsiz() calls") switched this tool over to use
the common_bufsiz logic but missed including the header leading to a
build failure when enabled:
selinux/setfiles.c:80:30: error: 'bb_common_bufsiz1' undeclared (first use in this function)

URL: https://bugs.gentoo.org/600106
Reported-by: Jonas Jelten <jj@stusta.net>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
7 years agomdev.conf: rename hw_random to hwrng
Mike Frysinger [Fri, 9 Dec 2016 21:12:15 +0000 (16:12 -0500)]
mdev.conf: rename hw_random to hwrng

The kernel broke the name years ago, but didn't notice until it was much
too late.  Rename the node to match expectations of userland software,
and what the kernel itself documents in its Kconfig help:
This provides a device that's usually called /dev/hwrng, ...

URL: https://marc.info/?l=linux-crypto-vger&m=144249767024990&w=2
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
7 years agorandomconfig fixes
Denys Vlasenko [Thu, 8 Dec 2016 11:24:48 +0000 (12:24 +0100)]
randomconfig fixes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agosvc: new applet (daemontools-compatible version of "sv")
Denys Vlasenko [Mon, 5 Dec 2016 12:56:40 +0000 (13:56 +0100)]
svc: new applet (daemontools-compatible version of "sv")

function                                             old     new   delta
sv                                                     -    1199   +1199
svc_main                                               -     145    +145
packed_usage                                       30255   30364    +109
applet_names                                        2437    2441      +4
applet_main                                         1420    1424      +4
find_applet_by_name                                  125     126      +1
sv_main                                             1201       9   -1192
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 1462/-1192)        Total: 270 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agofix musl problem with dirname, now for all users of bb_make_directory()
Denys Vlasenko [Sun, 4 Dec 2016 09:42:07 +0000 (10:42 +0100)]
fix musl problem with dirname, now for all users of bb_make_directory()

function                                             old     new   delta
bb_make_directory                                    412     419      +7
install_main                                         793     769     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-24)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoREADME_distro_proposal.txt: writeup about runit adoption
Denys Vlasenko [Sat, 3 Dec 2016 13:06:55 +0000 (14:06 +0100)]
README_distro_proposal.txt: writeup about runit adoption

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agotop: fix help text: with !TERMIOS, no keys are affected top output
Denys Vlasenko [Sat, 3 Dec 2016 11:09:50 +0000 (12:09 +0100)]
top: fix help text: with !TERMIOS, no keys are affected top output

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoinstall: fix musl problem with dirname
Denys Vlasenko [Sat, 3 Dec 2016 10:49:23 +0000 (11:49 +0100)]
install: fix musl problem with dirname

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoDo not print useless empty line after list of applets
Denys Vlasenko [Mon, 28 Nov 2016 00:29:28 +0000 (01:29 +0100)]
Do not print useless empty line after list of applets

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoCode style fixes, no code changes
Denys Vlasenko [Mon, 28 Nov 2016 00:22:57 +0000 (01:22 +0100)]
Code style fixes, no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agolineedit: simplify code a bit
Denys Vlasenko [Mon, 28 Nov 2016 00:10:16 +0000 (01:10 +0100)]
lineedit: simplify code a bit

function                                             old     new   delta
lineedit_read_key                                    155     162      +7
put_prompt                                            51      46      -5
read_line_input                                     3722    3715      -7
cmdedit_setwidth                                      81      50     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 7/-43)             Total: -36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agomakedevs: make special node creation idempotent
Denys Vlasenko [Sun, 27 Nov 2016 22:27:54 +0000 (23:27 +0100)]
makedevs: make special node creation idempotent

When makedevs is called for a second time with the same device file,
it fails because the files already exist and mknod() gives -EEXIST.

Ignore EEXIST errors.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agolineedit: fix two bugs in SIGWINCH signal handling
Denys Vlasenko [Sun, 27 Nov 2016 21:25:07 +0000 (22:25 +0100)]
lineedit: fix two bugs in SIGWINCH signal handling

(1) restore entire sigaction, not only signal handler function
(2) do not use stdio when not sure WINCH did not interrupt a printf() or such.

function                                             old     new   delta
cmdedit_setwidth                                       -      81     +81
read_line_input                                     3682    3722     +40
lineedit_read_key                                    138     155     +17
put_prompt                                            55      51      -4
win_changed                                           93      47     -46
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 138/-50)            Total: 88 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agofdisk_gpt: simplify GPT partition name printing
Denys Vlasenko [Sun, 27 Nov 2016 19:47:01 +0000 (20:47 +0100)]
fdisk_gpt: simplify GPT partition name printing

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agofdisk: sanitize partition name printing; drop "Code" column; get rid of one static var
Denys Vlasenko [Sun, 27 Nov 2016 05:13:43 +0000 (06:13 +0100)]
fdisk: sanitize partition name printing; drop "Code" column; get rid of one static var

function                                             old     new   delta
list_table                                          2335    2373     +38
fill_bounds                                          131     128      -3
part_array_len                                         4       -      -4
get_boot                                            1584    1574     -10
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 38/-17)             Total: 21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agodpkg-deb: shorten code, improve help text
Denys Vlasenko [Sun, 27 Nov 2016 03:48:53 +0000 (04:48 +0100)]
dpkg-deb: shorten code, improve help text

function                                             old     new   delta
packed_usage                                       30261   30236     -25
dpkg_deb_main                                        437     401     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-61)             Total: -61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agodpkg-deb: remove unused FEATURE_DPKG_DEB_EXTRACT_ONLY config option
Denys Vlasenko [Sun, 27 Nov 2016 02:57:08 +0000 (03:57 +0100)]
dpkg-deb: remove unused FEATURE_DPKG_DEB_EXTRACT_ONLY config option

Its usage in C code was removed in 2004.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agofind: fix handling of trailing slashes in -name PATTERN comparisons
Denys Vlasenko [Fri, 25 Nov 2016 19:14:33 +0000 (20:14 +0100)]
find: fix handling of trailing slashes in -name PATTERN comparisons

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash,hush: make ^C in interactive mode visually much closer to bash behavior
Denys Vlasenko [Fri, 25 Nov 2016 02:41:03 +0000 (03:41 +0100)]
ash,hush: make ^C in interactive mode visually much closer to bash behavior

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMove FEATURE_BUFFERS_USE_foo options to library tuning
Denys Vlasenko [Thu, 24 Nov 2016 21:30:52 +0000 (22:30 +0100)]
Move FEATURE_BUFFERS_USE_foo options to library tuning

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMove locale, unicode, and "use sendfile?" options to library tuning
Denys Vlasenko [Thu, 24 Nov 2016 21:18:55 +0000 (22:18 +0100)]
Move locale, unicode, and "use sendfile?" options to library tuning

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoCollapse three levers of menuconfig to two levels.
Denys Vlasenko [Thu, 24 Nov 2016 21:08:12 +0000 (22:08 +0100)]
Collapse three levers of menuconfig to two levels.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash,hush: ^C from command line should set $? to 128+SIGINT
Denys Vlasenko [Thu, 24 Nov 2016 16:44:02 +0000 (17:44 +0100)]
ash,hush: ^C from command line should set $? to 128+SIGINT

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agolineedit: fix handling of repeating Alt-b, Alt-f, Alt-d, Alt-Backspace
Rostislav Skudnov [Thu, 24 Nov 2016 14:04:00 +0000 (15:04 +0100)]
lineedit: fix handling of repeating Alt-b, Alt-f, Alt-d, Alt-Backspace

These key combinations should repeat correctly when the keys are
pressed and held.

Before this change, they do this erratically - many repeats are "eaten"
because they are treated as unrecognized ESC seqs:
ESC 0x7f is treated by Alt+baskspace, but ESC 0x7f ESC 0x7f ESC 0x7f
is unrecognized.

Escape sequences corresponding to these key combinations are moved from
read_line_input to lineedit_read_key.

Also, these key sequences are now enabled regardless of whether
FEATURE_EDITING_VI is set, since Vim does not actually support these key
combinations, but they are present in readline library.

function                                             old     new   delta
static.esccmds                                        93     103     +10
read_line_input                                     3737    3687     -50

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agopatch: fix matching failure
Aaro Koskinen [Mon, 21 Nov 2016 22:19:51 +0000 (00:19 +0200)]
patch: fix matching failure

Fix matching failure when plist is advanced while checking for buffered
lines - the lines in the hunk that are about to be added should be
skipped when checking for matching context.

Also add a valid test case that fails with current busybox and is fixed
by the change.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agopatch: fix debug log failure
Aaro Koskinen [Mon, 21 Nov 2016 22:19:50 +0000 (00:19 +0200)]
patch: fix debug log failure

If we reach the end of plist it means the input has still data while we
are expecting EOF. Fix the log to avoid a crash.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoRemove outdated comments
Denys Vlasenko [Wed, 23 Nov 2016 20:51:11 +0000 (21:51 +0100)]
Remove outdated comments

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all udhcp applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 17:54:59 +0000 (18:54 +0100)]
Convert all udhcp applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all selinux/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 17:46:40 +0000 (18:46 +0100)]
Convert all selinux/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agotest: make [ and [[ forms individually selectable
Denys Vlasenko [Wed, 23 Nov 2016 17:31:48 +0000 (18:31 +0100)]
test: make [ and [[ forms individually selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoRemove remnants of disabled "length" applet
Denys Vlasenko [Wed, 23 Nov 2016 13:54:38 +0000 (14:54 +0100)]
Remove remnants of disabled "length" applet

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake dos2unix/unix2dos independently selectable
Denys Vlasenko [Wed, 23 Nov 2016 13:52:19 +0000 (14:52 +0100)]
Make dos2unix/unix2dos independently selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all coreutils/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 13:46:56 +0000 (14:46 +0100)]
Convert all coreutils/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake "hd" independently selectable
Denys Vlasenko [Wed, 23 Nov 2016 10:53:12 +0000 (11:53 +0100)]
Make "hd" independently selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all util-linux/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 10:46:32 +0000 (11:46 +0100)]
Convert all util-linux/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoRemove trailing empty lines
Denys Vlasenko [Wed, 23 Nov 2016 09:43:39 +0000 (10:43 +0100)]
Remove trailing empty lines

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all console-tools/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 09:39:27 +0000 (10:39 +0100)]
Convert all console-tools/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all mailutils/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 08:58:03 +0000 (09:58 +0100)]
Convert all mailutils/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agotc: consolidate its disabled bits
Denys Vlasenko [Wed, 23 Nov 2016 08:51:33 +0000 (09:51 +0100)]
tc: consolidate its disabled bits

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake ping6 and traceroute6 selectable independently from ping/traceroute
Denys Vlasenko [Wed, 23 Nov 2016 08:25:57 +0000 (09:25 +0100)]
Make ping6 and traceroute6 selectable independently from ping/traceroute

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoipneigh: add this shortcur similar to other "ip <CMD>" shortcuts
Denys Vlasenko [Wed, 23 Nov 2016 08:18:05 +0000 (09:18 +0100)]
ipneigh: add this shortcur similar to other "ip <CMD>" shortcuts

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoRename FEATURE_FTP_WRITE and FEATURE_FTP_AUTHENTICATION to *_FTPD_*
Denys Vlasenko [Wed, 23 Nov 2016 08:07:44 +0000 (09:07 +0100)]
Rename FEATURE_FTP_WRITE and FEATURE_FTP_AUTHENTICATION to *_FTPD_*

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all networking/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 08:05:14 +0000 (09:05 +0100)]
Convert all networking/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all modutils/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 06:54:52 +0000 (07:54 +0100)]
Convert all modutils/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake killall and killall5 selecatable independent from kill
Denys Vlasenko [Wed, 23 Nov 2016 05:43:46 +0000 (06:43 +0100)]
Make killall and killall5 selecatable independent from kill

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all procps/* applets to "new style" applet definitions
Denys Vlasenko [Wed, 23 Nov 2016 05:23:44 +0000 (06:23 +0100)]
Convert all procps/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoConvert all miscutils/* applets to "new style" applet definitions
Denys Vlasenko [Tue, 22 Nov 2016 22:54:17 +0000 (23:54 +0100)]
Convert all miscutils/* applets to "new style" applet definitions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoSplit miscutils/Config.src items into miscutils/*.c files
Denys Vlasenko [Tue, 22 Nov 2016 22:14:24 +0000 (23:14 +0100)]
Split miscutils/Config.src items into miscutils/*.c files

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohttpd: explain why we use sprintf and why it should be fine
Denys Vlasenko [Tue, 22 Nov 2016 01:23:35 +0000 (02:23 +0100)]
httpd: explain why we use sprintf and why it should be fine

While at it, fix a pathological case where it is not fine:
-r REALM with some 8-kbyte long REALM would overflow the buffer.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoFix allnoconfig warnings
Denys Vlasenko [Fri, 18 Nov 2016 20:42:44 +0000 (21:42 +0100)]
Fix allnoconfig warnings

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoapplets.h.sh: a script to check applet names against config options
Denys Vlasenko [Thu, 17 Nov 2016 14:34:16 +0000 (15:34 +0100)]
applets.h.sh: a script to check applet names against config options

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake mkfs.vfat and mkdosfs individually selectable
Denys Vlasenko [Wed, 16 Nov 2016 15:18:50 +0000 (16:18 +0100)]
Make mkfs.vfat and mkdosfs individually selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake mke2fs and mkfs.ext2 individually selectable
Denys Vlasenko [Wed, 16 Nov 2016 15:12:11 +0000 (16:12 +0100)]
Make mke2fs and mkfs.ext2 individually selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake bzcat, lzcat, xzcat, zcat, lzopcat, unlzop individually selectable
Denys Vlasenko [Wed, 16 Nov 2016 14:45:05 +0000 (15:45 +0100)]
Make bzcat, lzcat, xzcat, zcat, lzopcat, unlzop individually selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake ifup and ifdown individually selectable.
Denys Vlasenko [Mon, 14 Nov 2016 17:31:07 +0000 (18:31 +0100)]
Make ifup and ifdown individually selectable.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake swapon and swapoff individually selectable.
Denys Vlasenko [Mon, 14 Nov 2016 16:30:50 +0000 (17:30 +0100)]
Make swapon and swapoff individually selectable.

For example, without swapoff, code shrinks by 277 bytes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake grep/egrep/fgrep independently selectable
Denys Vlasenko [Mon, 14 Nov 2016 04:09:48 +0000 (05:09 +0100)]
Make grep/egrep/fgrep independently selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake halt/poweroff/reboot independently selectable
Denys Vlasenko [Mon, 14 Nov 2016 03:55:04 +0000 (04:55 +0100)]
Make halt/poweroff/reboot independently selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoMake setarch/linux32/linux64 independently selectable
Denys Vlasenko [Sun, 13 Nov 2016 21:56:04 +0000 (22:56 +0100)]
Make setarch/linux32/linux64 independently selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agodnsdomainname: split it from "hostname", make it independently selectable
Denys Vlasenko [Sun, 13 Nov 2016 21:35:10 +0000 (22:35 +0100)]
dnsdomainname: split it from "hostname", make it independently selectable

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agotar: handle pax-encoded utf8 filenames and link names. Closes 9406
Denys Vlasenko [Fri, 11 Nov 2016 16:56:45 +0000 (17:56 +0100)]
tar: handle pax-encoded utf8 filenames and link names. Closes 9406

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: make getch/peek functions directly called
Denys Vlasenko [Tue, 8 Nov 2016 21:35:05 +0000 (22:35 +0100)]
hush: make getch/peek functions directly called

Indirect calls are more difficult to predict.
Unfortunately, on x64 direct call is 5 bytes while indirect "call (reg+ofs)"
is 3 bytes:

function                                             old     new   delta
i_getch                                                -      82     +82
i_peek                                                 -      63     +63
parse_stream                                        2531    2579     +48
parse_dollar                                         771     797     +26
parse_redirect                                       296     321     +25
add_till_closing_bracket                             408     420     +12
encode_string                                        256     265      +9
i_peek_and_eat_bkslash_nl                             93      99      +6
add_till_backquote                                   110     114      +4
parse_and_run_stream                                 139     141      +2
expand_vars_to_list                                 1143    1144      +1
static_peek                                            6       -      -6
setup_string_in_str                                   39      18     -21
setup_file_in_str                                     40      19     -21
static_get                                            27       -     -27
file_peek                                             52       -     -52
file_get                                              65       -     -65
------------------------------------------------------------------------------
(add/remove: 2/4 grow/shrink: 9/2 up/down: 278/-192)           Total: 86 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: renumber PIPE_foo, make PIPE_SEQ = 0
Denys Vlasenko [Tue, 8 Nov 2016 19:35:53 +0000 (20:35 +0100)]
hush: renumber PIPE_foo, make PIPE_SEQ = 0

PIPE_SEQ is used most often, having it zero makes code smaller:

function                                             old     new   delta
done_word                                            719     707     -12
parse_stream                                        2546    2531     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: small optimization in run_list
Denys Vlasenko [Tue, 8 Nov 2016 19:26:11 +0000 (20:26 +0100)]
hush: small optimization in run_list

I thought gcc can detect this itself. It doesn't.

function                                             old     new   delta
run_list                                            1030    1021      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: deindent large block of code, no code changes
Denys Vlasenko [Tue, 8 Nov 2016 16:34:44 +0000 (17:34 +0100)]
hush: deindent large block of code, no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: simplify insert_bg_jobs
Denys Vlasenko [Tue, 8 Nov 2016 16:28:45 +0000 (17:28 +0100)]
hush: simplify insert_bg_jobs

function                                             old     new   delta
insert_bg_job                                        366     281     -85

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: make "wait %1" less likely to play with signal mask
Denys Vlasenko [Tue, 8 Nov 2016 03:59:11 +0000 (04:59 +0100)]
hush: make "wait %1" less likely to play with signal mask

Was playing with "sleep 3 | exit 3 & wait %1" and noticed that often
SIGCHLD arrives even before I get to signal masking. Can avoid it in this
case.

function                                             old     new   delta
wait_for_child_or_signal                             228     265     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: rework "wait %jobspec" to work in non-interactive shells too
Denys Vlasenko [Mon, 7 Nov 2016 23:59:29 +0000 (00:59 +0100)]
hush: rework "wait %jobspec" to work in non-interactive shells too

Also add tests. wait5.tests so far fails (but works for ash and dash).

function                                             old     new   delta
builtin_wait                                         305     283     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: "wait $!; echo $?" should return 127 if $! already exited
Denys Vlasenko [Mon, 7 Nov 2016 22:07:21 +0000 (23:07 +0100)]
hush: "wait $!; echo $?" should return 127 if $! already exited

It would be nice to provide bash-like "remember las exitcode"
thingy, but it's a bit complex. For now, match ash and dash.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: implement "wait %jobspec"
Denys Vlasenko [Mon, 7 Nov 2016 21:12:18 +0000 (22:12 +0100)]
hush: implement "wait %jobspec"

function                                             old     new   delta
parse_jobspec                                          -      83     +83
job_exited_or_stopped                                  -      79     +79
builtin_wait                                         236     302     +66
wait_for_child_or_signal                             199     228     +29
checkjobs                                            142     158     +16
builtin_jobs                                          59      68      +9
process_wait_result                                  453     408     -45
builtin_fg_bg                                        272     203     -69
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/2 up/down: 282/-114)          Total: 168 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: factor out %jobspec parsing
Denys Vlasenko [Mon, 7 Nov 2016 19:06:40 +0000 (20:06 +0100)]
hush: factor out %jobspec parsing

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: comment fix
Denys Vlasenko [Mon, 7 Nov 2016 18:36:50 +0000 (19:36 +0100)]
hush: comment fix

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: do not allow sh -c '{ echo boo }'
Denys Vlasenko [Mon, 7 Nov 2016 15:22:35 +0000 (16:22 +0100)]
hush: do not allow sh -c '{ echo boo }'

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agocpio: add ownership (-R) test cases
Aaro Koskinen [Wed, 2 Nov 2016 22:25:05 +0000 (00:25 +0200)]
cpio: add ownership (-R) test cases

Add ownership (-R) test cases.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: case logic for setting $? was still wrong
Denys Vlasenko [Fri, 4 Nov 2016 19:14:04 +0000 (20:14 +0100)]
hush: case logic for setting $? was still wrong

Resetting to 0 should happen in "esac". Matched branch must
still see previous $?.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: non-matching "case" statement sets $? to 0
Denys Vlasenko [Fri, 4 Nov 2016 17:52:48 +0000 (18:52 +0100)]
hush: non-matching "case" statement sets $? to 0

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: allow { cmd } to not be terminated by semicolon in some cases
Denys Vlasenko [Fri, 4 Nov 2016 17:46:14 +0000 (18:46 +0100)]
hush: allow { cmd } to not be terminated by semicolon in some cases

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: fix "duplicate local" code (forgot to re-enable interrupts)
Denys Vlasenko [Fri, 4 Nov 2016 15:43:18 +0000 (16:43 +0100)]
ash: fix "duplicate local" code (forgot to re-enable interrupts)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agocomment and readme updates
Denys Vlasenko [Fri, 4 Nov 2016 13:13:58 +0000 (14:13 +0100)]
comment and readme updates

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agosu: expand help; simplify passing of -c CMD to run_shell()
Denys Vlasenko [Thu, 3 Nov 2016 21:13:08 +0000 (22:13 +0100)]
su: expand help; simplify passing of -c CMD to run_shell()

Also, added a comment about bug 9401 (TIOCSTI input injection).

function                                             old     new   delta
packed_usage                                       30909   30932     +23
su_main                                              470     487     +17
sulogin_main                                         260     258      -2
run_applet_and_exit                                  681     678      -3
run_shell                                            166     126     -40

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoloadfont: 32k size limit is not enough
Denys Vlasenko [Thu, 3 Nov 2016 19:57:37 +0000 (20:57 +0100)]
loadfont: 32k size limit is not enough

Since our "read to malloced buf" routines only gradually grow
allocations, let's be generous here and allow 128k.

Reported by Alex Henrie <alexhenrie24@gmail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: while (!got_sig) pause() is not reliable, use sigsuspend()
Denys Vlasenko [Thu, 3 Nov 2016 19:17:23 +0000 (20:17 +0100)]
ash: while (!got_sig) pause() is not reliable, use sigsuspend()

dash was doing it for a reason. Unfortunately, it had no comment why...
now I know.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoman: remove -Tascii from nroff invocation
Denys Vlasenko [Mon, 31 Oct 2016 13:05:34 +0000 (14:05 +0100)]
man: remove -Tascii from nroff invocation

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoman: make width selection more thorough; explain how to override it
Denys Vlasenko [Mon, 31 Oct 2016 00:52:18 +0000 (01:52 +0100)]
man: make width selection more thorough; explain how to override it

Fedora's "man CMD >file" still uses terminal width, not 80 (but disables formatting),
this change mimics that.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoman: allow nroff and tbl commands be overridden; unmangle writing to files
Denys Vlasenko [Sun, 30 Oct 2016 21:31:30 +0000 (22:31 +0100)]
man: allow nroff and tbl commands be overridden; unmangle writing to files

Parse this in config files:
 DEFINE col ...
 DEFINE tbl ...
 DEFINE nroff ...
Add width options to nroff command line.
Use "tbl", not "gtbl", as default tbl command.
Export GROFF_NO_SGR=1 and use "col -b -p -x" instead of pager when writing to file.

function                                             old     new   delta
man_main                                             735     863    +128
if_redefined                                           -      64     +64
show_manpage                                         199     169     -30
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 192/-30)           Total: 162 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: if using libc glob(), skip it if no metachars are in word
Denys Vlasenko [Sun, 30 Oct 2016 17:41:01 +0000 (18:41 +0100)]
ash: if using libc glob(), skip it if no metachars are in word

This saves making tons of pointless stat() calls

function                                             old     new   delta
expandarg                                            888     921     +33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: fix bit-rotten debug infrastructure
Denys Vlasenko [Sun, 30 Oct 2016 17:30:29 +0000 (18:30 +0100)]
ash: fix bit-rotten debug infrastructure

DEBUG = 2 output was a bit messed up

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: make popfile() anfter popallfiles() safe
Denys Vlasenko [Sun, 30 Oct 2016 17:27:14 +0000 (18:27 +0100)]
ash: make popfile() anfter popallfiles() safe

In this example:

ash -c 'readonly x; echo $(command eval x=2)'

evalstring() is called after forkchild(), which calls popallfiles().
On exception, evalstring() will popfile().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: fix "(sleep 1; exit 3) & sleep 2; echo $?; wait $!; echo $?"
Denys Vlasenko [Fri, 28 Oct 2016 20:39:12 +0000 (22:39 +0200)]
hush: fix "(sleep 1; exit 3) & sleep 2; echo $?; wait $!; echo $?"

"wait $!" may be just a bit too late: backgrounded $! is gone.
Do not bomb out in this case.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agohush: fix "wait PID"
Denys Vlasenko [Fri, 28 Oct 2016 19:57:31 +0000 (21:57 +0200)]
hush: fix "wait PID"

It was not properly interruptible, and did not update job status
(the exited processes were still thought of as running).

function                                             old     new   delta
process_wait_result                                    -     453    +453
wait_for_child_or_signal                               -     199    +199
run_list                                             996    1002      +6
checkjobs_and_fg_shell                                41      43      +2
builtin_wait                                         328     215    -113
checkjobs                                            516     142    -374
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/2 up/down: 660/-487)          Total: 173 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: use pause(), not sigsuspend(), in wait builtin
Denys Vlasenko [Fri, 28 Oct 2016 15:16:11 +0000 (17:16 +0200)]
ash: use pause(), not sigsuspend(), in wait builtin

Same effect, smaller code

function                                             old     new   delta
dowait                                               463     374     -89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: fix interactive "command eval STRING" exiting on errors.
Denys Vlasenko [Fri, 28 Oct 2016 13:43:50 +0000 (15:43 +0200)]
ash: fix interactive "command eval STRING" exiting on errors.

This bug is also present in current dash

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: [JOBS] Fix dowait signal race
Denys Vlasenko [Thu, 27 Oct 2016 21:51:19 +0000 (23:51 +0200)]
ash: [JOBS] Fix dowait signal race

Upstream commit:

    Date: Sun, 22 Feb 2009 18:10:01 +0800
    [JOBS] Fix dowait signal race

    This test program by Alexey Gladkov can cause dash to enter an
    infinite loop in waitcmd.

    #!/bin/dash
    trap "echo TRAP" USR1
    stub() {
        echo ">>> STUB $1" >&2
        sleep $1
        echo "<<< STUB $1" >&2
        kill -USR1 $$
    }
    stub 3 &
    stub 2 &
    until { echo "###"; wait; } do
    echo "*** $?"
    done

    The problem is that if we get a signal after the wait3 system
    call has returned but before we get to INTON in dowait, then
    we can jump back up to the top and lose the exit status.  So
    if we then wait for the job that has just exited, then it'll
    stay there forever.

    I made the original change that caused this bug to fix pretty
    much the same bug but in the opposite direction.  That is, if
    we get a signal after we enter wait3 but before we hit the kernel
    then it too can cause the wait to go on forever (assuming the
    child doesn't exit).

    In fact this is pretty much exactly the scenario that you'll
    find in glibc's documentation on pause().  The solution is given
    there too, in the form of sigsuspend, which is the only way to
    do the check and wait atomically.

    So this patch fixes Alexey's race without reintroducing the old
    bug by converting the blocking wait3 to a sigsuspend.

    In order to do this we need to set a signal handler for SIGCHLD,
    so the code has been modified to always do that.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
I failed to reproduce the bug (it requires precise timing), but it seems real.

function                                             old     new   delta
dowait                                               284     463    +179
setsignal                                            301     326     +25
signal_handler                                        59      76     +17
ash_main                                            1481    1487      +6
localcmd                                             350     348      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 227/-2)            Total: 225 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: [SIGNAL] Remove EXSIG
Denys Vlasenko [Thu, 27 Oct 2016 19:09:01 +0000 (21:09 +0200)]
ash: [SIGNAL] Remove EXSIG

Upstream commit 1:

    Date: Sun, 22 Feb 2009 18:16:13 +0800
    [SIGNAL] Remove EXSIG

    Now that waitcmd no longer uses EXSIG we can remove it.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 2:

    Date: Thu, 2 Oct 2014 21:07:55 +0800
    [ERROR] Set exitstatus in onint

    Currently the exit status when we receive SIGINT is set in evalcommand
    which means that it doesn't always get set.  For example, if you press
    CTRL-C at the prompt of an interactive dash, the exit status is not
    set to 130 as it is in many other Bourne shells.

    This patch fixes this by moving the setting of the exit status into
    onint which also simplifies evalcommand.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 3:

    Date: Fri, 3 Oct 2014 14:07:07 +0800
    [EVAL] Do not clobber exitstatus in evalcommand

    All originators of EXERROR have been setting the exitstatus for
    a while now.  So it is no longer appropriate to set it explicitly
    in evalcommand.

    In fact doing so may cause the original exitstatus to be lost.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Last three coomits:
function                                             old     new   delta
waitcmd                                              186     224     +38
dowait                                               276     284      +8
waitforjob                                           104     107      +3
localcmd                                             348     350      +2
showjobs                                              64      61      -3
forkshell                                            263     260      -3
raise_interrupt                                       93      67     -26
blocking_wait_with_raise_on_sig                       40       -     -40
evalcommand                                         1264    1208     -56
evaltree                                             809     498    -311

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: open-code blocking_dowait_with_raise_on_sig()
Denys Vlasenko [Thu, 27 Oct 2016 18:18:18 +0000 (20:18 +0200)]
ash: open-code blocking_dowait_with_raise_on_sig()

There is in fact only one callsite.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: return to DOWAIT_* constants similar to dash, no logic changes
Denys Vlasenko [Thu, 27 Oct 2016 18:08:28 +0000 (20:08 +0200)]
ash: return to DOWAIT_* constants similar to dash, no logic changes

This loses an insignificant optimization, but may allow backporting
of some recent-ish dash fixes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
7 years agoash: delete leftovers from "simplify EOF/newline handling in list parser" commit
Denys Vlasenko [Thu, 27 Oct 2016 12:49:21 +0000 (14:49 +0200)]
ash: delete leftovers from "simplify EOF/newline handling in list parser" commit

This commit should have deleted these two statements:

    commit c0e007663d30f83b0e5e074db34dcffaa8915e99
    Author: Ron Yorston <rmy@pobox.com>
    Date:   Thu Oct 29 11:30:55 2015 +0000
    ash: simplify EOF/newline handling in list parser

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