Commit Graph

13657 Commits

Author SHA1 Message Date
Denys Vlasenko
d598a8d4e6 lineedit: don't fall back to simple line input if tty is in raw mode
Testcase: shell command input after python ^Z should still work

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-10 17:22:13 +01:00
Bartosz Golaszewski
202d9a6464 Config: select PLATFORM_LINUX if using sendfile()
Man entry for sendfile:

  Not specified in POSIX.1-2001, or other standards.

  Other UNIX systems implement sendfile() with different  semantics  and
  prototypes. It should not be used in portable programs.

Select PLATFORM_LINUX if enabling FEATURE_USE_SENDFILE.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-10 13:46:53 +01:00
Jacob Kjaergaard
bd7c1f2d13 flashcp: change BUFSIZE to 4k
some flash partitions can be smaller than the existing BUFSIZE thus write
BUFSIZE will fail with "no space left on device"

Signed-off-by: Jacob Kjaergaard <jacob.kjaergaard@prevas.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-10 13:44:27 +01:00
Stephen Heumann
aca9256f97 Address problem where commands to be run in subshells were getting mangled by command-line parsing.
They are now encoded to prevent this.
2014-12-09 19:52:58 -06:00
Stephen Heumann
ac0aab62bf Eliminate memory leaks in the exec* routines for GNO.
This is done by adding new memory allocation routines that use the current process's userID, so the memory will be deallocated when it quits or execs, even if it's a forked child process.
2014-12-09 18:11:20 -06:00
Denys Vlasenko
cfcd2399b2 make xmalloc_open_zipped_read_close result NUL terminated
Compat with xmalloc_open_read_close

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-07 00:49:55 +01:00
Denys Vlasenko
b4c11c1397 libarchive: add capability to unpack to mem.buffer
The performance and number of processes for a "depmod -a" with gzipped
modules was abysmal. This patch adds a code path without fork,
benefiting all users of xmalloc_open_zipped_read_close.

"modinfo radeon.ko.gz", a single-file reader, got 30% faster.
"depmod -a", which used to fork over 800 times, got 20% faster.

Heavily based on a patch by Lauri Kasanen <curaga@operamail.com>

function                                             old     new   delta
setup_transformer_on_fd                                -     159    +159
transformer_write                                      -     122    +122
fork_transformer                                       -     112    +112
xmalloc_open_zipped_read_close                        63     118     +55
read_bunzip                                         1866    1896     +30
xtransformer_write                                     -      19     +19
unzip_main                                          2449    2462     +13
bbunpack                                             755     766     +11
unpack_lzma_stream                                  2717    2723      +6
unpack_xz_stream                                    2393    2397      +4
unpack_Z_stream                                     1173    1175      +2
inflate_unzip                                        111     105      -6
check_signature16                                     70      63      -7
unpack_bz2_stream                                    359     349     -10
unpack_unxz                                           12       -     -12
unpack_unlzma                                         12       -     -12
unpack_uncompress                                     12       -     -12
unpack_gunzip                                         12       -     -12
unpack_bunzip2                                        12       -     -12
open_transformer                                     106      92     -14
inflate_unzip_internal                              1945    1916     -29
unpack_gz_stream                                     693     655     -38
open_zipped                                           89      47     -42
setup_unzip_on_fd                                    142      53     -89
------------------------------------------------------------------------------
(add/remove: 4/5 grow/shrink: 7/8 up/down: 533/-295)          Total: 238 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-07 00:44:00 +01:00
Denys Vlasenko
e7800f351a Rename transformer_aux_data_t -> transformer_state_t
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-07 00:42:49 +01:00
Stephen Heumann
b4a362ef71 Make test report EXEC files (shell scripts) as executable. 2014-12-04 13:41:21 -06:00
Stephen Heumann
a549af27ca Fix test to account for GNO stat() giving only "owner" permission bits. 2014-12-04 12:22:52 -06:00
Stephen Heumann
2d16296748 Work around an ORCA/C preprocessor bug that was causing shell conditionals not to work properly.
The bug is that an #if condition may be mis-evaluated if it immediately follows a use of a function-like macro. I also modified a couple other places that could possibly trigger the bug (including a possibly more reliable fix for the instance of this problem I worked around earlier in include/xatonum.h).
2014-12-04 11:42:48 -06:00
Stephen Heumann
dc2193b997 Translate colons to slashes in the current path name, for compatibility with Unix-style usage.
As an exception, the translation isn't done if there is a directory name containing a /.
2014-12-03 23:02:15 -06:00
Stephen Heumann
fb9b298ca4 Implement "close-on-exec" functionality for GNO.
We do this by maintaining a mask (for each pid) giving the fds to be closed on exec. We wrap functions that close fds so that their close-on-exec bits can be cleared at that point.

