Commit Graph

772 Commits

Author SHA1 Message Date
Stephen Heumann 16cd3c0619 Merge with BusyBox 1.24.0.
There's really only one bug fix in here that should be significant for GNO hush. The other changes should be inconsequential, AFAIK.
2015-10-17 01:10:35 -05:00
Denys Vlasenko 85378cded7 hush: code shrink
function                                             old     new   delta
builtin_wait                                         347     328     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 21:47:11 +02:00
Denys Vlasenko 550bf5b4a4 remove global "jmp_buf die_jmp" from !FEATURE_PREFER_APPLETS builds
function                                             old     new   delta
xfunc_has_died                                         -      21     +21
sleep_much                                             -      12     +12
sleep10                                                -       9      +9
die_func                                               -       4      +4
fflush_stdout_and_exit                                35      36      +1
builtin_type                                         121     119      -2
die_sleep                                              4       -      -4
xfunc_die                                             60      24     -36
hush_main                                           1128    1011    -117
die_jmp                                              156       -    -156
------------------------------------------------------------------------------
(add/remove: 4/2 grow/shrink: 1/3 up/down: 47/-315)          Total: -268 bytes
   text	   data	    bss	    dec	    hex	filename
 939992	    992	  17652	 958636	  ea0ac	busybox_old
 939880	    992	  17496	 958368	  e9fa0	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 16:42:57 +02:00
Denys Vlasenko d60752f8c9 build system: -fno-builtin-printf
Benefits are: drops reference to out-of-line putchar(), fixes a few cases
of failed string merge.

function                                             old     new   delta
i2cdump_main                                        1488    1502     +14
sha256_process_block64                               423     433     +10
sendmail_main                                       1183    1185      +2
list_table                                          1114    1116      +2
i2cdetect_main                                      1235    1237      +2
fdisk_main                                          2852    2854      +2
builtin_type                                         119     121      +2
unicode_conv_to_printable2                           325     324      -1
scan_recursive                                       380     378      -2
mkfs_minix_main                                     2687    2684      -3
buffer_fill_and_print                                178     169      -9
putchar                                              152       -    -152
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 7/4 up/down: 34/-167)          Total: -133 bytes
   text    data     bss     dec     hex filename
 937788     932   17676  956396   e97ec busybox_old
 937564     932   17676  956172   e970c busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 22:42:45 +02:00
Denys Vlasenko 5711a2a4ad libbb: more compact API for bb_parse_mode()
function                                             old     new   delta
make_device                                         2182    2188      +6
parse_command                                       1440    1443      +3
parse_params                                        1497    1499      +2
install_main                                         773     769      -4
mkdir_main                                           168     160      -8
getoptscmd                                           641     632      -9
builtin_umask                                        158     147     -11
bb_parse_mode                                        431     410     -21
umaskcmd                                             286     258     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/6 up/down: 11/-81)            Total: -70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:55:33 +02:00
Denys Vlasenko 6283f98283 hush: fix umask: umask(022) was setting umask(755)
Based on the patch by Rich Felker <dalias@libc.org>

function                                             old     new   delta
builtin_umask                                        121     161     +40
umaskcmd                                             318     279     -39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 16:56:20 +02:00
Denys Vlasenko b5be13ccd9 hush: fix a nommu bug where a part of function body is lost if run in a pipe
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 06:22:10 +02:00
Maninder Singh 97f2f7ca7f Removes stray empty line from code
This patch removes stray empty line from busybox code
reported by script find_stray_empty_lines

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:25:46 +02:00
Maninder Singh 97c6491b4e typo fixes
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 13:46:36 +02:00
Denys Vlasenko 8dff01d06a libbb: introduce and use is_prefixed_with()
function                                             old     new   delta
is_prefixed_with                                       -      18     +18
complete_username                                     78      77      -1
man_main                                             737     735      -2
fsck_device                                          429     427      -2
unpack_ar_archive                                     80      76      -4
strip_unsafe_prefix                                  105     101      -4
singlemount                                         1054    1050      -4
rtc_adjtime_is_utc                                    90      86      -4
resolve_mount_spec                                    88      84      -4
parse_one_line                                      1029    1025      -4
parse_conf                                          1460    1456      -4
may_wakeup                                            83      79      -4
loadkmap_main                                        219     215      -4
get_irqs_from_stat                                   103      99      -4
get_header_cpio                                      913     909      -4
findfs_main                                           79      75      -4
fbsplash_main                                       1230    1226      -4
load_crontab                                         776     771      -5
expand_vars_to_list                                 1151    1146      -5
date_main                                            881     876      -5
skip_dev_pfx                                          30      24      -6
make_device                                         2199    2193      -6
complete_cmd_dir_file                                773     767      -6
run_applet_and_exit                                  715     708      -7
uudecode_main                                        321     313      -8
pwdx_main                                            197     189      -8
execute                                              568     560      -8
i2cdetect_main                                      1186    1176     -10
procps_scan                                         1242    1230     -12
procps_read_smaps                                   1017    1005     -12
process_module                                       746     734     -12
patch_main                                          1903    1891     -12
nfsmount                                            3572    3560     -12
stack_machine                                        126     112     -14
process_timer_stats                                  449     435     -14
match_fstype                                         111      97     -14
do_ipaddr                                           1344    1330     -14
open_list_and_close                                  359     343     -16
get_header_tar                                      1795    1779     -16
prepend_new_eth_table                                340     323     -17
fsck_main                                           1811    1794     -17
find_iface_state                                      56      38     -18
dnsd_main                                           1321    1303     -18
base_device                                          179     158     -21
find_keyword                                         104      82     -22
handle_incoming_and_exit                            2785    2762     -23
parse_and_put_prompt                                 774     746     -28
modinfo                                              347     317     -30
find_action                                          204     171     -33
update_passwd                                       1470    1436     -34
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/49 up/down: 18/-540)         Total: -522 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 17:48:34 +01:00
Stephen Heumann 46abe82986 Add support for displaying prefixes as well as setting them with prefix builtin 2015-02-07 11:26:54 -06:00
Stephen Heumann 8ab8709e6b Add code to kill stopped (or partially stopped) jobs with SIGHUP on exit.
POSIX says that _exit() should do this, but on GNO it doesn't. This implementation should match the POSIX behavior in most cases, although it's not exactly the same.

