Commit Graph

2010 Commits

Author SHA1 Message Date
Stephen Heumann
d305e3b821 Fix a bug where numbers could be truncated to four decimal digits in certain circumstances.
This affected values from $RANDOM, and could potentially also result in corruption of pid values if they were large enough.
2015-01-15 21:28:35 -06:00
Stephen Heumann
3d106c6708 In waitpid emulation, restart waiting after signals.
This matches the semantics the original hush code obtained by using the SA_RESTART flag when installing signal handlers, and avoids error messages about waitpid being interrupted.
2015-01-15 18:45:42 -06:00
Stephen Heumann
656769d136 Work around GNO libc's buggy sigprocmask implementation by defining our own version of it. This should fix issues where hush could hang in wait() calls.
The sigprocmask implementation in GNO 2.0.6 libc has bugs that cause it to never actually unblock signals that have been blocked. This was causing many signals to remain blocked when they shouldn't be, particularly after running signal handlers.

This problem combined with a kernel issue (wait() calls won't recognize that a child has finished if SIGCHLD is blocked) to cause hangs in certain conditions.

This patch works around these issues by defining our own non-buggy version of sigprocmask in place of libc's.
2015-01-15 18:02:33 -06:00
Stephen Heumann
01890e4a42 Reset to normal cursor when the command prompt is printed.
This works around problems when programs change the cursor and don't restore it before exiting.
2015-01-08 17:10:46 -06:00
Stephen Heumann
ba87092078 Work around problem where hush would hang after another process was ^C'd while reading from the terminal.
I think this problem is probably due to a bug in GNO's implementation of select().

The workaround is not to use poll (which calls select) when reading a key with no timeout (which is the normal case for command-line input).
2015-01-01 23:16:26 -06:00
Stephen Heumann
b220322ac5 Fix so history files on ProDOS volumes actually get replaced and thus shortened when they reach their max size.
Also, reduce the default history size.
2015-01-01 22:11:38 -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
70ea37208b Merge with BusyBox 1.23.0.
The only substantive change is about when simple line input mode is used.

I also bumped the version number and included a GNO-version-specific component.
2014-12-27 13:33:41 -06:00
Stephen Heumann
5b1c69f8d6 Error handling in case termcap entry can't be found 2014-12-26 23:13:52 -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
Denys Vlasenko
ca9c4653a9 libbb: add sanity check in bb_arg_max()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-24 01:46:29 +01:00
Denys Vlasenko
11775edbfc randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-22 19:37:05 +01:00
Stephen Heumann
c37319db8a Fix problem where the system crashed as soon as you typed anything at the hush prompt in TMTerm or GSI.
The problem seemed to be that it crashes if the t_intrc special character is set to -1 on a pty. I worked around this by setting it to an obscure control character instead in that case.
2014-12-17 23:09:20 -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
Ron Yorston
20cd31a2d7 lineedit: don't block when looking for escape sequence in vi-mode
In vi-mode lineedit tries to detect some escape sequences.
After the ESC it reads the next character to check for certain
values.  This read should have a timeout or a user-entered ESC to
switch to command mode doesn't properly handle the next character.

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-15 13:30:58 +01: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
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
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
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
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
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
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
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
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
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
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
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
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
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
078f526df7 Fixes for terminal behavior on the GNO console 2014-11-19 12:52:05 -06:00
Denys Vlasenko
628f134fe7 exit with 127 if appled name wasn't found - it's more POSIXy
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-17 17:03:47 +01:00
Stephen Heumann
2fd57a3bdc Add basic support for getting input escape sequences from termcap. 2014-11-12 23:25:01 -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
b3a419646b Changes to handle the use of \r as newline on the IIgs. 2014-11-08 19:58:11 -06:00