Commit Graph

13605 Commits

Author SHA1 Message Date
Stephen Heumann f873a5cb9f README format fix. 2014-12-15 21:48:31 -06:00
Stephen Heumann d6f48f9104 Add README file 2014-12-15 21:46:21 -06:00
Stephen Heumann 787a84b7e8 Include copyright/license notices in all c files, including a BSD-style license for ones written from scratch by me. 2014-12-15 17:27:46 -06:00
Stephen Heumann e96ed4b46a Update the makefile for building on modern *nix systems. Rename to "Makefile" so we can build with just "make."
Also remove an unused variable that clang was warning about.
2014-12-15 16:47:12 -06:00
Stephen Heumann 12d172a1d9 GNO Makefile updates
1) Rename to Makefile.mk
2) Use *.o rather than *.a for object files
3) Reduce stack size to 4096 (may reduce further later)
2014-12-15 16:35:34 -06:00
Stephen Heumann d0dd867542 Fix problem where trying to run a program on a nonexistent volume gave an unescapable 'insert disk' dialog.
This also gives more sensible error messages when trying to execute nonexistent files.
2014-12-14 22:37:12 -06:00
Stephen Heumann 0c9ebf3839 Fix problem with the read builtin where it wouldn't finish until you typed an additional character beyond the return that was supposed to terminate it. 2014-12-14 22:06:27 -06:00
Stephen Heumann 26efb6c33e Add support for moving forward/backward one word with OA-left/right on GNO and Ctrl/Alt/Command-left/right on VT100-style terminals.
The support for OA-left/right on GNO uses the OA2META ioctl option to map OA-x to ESC x.

VT100-type terminal emulators have significant variations in what modifier combinations they'll pass through and what escape sequences they produce. Hopefully at least one of them works on just about everything.
2014-12-14 18:49:10 -06:00
Stephen Heumann 8bc7d9fb31 Fix lineedit to process down arrow key properly.
This was broken by the change to using CRMOD mode, which actually does mapping on input as well as output. The fix is to set the terminal to "vt100 arrow" mode, which is an undocumented option that translates arrows to vt100-style escape sequences (also used by gsh).

(Note that the earlier patch actually makes us use CRMOD mode most of the time, not non-CRMOD mode as the summary erroneously says.)
2014-12-14 17:25:04 -06:00
Stephen Heumann 3887b30719 Fix bb_put_cr on non-GNO (it wasn't flushing stdout before printing the CR, leading to the prior character not appearing). 2014-12-14 14:21:25 -06:00
Stephen Heumann 55302cd56c Change lineedit so the terminal isn't kept in CRMOD mode most of the time.
This is important because CRMOD mode prevents text from backgrounded programs from being printed properly. It also leaves the terminal in an inappropriate state if hush crashes or is killed.

For the time being, we still switch briefly to CRMOD mode when we want to print just a CR.
2014-12-14 12:40:46 -06:00
Stephen Heumann 4f7d95d896 Fix problems with editing of commands that extend to multiple lines. 2014-12-13 22:21:38 -06:00
Stephen Heumann 038f37f9eb Enable "fancy echo," including echo -n and -e options. 2014-12-10 18:56:14 -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 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
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
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 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
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
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
Stephen Heumann 60b6415214 Add our own implementation of fnmatch (taken from NetBSD), because the one in GNO 2.0.6's libc is broken.
The version in libc both matches things it shouldn't and doesn't match things it should, in (at least) cases where a pattern includes additional stuff beyond a *.
2014-11-18 20:51:04 -06:00
Denys Vlasenko 8a475def9e ash,hush: do not segfault on $((2**63 / -1))
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-18 14:32:58 +01:00