This implementation may close the fds even if the execve operation ultimately fails.
2014-12-03 21:04:46 -06:00
Stephen Heumann
8cdae3cd7a Add our own version of qsort, because the one from ORCA/C is recursive and can use thousands of KB of stack space.
The new version is a heap sort implementation adapted from musl libc.
2014-12-03 10:49:24 -06:00
Stephen Heumann
e97a83d054 Add code to check and report our stack usage if HUSH_STACKCHECK is defined.
This only covers exec'd instances of hush (run by the user, or by re_execute_shell), not the forked, pre-exec part.
2014-12-02 20:53:45 -06:00
Stephen Heumann
7b989fb6bc Work around a preprocessor bug that was causing an inappropriate version of many of the xatonum functions to be included in every object file. 2014-12-02 18:57:45 -06:00
Stephen Heumann
52c59f6da1 Properly reset getopt in each invocation of getopt32() on BSD-type systems, including GNO and OS X.
Also, fix issue where callers of getopt32() weren't properly detecting errors on GNO due to a size mismatch.

This avoids strange behavior when commands using getopt32 (like export) are invoked multiple times, sometimes with invalid arguments.
2014-12-02 15:31:50 -06:00
Stephen Heumann
1ac41557b2 Replace stack-allocated "struct utsname" in hush_main with dynamic allocation. 2014-12-02 13:56:38 -06:00
Stephen Heumann
81652ca9c4 Always copy the variable strings from environ to our variable structures in hush_main, instead of trying to share them.
This avoids problems stemming from the fact that GNO's environment implementation may deallocate those strings, in some cases before we're done with them. It also allows us to uppercase the variable names, although since we made them case-insensitive this only matters for display purposes (in "set" output).
2014-12-02 13:42:18 -06:00
Stephen Heumann
3805dfc06e Replace stack-allocated array with dynamically-allocated data in getopt32(). 2014-12-02 11:31:20 -06:00
Stephen Heumann
468751ba5f Switch the vfork implementation to use procrecvtim() for waiting, and not signal the parent from the child.
This avoids a problem where one of the SIGALRM signals could be delivered after the original SIGALRM handler was restored, which would normally cause the process to terminate.

For now, we just rely on polling in a loop to determine when the child is done. This isn't optimal, but should be OK. If procsend() worked, we could use that in the child to signal the parent. However, procsend() is broken in GNO 2.0.6 -- it seems that it actually tries to invoke the send() call for sockets, but with the wrong arguments, leading to a crash.
2014-12-01 21:05:13 -06:00
Denys Vlasenko
476654cdbe man: do not mangle $MANPATH in memory
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-30 19:39:58 +01:00
Bartosz Golaszewski
8d75d794ea libbb: use sendfile() to copy data between file descriptors
Busybox already uses sendfile in httpd. This patch proposes to use it
globally to copy data between file descriptors.

It speeds up the copying on slow systems a lot - below are the times needed
to copy a 450Mb file with and without this option enabled on a BeagleBone
Black:

sendfile:
user    0m0.000s
sys     0m8.170s

read/write 4k:
user    0m0.470s
sys     0m16.300s

function                                             old     new   delta
bb_full_fd_action                                    394     474     +80

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-27 23:31:58 +01:00
Denys Vlasenko
ee41094b80 man: accept a list of dirs in $MANPATH
function                                             old     new   delta
add_MANPATH                                            -     143    +143
man_main                                             852     731    -121
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 143/-121)           Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-27 00:40:08 +01:00
Denys Vlasenko
04c1417602 libbb: use ARG_MAX for bb_arg_max() only if it's 60k+
Sometimes ARG_MAX is small (like 32k) yet sysconf(_SC_ARG_MAX)
is big, and people prefer using the bigger value.

OTOH, with sufficiently large ARG_MAX, further wins from
sysconf(_SC_ARG_MAX) being bigger are exponentially smaller:
you can see 4 times fewer fork+execs when you run find, but
when each execed process already takes a thousand parameters
it's likely execution time is dominated by what that process
does with each parameter.