Gsh also kills jobs on exit, but does so whether they're stopped or not and uses SIGKILL.
2015-01-24 21:32:57 -06:00
Stephen Heumann b2161dc4e1 Disable a bit of useless code.
Also, add a copyright notice for me in hush.c.
2015-01-24 18:56:25 -06:00
Stephen Heumann acab757b9a Don't try to block SIGCHLD in the system() implementation.
The logic for this was broken (giving a signal number rather than a mask to sigblock), and if it wasn't broken then it would have caused the wait call to hang.

Blocking SIGCHLD is required by POSIX, but gsh doesn't do it, so existing GNO code shouldn't be relying on it.
2015-01-22 20:57:21 -06:00
Stephen Heumann 445a03527d Fix to make ^Z work for suspending processes when hush is the login shell.
The issue is that GNO's login (and other BSD-derived versions) start up the login shell with SIGTSTP ignored. Hush was recording this configuration and propagating it to its child processes, causing ^Z not to work. The fix is to not do that (for login shells only).

Also, set the system vector to run hush before running any of the startup scripts, in case something run in them uses it.
2015-01-22 17:43:45 -06:00
Stephen Heumann 2eafa59ebc Better handling of really long commands.
Commands in the range of 16k-32k should now work, and commands longer than that should cause hush to die with an error message instead of corrupting stuff (at least in the simple cases I tested).

It would be possible to eliminate the 32k limit by using a type larger than "int" for lengths, but that would be a more invasive change.
2015-01-16 21:33:13 -06:00
Stephen Heumann 988683c572 Fix "wait" builtin to work correctly in no-parameters case
This was another issue where wait() was being called with SIGCHLD masked, and therefore never returning.
2015-01-16 18:14:55 -06:00
Stephen Heumann bb88e739e5 Fix bug where using a 16-bit signal mask caused some signal handlers not to be installed.
This manifested itself in interactive hush shells getting suspended when ^Z was typed (and maybe also other ways).
2015-01-15 20:34:20 -06:00
Stephen Heumann 3380dae27a If hush is invoked as a login shell, set up a handler so it will be invoked when system() is called. 2015-01-01 17:33:01 -06:00
Stephen Heumann 01dbfccea6 Reset the terminal to our pgrp after groups, functions, and builtins, not just external command invocations.
This addresses a problem where something invoked in a group or function (e.g. gsh) could change the terminal's pgrp, and this would result in hush getting backgrounded.

We can still get strange behavior when a backgrounded child process changes the pgrp. Trying to deal with this would be inherently racy. Gsh also has problems in this scenario.
2014-12-28 12:22:37 -06:00
Stephen Heumann 9033a24562 Add support for additional startup files that will be sourced either always, for login shells, or for interactive shells. 2014-12-27 21:59:45 -06:00
Stephen Heumann 6dfc5eadb3 Changes to support GNO-style PATH in type and source commands, and in tab completion. 2014-12-26 21:49:55 -06:00
Stephen Heumann 3e96c3390f Check for TERM changes every time we read input.
Also, fix possible crashes when termcap entries aren't found.
2014-12-24 14:54:06 -06:00
Stephen Heumann cdad130f39 Add a "prefix" builtin for setting GS/OS prefixes 2014-12-22 11:18:38 -06:00
Stephen Heumann dc3caf92e7 Use a ProDOS-compatible filename for saved history file on GNO. 2014-12-16 16:02:24 -06: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 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 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 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 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 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
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
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 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
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 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
Stephen Heumann 5f6121c091 Add initial support for getting terminal information from termcap, instead of hard-coding vt100-style codes.
This currently only supports output, and still doesn't quite display correctly in some cases.
2014-11-11 20:58:06 -06:00
Stephen Heumann c37475dcbc Change vfork_and_run implementation to inspect the kernel's process tables to determine whether the child has really exec'd or exited.
This should avoid strange behavior due to races when the parent has resumed but the child is still running the exec* code in libc, which mainly manifests itself when running at low speed.

We also change to signaling the child's completion with SIGALRM, and setting an extra alarm in the parent in case the child doesn't actually do it.
2014-11-10 16:08:24 -06:00
Stephen Heumann 6d5e65b9df Fix corruption and hanging resulting from using _exit in forked processes by calling QuitGS directly instead.
GNO's _exit (contrary to its man page) does clean-up for stuff like the memory allocator, which is inappropriate in a forked child process and leads to hangs and crashes.
2014-11-09 18:49:58 -06:00
Stephen Heumann b3a419646b Changes to handle the use of \r as newline on the IIgs. 2014-11-08 19:58:11 -06:00
Stephen Heumann c8de71ae9d Changes so that hush can successfully re-execute itself:
*initialize the "environ" variable
*Reduce the stack size to 8192 (This should still be further reduced based on analysis of usage.)
2014-11-08 18:03:25 -06:00
Stephen Heumann bff0844d44 Add code to get the path of the current executable, which we need to re-execute the shell.
On the GS, this uses GS/OS calls. Versions for OS X and Linux are also included.
2014-11-07 23:06:34 -06:00