Denys Vlasenko [Sun, 6 Aug 2017 16:56:25 +0000 (18:56 +0200)]
setconsole: make it NOEXEC
BTW, I failed to make it do what it meant to do.
ioctl appears to succeed, but kernel's output is not coming
to the specified console (tried on VT consoles too).
OTOH, setlogcons does work...
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 16:54:16 +0000 (18:54 +0200)]
setconsole: since SUSE version has no -r, nuke our --reset longopt
Why we even bother inventing incompatible longopts?!
function old new delta
packed_usage 31734 31738 +4
static.setconsole_longopts 9 - -9
setconsole_main 94 84 -10
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 4/-19) Total: -15 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 16:29:25 +0000 (18:29 +0200)]
setkeycodes: make it NOEXEC, better --help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 16:17:58 +0000 (18:17 +0200)]
setlogcons: make it NOEXEC, better --help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 16:06:46 +0000 (18:06 +0200)]
setserial: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 15:59:37 +0000 (17:59 +0200)]
setserial: code shrink, better --help text
function old new delta
packed_usage 31747 31749 +2
setserial_main 1152 1132 -20
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 15:14:09 +0000 (17:14 +0200)]
slattach: code shrink, better --help text
function old new delta
tcsetattr_serial_or_warn - 34 +34
static.int_N_SLIP - 4 +4
restore_state_and_exit 123 117 -6
packed_usage 31774 31747 -27
set_termios_state_or_warn 42 - -42
slattach_main 673 624 -49
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 0/3 up/down: 38/-124) Total: -86 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 12:15:24 +0000 (14:15 +0200)]
nameif: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 12:03:27 +0000 (14:03 +0200)]
Tweak outdated documentation and comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 10:28:00 +0000 (12:28 +0200)]
tunctl: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 10:23:04 +0000 (12:23 +0200)]
kbd_more: make it NOEXEC, remove redundant opt clearing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 10:17:46 +0000 (12:17 +0200)]
kbd_mode: try harder to find console device if -C TTY is not given
Was (under X):
$ ./busybox_old kbd_mode
kbd_mode: ioctl 0x4b44 failed: Inappropriate ioctl for device
Now:
$ ./busybox kbd_mode
The keyboard is in off mode
function old new delta
kbd_mode_main 166 174 +8
packed_usage 31782 31764 -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 8/-18) Total: -10 bytes
text data bss dec hex filename
915757 485 6880 923122 e15f2 busybox_old
915747 485 6880 923112 e15e8 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 6 Aug 2017 09:58:46 +0000 (11:58 +0200)]
kbd_mode: show "off" mode too
function old new delta
kbd_mode_main 156 166 +10
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 21:28:19 +0000 (23:28 +0200)]
lspci,lsscsi,lsusb: make them NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 21:21:02 +0000 (23:21 +0200)]
umount: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 20:25:00 +0000 (22:25 +0200)]
pstree: make it NOEXEC
While at it, documet why ps can't be NOEXEC.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 18:38:04 +0000 (20:38 +0200)]
chattr,lsattr,tune2fs: make them NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 18:33:48 +0000 (20:33 +0200)]
chattr: fix option parsing to accept more cryptic option combos
function old new delta
chattr_main 286 289 +3
packed_usage 31793 31761 -32
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 16:23:10 +0000 (18:23 +0200)]
sysctl: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 16:20:34 +0000 (18:20 +0200)]
sysctl: recognize ";comment" and "<whitespace>#comment" lines
function old new delta
config_read 639 699 +60
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 15:50:35 +0000 (17:50 +0200)]
libbb: make trim() return pointer to terminating NUL
function old new delta
trim 80 90 +10
angle_address 56 50 -6
sysctl_main 282 273 -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: +10/-15) Total: -5 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 11:45:22 +0000 (13:45 +0200)]
sysctl: fix file parsing, do not require -w for VAR=VAL
function old new delta
sysctl_act_on_setting - 451 +451
sysctl_main 222 282 +60
packed_usage 31744 31793 +49
config_read 604 639 +35
sysctl_act_recursive 612 163 -449
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 595/-449) Total: 146 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 00:08:23 +0000 (02:08 +0200)]
cryptpw, mkpasswd: make them NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 5 Aug 2017 00:02:31 +0000 (02:02 +0200)]
chvt, deallocvt, dumpkmap, fgconsole, loadkmap: make them NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 23:51:12 +0000 (01:51 +0200)]
pivot_root: make it NOFORK
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 23:46:39 +0000 (01:46 +0200)]
partprobe: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 23:42:08 +0000 (01:42 +0200)]
sv, svc: make them NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 23:38:55 +0000 (01:38 +0200)]
svc: fix a case where with more than option, getopt() state is not reset
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 23:29:12 +0000 (01:29 +0200)]
blockdev, fsfreeze, fstrim, mountpoint: make NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 21:04:17 +0000 (23:04 +0200)]
libbb: use _exit, not exit, in bb_daemonize_or_rexec()
By the time we reach exit in parent, child already exited or execed.
We should not re-run libc cleanup code.
While at it, introduce bb_daemon_helper() and add a few comments.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 18:07:19 +0000 (20:07 +0200)]
stty: make in NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 17:55:01 +0000 (19:55 +0200)]
make 17 state-changing execing applets (ex: "nice PROG ARGS") noexec
The applets with "<applet> [opts] PROG ARGS" API very quickly exec
another program, noexec is okay for them:
chpst/envdir/envuidgid/softlimit/setuidgid
chroot
chrt
ionice
nice
nohup
setarch/linux32/linux64
taskset
cttyhack
"reset" and "sulogin" applets don't have this form, but also exec
another program at once, thus made noexec too.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 17:16:01 +0000 (19:16 +0200)]
mesg: make in NOFORK
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 16:36:55 +0000 (18:36 +0200)]
pmap: tweak help text, show usage if no params are given
Noticed while auditing nofork/noexec status
function old new delta
pmap_main 70 80 +10
packed_usage 31747 31744 -3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 15:59:46 +0000 (17:59 +0200)]
runlevel: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 15:39:05 +0000 (17:39 +0200)]
mktemp: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 15:36:16 +0000 (17:36 +0200)]
chat: trim help text
Noticed while auditing nofork/noexec status
function old new delta
packed_usage 31777 31747 -30
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 14:46:17 +0000 (16:46 +0200)]
getopt32: move support for "always treat first arg as option" to users (tar/ar)
Now getopt() never leaks (and never performs) any xmalloc's.
function old new delta
ar_main 522 556 +34
tar_main 986 1014 +28
getopt32 1458 1350 -108
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 62/-108) Total: -46 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 14:23:42 +0000 (16:23 +0200)]
getopt32: factor out code to treat all args as options
Working towards making getopt32() xmalloc-free
function old new delta
make_all_argv_opts - 58 +58
top_main 914 912 -2
getopt32 1517 1458 -59
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 58/-61) Total: -3 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 14:01:39 +0000 (16:01 +0200)]
tweak NOFORK_NOEXEC.lst
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 13:24:49 +0000 (15:24 +0200)]
ash: BASH_XTRACEFD bashism
Based on patch by Johannes Schindelin <johannes.schindelin@gmx.de>
function old new delta
evalcommand 1447 1500 +53
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Johannes Schindelin [Fri, 4 Aug 2017 10:16:46 +0000 (12:16 +0200)]
ash: remove no-longer-used variable
As of
035486c75 (ash: significant overhaul of redirect saving logic,
2017-07-31), the sv_pos variable is no longer used (just assigned to,
with no further effect).
Let's just remove it.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 12:50:03 +0000 (14:50 +0200)]
ash: INT_OFF/INT_ON around run_nofork_applet()
function old new delta
evalcommand 1441 1447 +6
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 12:28:16 +0000 (14:28 +0200)]
sheel: improve comments on signal handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 00:56:39 +0000 (02:56 +0200)]
modutils: make them NOEXEC except depmod
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 4 Aug 2017 00:01:45 +0000 (02:01 +0200)]
microcom: require exactly one non-option
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 3 Aug 2017 17:56:29 +0000 (19:56 +0200)]
ash: add a fixme comment at run_nofork_applet
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 3 Aug 2017 17:52:47 +0000 (19:52 +0200)]
nofork: fix a bug uncovered by hush testsuite (forgotten fflush)
function old new delta
run_nofork_applet 280 287 +7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 3 Aug 2017 17:30:21 +0000 (19:30 +0200)]
getopt: make it NOEXEC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 3 Aug 2017 17:00:01 +0000 (19:00 +0200)]
new NOFORKs: pwdx,kill[all5],ttysize,realpath,readlink NOEXECs: date,resize
function old new delta
run_nofork_applet 258 280 +22
readlink_main 112 123 +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 33/0) Total: 33 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 3 Aug 2017 01:46:14 +0000 (03:46 +0200)]
config: FEDORA_COMPAT option (so far only tweaks uname)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 3 Aug 2017 01:29:32 +0000 (03:29 +0200)]
new NOFORKs: clear, nproc, tty, uname, arch, unlink, which
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 2 Aug 2017 17:44:05 +0000 (19:44 +0200)]
hush: do not accept "if() { echo; }" function def
function old new delta
parse_stream 2634 2692 +58
msg_and_die_if_script - 21 +21
syntax_error_unexpected_ch 41 46 +5
syntax_error_at 14 18 +4
die_if_script 31 28 -3
setup_redirects 319 308 -11
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/2 up/down: 88/-14) Total: 74 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 2 Aug 2017 15:27:28 +0000 (17:27 +0200)]
line editing: make read_line_input() not take timeout param
It's almost always -1.
function old new delta
read_line_input 3902 3912 +10
new_line_input_t 24 31 +7
pgetc 583 585 +2
save_command_ps_at_cur_history 80 78 -2
read_line 76 74 -2
fgetc_interactive 246 244 -2
addLines 84 82 -2
doCommands 2226 2222 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/5 up/down: 19/-12) Total: 7 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 2 Aug 2017 14:52:12 +0000 (16:52 +0200)]
hush: make SIGINT handling visually less confusing
$ echo $$
18448
$ echo $? <wait here, run "kill -INT 18448" in other shell><press enter>
<=== NOTHING??
$
That empty line does not look right. After this patch:
$ echo $$
18448
$ echo $? <wait here, run "kill -INT 18448" in other shell><press enter>
^C
$
function old new delta
fgetc_interactive 245 246 +1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 2 Aug 2017 14:37:39 +0000 (16:37 +0200)]
NOFORK fixes
"rm -i FILE" and "yes" can now be interrupted by ^C in hush.
This also now works:
$ usleep
19999999
^C
$ echo $?
130
function old new delta
run_pipe 1668 1711 +43
pseudo_exec_argv 312 321 +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0) Total: 52 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 2 Aug 2017 12:26:33 +0000 (14:26 +0200)]
do not use `a' quoting style in comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 2 Aug 2017 12:12:48 +0000 (14:12 +0200)]
config: do not use `a' quoting in help texts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 17:43:47 +0000 (19:43 +0200)]
ash: align --login code with dash
Upstream commit:
Date: Sun, 13 Jul 2008 22:34:50 +0800
[OPTIONS] Added support for -l
This patch adds support for the -l option (login shell) as required
by the LSB.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
It's a bit bigger, but gets rid of one global variable
function old new delta
options 554 576 +22
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 17:20:43 +0000 (19:20 +0200)]
test: fix 4-argument case
Upstream dash commit:
Date: Sun, 13 Jul 2008 19:20:10 +0800
Fixed 3,4-argument cases for test per POSIX
----- Forwarded message from Gerrit Pape <pape@smarden.org> -----
Subject: Bug#455828: dash: 4-argument test "test \( ! -e \)" yields an error
Date: Fri, 28 Dec 2007 08:53:29 +0000
From: Gerrit Pape <pape@smarden.org>
To: Vincent Lefevre <vincent@vinc17.org>, 455828@bugs.debian.org
On Thu, Dec 27, 2007 at 06:23:20PM +0100, Vincent Lefevre wrote:
> On 2007-12-27 16:00:06 +0000, Gerrit Pape wrote:
> > On Wed, Dec 12, 2007 at 02:18:47AM +0100, Vincent Lefevre wrote:
> > > According to POSIX[*], "test \( ! -e \)" is a 4-argument test and is
> > > here equivalent to "test ! -e". But dash (like ksh93 and bash) yields
> > > an error:
> > >
> > > $ test \( ! -e \) || echo $?
> > > test: 1: closing paren expected
> > > 2
> > > $ test ! -e || echo $?
> > > 1
> >
> > Hi Vincent,
> >
> > the -e switch to test takes an argument, a pathname.
>
> According to POSIX, in both above examples, "-e" is *not* a switch,
> just a string.
>
> test \( ! -e \)
>
> means: return true if the string "-e" is empty, otherwhise return false.
> The error in dash is that it incorrectly thinks that "-e" is a switch in
> this context.
I see, you're right. Thanks, Gerrit.
----- End forwarded message -----
This patch hard-codes the 3,4-argument cases in the way required by
POSIX.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
function old new delta
test_main 370 421 +51
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 16:06:07 +0000 (18:06 +0200)]
hush: remove redundant "G_flag_return_in_progress = -1"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 16:02:28 +0000 (18:02 +0200)]
hush: fix "true | func_with_return" not allowing return.
function old new delta
pseudo_exec_argv 305 312 +7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 12:32:18 +0000 (14:32 +0200)]
ash: fix display of ">&-" redirect in job strings
function old new delta
cmdtxt 558 569 +11
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 03:27:09 +0000 (05:27 +0200)]
hush: functions have priority over builtins (!)
function old new delta
pseudo_exec_argv 291 305 +14
run_pipe 1560 1555 -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-5) Total: 9 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 02:54:53 +0000 (04:54 +0200)]
hush: if STANDALONE, close interactive fd for NOEXECed children
function old new delta
pseudo_exec_argv 291 305 +14
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 02:32:06 +0000 (04:32 +0200)]
ash,hush: ">&10" redirects to script/tty fds should not work
The fact that shell has open fds to tty and/or scripts should be
unobservable, if possible. In particular, if redirect tries to dup
one of them via ">&script_fd", it's better to pretend that script_fd
is closed, and thus redirect fails with EBADF.
Fixes these two testcase failures:
ash-redir/redir_to_bad_fd.tests
hush-redir/redir_to_bad_fd3.tests
function old new delta
redirect 1018 1129 +111
setup_redirects 250 359 +109
readtoken1 2651 2655 +4
cmdloop 185 187 +2
changepath 194 195 +1
save_fd_on_redirect 203 194 -9
evaltree 501 484 -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/2 up/down: 227/-26) Total: 201 bytes
text data bss dec hex filename
914553 485 6848 921886 e111e busybox_old
914754 485 6848 922087 e11e7 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 31 Jul 2017 02:09:19 +0000 (04:09 +0200)]
ash: significant overhaul of redirect saving logic
New code is similar to what hush is doing.
Make CLOSED to -1: same as dash.
popredir() loses "restore" parameter: same as dash.
COPYFD_RESTORE bit is no longer necessary.
This change fixes this interactive bug:
$ ls -l /proc/$$/fd 10>&-
ash: can't set tty process group: Bad file descriptor
ash: can't set tty process group: Bad file descriptor
[1]+ Done(2) ls -l /proc/${\$}/fd 10>&
4294967295
function old new delta
unwindredir 29 27 -2
tryexec 154 152 -2
evaltree 503 501 -2
evalcommand 1369 1367 -2
cmdloop 187 185 -2
redirect 1029 1018 -11
popredir 153 123 -30
need_to_remember 36 - -36
is_hidden_fd 68 - -68
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-155) Total: -155 bytes
text data bss dec hex filename
914572 485 6848 921905 e1131 busybox_old
914553 485 6848 921886 e111e busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 30 Jul 2017 21:34:04 +0000 (23:34 +0200)]
hush: massage redirect code to be slightly more like ash
function old new delta
save_fd_on_redirect - 203 +203
xdup_CLOEXEC_and_close - 75 +75
setup_redirects 245 250 +5
xdup_and_close 72 - -72
save_fds_on_redirect 221 - -221
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/0 up/down: 283/-293) Total: -10 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 30 Jul 2017 14:51:05 +0000 (16:51 +0200)]
ash: remove REDIR_SAVEFD2
function old new delta
evalcommand 1364 1369 +5
redirect 1055 1014 -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-41) Total: -36 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 20:58:44 +0000 (22:58 +0200)]
ash: if !ENABLE_ASH_EXPAND_PRMT, disable PSSYNTAX code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 20:51:52 +0000 (22:51 +0200)]
ash: [REDIR] Fix popredir on abnormal exit from built-in
Upstream commit:
Date: Thu, 27 May 2010 15:03:46 +0800
[REDIR] Fix popredir on abnormal exit from built-in
Just like the poplocalvar problem recently fixed, redirections
can also be leaked in case of an abnormal exit. This patch fixes
it using the same method as poplocalvar, by storing the previous
redirection state and restoring to that point.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 19:12:29 +0000 (21:12 +0200)]
ash: [PARSER] Add FAKEEOFMARK for expandstr
Upstream commit:
Date: Thu, 27 Dec 2007 13:54:16 +1100
[PARSER] Add FAKEEOFMARK for expandstr
Previously expandstr used the string "" to indicate that it needs to be
treated just like a here-doc except that there is no terminator. However,
the string "" is in fact a valid here-doc terminator so now that we deal
with it correctly expandstr no longer works in the presence of new-lines
in the prompt.
This patch introduces the FAKEEOFMARK macro which does not equal any
real EOF marker but is distinct from the NULL pointer which is used to
indicate non-here-doc contexts.
Thanks to Markus Triska for reporting this regression.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Unfortunately, I did not find the failing example for this old fix.
I also tweaked the code which was added by this commit:
"
Date: Mon Sep 24 18:30:02 2007 +0000
ash: fix prompt expansion (Natanael Copa <natanael.copa@gmail.com>)
"
since other parts of code do expect expandstr() to use DQSYNTAX, not PSSYNTAX.
function old new delta
parse_stream 2609 2634 +25
setprompt_if 128 133 +5
read_profile 32 37 +5
evalcommand 1334 1339 +5
expandstr 122 120 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 40/-2) Total: 38 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 18:43:26 +0000 (20:43 +0200)]
hush: fix handling of empty heredoc EOF marker
function old new delta
parse_stream 2609 2634 +25
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 17:57:28 +0000 (19:57 +0200)]
ash: [PARSER] Removed noexpand/length check on eofmark
Upstream comment:
Date: Sun, 11 Nov 2007 14:21:23 +0800
[PARSER] Removed noexpand/length check on eofmark
On Tue, Oct 30, 2007 at 04:23:35AM +0000, Oleg Verych wrote:
>
> } 8<<""
> ======================
Actually this (the empty delim) only works with dash by accident.
I've tried bash and pdksh and they both terminate on the first
empty line which is what you would expect rather than EOF. The
real Korn shell does something completely different.
I've fixed this in dash to conform to bash/pdksh.
> In [0] it's stated, that delimiter isn't evaluated (expanded), only
> quoiting must be checked. That if() seems to be completely bogus.
OK I agree. The reason it was there is because the parser would
have already replaced the dollar sign by an internal representation.
I've fixed it properly with this patch.
Test case:
cat <<- $a
OK
$a
cat <<- ""
OK
echo OK
Old result:
dash: Syntax error: Illegal eof marker for << redirection
OK
echo OK
New result:
OK
OK
OK
function old new delta
parsefname 227 152 -75
readtoken1 2819 2651 -168
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-243) Total: -243 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 16:54:53 +0000 (18:54 +0200)]
ash: "Undo all redirections" comment is wrong, delete it
No code changes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Ron Yorston [Sat, 29 Jul 2017 13:48:00 +0000 (14:48 +0100)]
libbb: remove vdprintf
Two reasons:
* it's only built for GNU C Library versions < 2 (released 1997)
* it isn't used anywhere in BusyBox
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 00:27:12 +0000 (02:27 +0200)]
ps: tweak outdated comment, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 00:20:17 +0000 (02:20 +0200)]
ps: implement -o sid
function old new delta
func_sid - 29 +29
out_spec 320 340 +20
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 49/0) Total: 49 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 29 Jul 2017 00:19:01 +0000 (02:19 +0200)]
standalone shell / prefer_applets: fix "exe" in comm fields
function old new delta
main 92 106 +14
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 28 Jul 2017 23:20:53 +0000 (01:20 +0200)]
ash: make tryexec(cmd) parameter const char
Fewer casts this way.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 28 Jul 2017 22:59:24 +0000 (00:59 +0200)]
shell: make standalone shell tab-complete "busybox"
function old new delta
busybox_main - 624 +624
packed_usage 31758 31777 +19
applet_names 2638 2646 +8
applet_main 1528 1532 +4
applet_install_loc 191 192 +1
run_applet_and_exit 681 78 -603
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/1 up/down: 656/-603) Total: 53 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Ron Yorston [Thu, 27 Jul 2017 12:53:39 +0000 (13:53 +0100)]
ash: support platforms that don't have '%m' printf specifier
The '%m' conversion specifier prints an error message based on the
current value of 'errno'. It is available in the GNU C library,
Cygwin (since 2012), uClibc and musl.
It is not available in various BSDs, BSD-derived systems (MacOS,
Android) or Microsoft Windows.
Use a symbol defined in platform.h to control how error messages
can be formatted to display the 'errno' message. On platforms that
support it use '%m'; on other platforms use '%s' and strerror().
On platforms that have '%m' there is essentially no change in the
size of the binary. Otherwise:
function old new delta
redirect 1287 1310 +23
xtcsetpgrp 27 44 +17
dup2_or_raise 34 51 +17
setinputfile 267 275 +8
.rodata 163379 163371 -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 65/-8) Total: 57 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 28 Jul 2017 13:28:33 +0000 (15:28 +0200)]
ash: less hackish implementation of evaltreenr()
Defining a function alias with __attribute__ ((alias("evaltree"),__noreturn__))
is not that usual, and clang had a bug which made it misunderstand
this construct.
Switch to:
ALWAYS_INLINE NORETURN evaltreenr() { evaltree(); unreachable(); }
Older gcc's do not know unreachable(), on them we pay the price of having
a few extra calls to abort():
function old new delta
evalsubshell 151 156 +5
evalpipe 357 362 +5
argstr 1141 1144 +3
On newer gcc, code size does not change.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Natanael Copa [Tue, 25 Jul 2017 18:44:50 +0000 (20:44 +0200)]
unzip: fix regression on big-endian machines
This fixes a regression which was introduced with commit
2a0867a5
("unzip: optional support for bzip2 and lzma") and causes unzip to exit
with error when extracting archives:
unzip: unsupported method 2048
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 12:45:25 +0000 (14:45 +0200)]
config: more tweaking of help texts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 12:31:59 +0000 (14:31 +0200)]
rdate: tweak comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 11:34:51 +0000 (13:34 +0200)]
inetd: improve --helpt text and config help text.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 10:53:20 +0000 (12:53 +0200)]
tweak examples/var_service/*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 10:34:56 +0000 (12:34 +0200)]
ed: fix "\n" removal in command line; make "w" set "dirty = 0"
function old new delta
doCommands 2184 2226 +42
getNum 345 343 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 42/-2) Total: 40 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 09:58:25 +0000 (11:58 +0200)]
ed: code shrink
function old new delta
findString 117 115 -2
skip_blank 16 - -16
getNum 369 345 -24
doCommands 2448 2183 -265
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-307) Total: -307 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 09:17:15 +0000 (11:17 +0200)]
ed: fix --help and reorder functions, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 08:58:08 +0000 (10:58 +0200)]
swapon: do not use FEATURE_MOUNT_LABEL, have your own FEATURE_SWAPONOFF_LABEL
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 08:53:09 +0000 (10:53 +0200)]
config: trim/improve item names and help texts, take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 27 Jul 2017 00:59:13 +0000 (02:59 +0200)]
config: trim/improve item names and help texts.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 26 Jul 2017 21:08:36 +0000 (23:08 +0200)]
ash: force inlining of a trivial function
function old new delta
bltinlookup 5 - -5
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 26 Jul 2017 21:03:21 +0000 (23:03 +0200)]
ash: revert previous implementation of "A=1 A=2 B=$A cmd" code
Reverts this:
commit
0e6f661e23d358cca104c24f8438d0ec64df32f1
Date: Fri Feb 15 15:02:15 2008 +0000
ash: handle "A=1 A=2 B=$A; echo $B". closes bug 947.
A different fix from upstream has been imported by previous six commits.
Last seven commits, cumulative:
function old new delta
poplocalvars - 314 +314
mklocal - 288 +288
pushlocalvars - 48 +48
evalcommand 1372 1408 +36
unwindlocalvars - 22 +22
ash_main 1022 1029 +7
setvar 167 172 +5
localvar_stack - 4 +4
setvareq 303 302 -1
evalcase 271 269 -2
subevalvar 1202 1198 -4
localvars 4 - -4
cmdenviron 4 - -4
expandarg 984 973 -11
evalvar 589 574 -15
argstr 1164 1141 -23
dotcmd 335 303 -32
bltinlookup 51 5 -46
varvalue 709 596 -113
evalfun 456 270 -186
localcmd 364 44 -320
------------------------------------------------------------------------------
(add/remove: 5/2 grow/shrink: 3/11 up/down: 724/-761) Total: -37 bytes
text data bss dec hex filename
915353 485 6888 922726 e1466 busybox_old
915320 485 6880 922685 e143d busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 26 Jul 2017 18:06:48 +0000 (20:06 +0200)]
ash: [VAR] Fix loss of variables when hash collides
Upstream commit:
Date: Tue, 6 Jul 2010 17:40:53 +0800
[VAR] Fix loss of variables when hash collides
Brian Koropoff reported that the new var patches broke the following
script:
#!/bin/dash
GDM_LANG="bar"
OPTION="foo"
unset GDM_LANG
# OPTION has mysteriously become unset
echo "$OPTION"
He correctly diagnosed this as a result of removing all variables
in the hash chain preceding the one that should be removed in
setvareq.
He also provided a patch to fix this.
This patch is based on his but without keeping the original vpp.
As a result, we now store new variables at the end of the hash
chain instead of the beginning.
To make this work, setvareq/setvar now returns the vp pointer
modified. In case they're used to unset a variable the pointer
returned is undefined. This is because mklocal needs it and
used to get it by assuming that the new variable always appear
at the beginning of the chain.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 26 Jul 2017 18:00:08 +0000 (20:00 +0200)]
ash: [VAR] Do not poplocalvars prematurely on regular utilities
Upstream commit:
Date: Thu, 27 May 2010 11:50:19 +0800
[VAR] Do not poplocalvars prematurely on regular utilities
The recent cmdenviron removal broke regular utilities by calling
poplocalvars too early. This patch fixes that by postponing the
poplocalvars for regular utilities until they have completed.
In order to ensure that local still works, it is now a special
built-in.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 26 Jul 2017 17:55:31 +0000 (19:55 +0200)]
ash: [VAR] Fix poplocalvar on abnormal exit from function
Upstream commit:
Date: Thu, 27 May 2010 11:32:55 +0800
[VAR] Fix poplocalvar on abnormal exit from function
The new localvar code broke the abnormal exit from functions
and built-ins by not restoring the original localvar state.
This patch fixes this by storing the previous localvar state so
that we always unwind correctly in case of an abnormal exit.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 26 Jul 2017 17:53:11 +0000 (19:53 +0200)]
ash: [VAR] Replace cmdenviron with localvars
Upstream commit:
Date: Wed, 26 May 2010 18:54:19 +0800
[VAR] Replace cmdenviron with localvars
This patch replaces the cmdenviron mechanism for temporary command
variables with the localvars mechanism used by functions.
This reduces code size, and more importantly, makes the variable
assignment take effect immediately as required by POSIX.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>