Thus, with this change ARG_MAX is used if it's sufficiently big,
otherwise sysconf(_SC_ARG_MAX) is used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-26 15:17:59 +01:00
Denys Vlasenko
2835a224cd bbunit: fix WANT_TIMING compilation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-26 14:04:51 +01:00
Bartosz Golaszewski
eff58f15b0 gitignore: add testsuite/echo-ne
Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-26 13:28:54 +01:00
Stephen Heumann
334678c6e9 Change various uses of signal masks to use 32-bit values (previously half the signals were essentially cut off). 2014-11-25 17:43:14 -06:00
Stephen Heumann
8b9da06832 Fix bug that was causing parse errors on shell control constructs (loops, if, case).
The bug was related to overflowing the 16-bit size of int.
2014-11-25 17:08:43 -06:00
Denys Vlasenko
298fabaefc udhcpd: if a lease from lease file coincides with a static one, ignore it
function                                             old     new   delta
read_leases                                          269     328     +59

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-25 18:49:14 +01:00
Stephen Heumann
abcab533f4 Fix to make ... and $(...) command substitution work correctly.
This was a 1 -> STDOUT_FILENO change that I missed previously.
2014-11-23 15:47:39 -06:00
Stephen Heumann
7ceb59ae57 Minor cleanup in execve. 2014-11-22 22:57:59 -06:00
Stephen Heumann
036cea4dbe Add support to our execve for running scripts, which may have a #! line giving the interpreter to use.
We have to do this ourselves, since the GNO kernel's _execve doesn't do it for us.
2014-11-22 21:27:11 -06:00
Stephen Heumann
3e7c0d0ace Add our own version of execve for GNO, which can quote arguments and can remove variables from the environment if needed.
Our versions of the execv* functions have been moved to their own file. They are now used for all the exec* calls in hush.
2014-11-22 16:53:59 -06:00
Stephen Heumann
8728cdf2b8 Encode functions and certain variables passed to subshells as command line arguments, to ensure they aren't mangled by ORCA/C's command line parsing. 2014-11-22 15:10:35 -06:00
Stephen Heumann
2eedd5e9b3 Implement our own version of execvp for GNO, which quotes arguments containing spaces or tabs.
This should allow most typical cases of arguments with spaces to work correctly, although it will still break down in some cases. We can't do this perfectly, because we're ultimately dependent on the argument parsing code in the target application, and at least the code generated by ORCA/C doesn't give us a way to make an arbitrary string be treated as a single argument.
2014-11-22 12:55:07 -06:00
Stephen Heumann
5c972aa397 Fix our handling of process groups for job control, working around a couple GNO bugs.
*Most significantly, we avoid using setpgid(), because it doesn't work and in fact corrupts the kernel's process group table.
*Also, work around tctpgrp() returning garbage instead of 0 on success.

This adds an implementation of tcsetpgrp that works by reading the process tables to find a process in the appropriate group. This isn't used for the main job control operations, though, since it might be relatively slow.

At this point, basic job control seems to work.
2014-11-21 23:05:38 -06:00
Denys Vlasenko
2bba9ad67a init: do not run shutdown/reexec actions from signal handler
this is racy wrt various libc functions such as syslog()

function                                             old     new   delta
check_delayed_sigs                                   182     352    +170
init_main                                            772     728     -44
restart_handler                                       74       -     -74
halt_reboot_pwoff                                     79       -     -79
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/1 up/down: 170/-197)          Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-21 20:10:57 +01:00
Stephen Heumann
72634b98b9 In redirection operations, map fds 0/1/2 to 1/2/3 so they work as stdin/stdout/stderr, preserving compatibility with Unix shell scripts.
Also do a similar mapping for fds passed to "read -u" and "test -t".
2014-11-20 23:12:01 -06:00
Stephen Heumann
432950e315 In glob, factor out "stat" call and structure to a separate function. This reduces stack usage in the recursive glob function. 2014-11-20 21:08:21 -06:00
Stephen Heumann
95bcfc3b6e Remove libbb/copyfd.c and an unused function that was its only caller. 2014-11-20 20:00:21 -06:00
Stephen Heumann
2e0e5358c3 Change some stack-allocated arrays in libbb/lineedit.c to be dynamically allocated. 2014-11-20 18:34:52 -06:00
Stephen Heumann
62d8398fcf Fix to assign valid pgrps to child processes. On GNO, we can't just use the pid as a pgrp; we must call tcnewpgrp instead. 2014-11-20 17:53:33 -06:00
Stephen Heumann
4d60cd1043 Fixes for environment variable handling on GNO:
* Push/pop environment to make sure it is isolated from our parents and children.
* Make all environment vars (and shell vars) case-insensitive, consistent with GNO's internal handling of environment vars.
* Wrap putenv and unsetenv to make sure they are called with lower-case variable names, which is necessary to maintain consistency between the environ array and the kernel's internal representation of variables.
2014-11-20 13:21:23 -06:00
Denys Vlasenko
4e314faa0a modprobe,rmmod: reject module names with slashes
function                                             old     new   delta
add_probe                                             86     113     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-20 18:24:33 +01:00
Stephen Heumann
97eb1defae Fix input handling so $ and # can be typed. This also fixes handling of ^C and ^D during line editing.
The issue with $ and # resulted from incompatible definitions of the CTRL macro between our code and the system headers.
2014-11-19 20:44:25 -06:00
Stephen Heumann
d958c364f9 Merge commit 'f5add44981b43490376ea0dfed1420dba09a3a75' 2014-11-19 18:49:57 -06:00
Denys Vlasenko
f5add44981 typo fix in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-20 01:43:30 +01:00
Stephen Heumann
078f526df7 Fixes for terminal behavior on the GNO console 2014-11-19 12:52:05 -06:00
Stephen Heumann
ed1fff2c7b Merge commit '8a475def9e3e21f780ebcf07dd607b26ceb00ea8'
Includes a fix for a potential overflow when doing shell arithmetic division.
2014-11-18 21:16:35 -06:00