summaryrefslogtreecommitdiffstats
path: root/bin/sh/jobs.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Don't trust that signal descriptions fit within 49 bytes.jilles2016-03-021-18/+18
|
* sh: Pass along SIGINT from a child if job control is enabled, even when notjilles2015-04-251-1/+1
| | | | | | | | | interactive. I added the interactive check in r208881 to be safe, but in actual use (scripts in set -m mode) passing along SIGINT seems best. Discussed with: bdrewery
* sh: Fix more compiler warnings.jilles2015-03-011-1/+1
|
* sh: Abort a wait builtin on any trapped signal.jilles2015-01-311-4/+4
| | | | | | | | This is required by POSIX. PR: 197210 Reported by: ache MFC after: 2 weeks
* sh: Remove more gotos.jilles2014-10-151-40/+58
|
* sh: Eliminate some gotos.jilles2014-10-051-5/+3
|
* sh: Allow enabling job control without a tty in non-interactive mode.jilles2014-09-041-13/+40
| | | | | If no tty is available, 'set -m' is still useful to put jobs in their own process groups.
* sh: Remove prefix() function. Use strncmp() instead.jilles2014-07-201-1/+4
|
* sh: Don't overwrite old exit status if a PID is reused.jilles2014-03-201-1/+2
| | | | | | | | | Only store exit status for a process if that process has not terminated yet. Test (slow): exit 7 & p1=$!; until exit 8 & p2=$!; [ "$p1" = "$p2" ]; do wait "$p2"; done; sleep 0.1; wait %1; echo $? should write "7".
* sh: Allow kill %job on jobs started without job control.jilles2014-03-151-4/+15
| | | | | | | | When killing a %job started without job control, kill all processes in it. As with process groups and zombies, if any process in the job can be killed or has already terminated, the command is successful. This also fixes occasional failures of the builtins/kill1.0 test.
* sh: Add some consts.jilles2014-03-141-4/+4
|
* sh: Successfully do nothing when killing a terminated job.jilles2014-03-081-0/+2
| | | | | | If a job has terminated but is still known, silently do nothing when using the kill builtin with the job specifier. Formerly, the shell called kill() with the process group ID that might have been reused.
* sh: Remove one syscall when waiting for a foreground job.jilles2013-10-181-2/+1
| | | | | | The getpgrp() call is unnecessary: if there is no job control then the result was not used at all and if there is job control then we are not a subshell and our process group ID is equal to our process ID (rootpid).
* sh: Fix race condition with signals and wait or set -T.jilles2013-09-021-17/+15
| | | | | | | | | | The change in r238888 was incomplete. It was still possible for a trapped signal to arrive before the shell went to sleep (sigsuspend()) because a check was missing or because the signal arrived before in_waitcmd was set. On SMP, this bug sometimes caused the builtins/wait4.0 test to take 1 second to execute; it then might or might not fail. On UP, the test almost always failed.
* sh: Do not prematurely discard stopped jobs in a wait builtin.jilles2013-08-241-5/+1
| | | | | | | | | | | | | If a job is specified to 'wait', wait for it to complete. Formerly, in interactive mode, the job was deleted if it stopped. If no jobs are specified in interactive mode, 'wait' still waits for all jobs to complete or stop. In non-interactive mode, WUNTRACED is not passed to wait3() so stopped jobs are not detected. PR: bin/181435
* sh: Recognize "--" as end of options in bg/fg/jobid builtins.jilles2013-08-161-6/+9
|
* sh: Remove #define MKINIT.jilles2013-07-251-3/+3
| | | | MKINIT only served for the removed mkinit. Many variables can be static now.
* sh: Return status 127 for unknown jobs in wait builtin.jilles2013-06-051-5/+19
| | | | | | | | | | This is required by POSIX, at least for pids that are not known child processes. Other problems with job specifications still cause wait to abort with exit status 2. PR: 176916
* sh: Allow multiple operands in wait builtin.jilles2013-06-051-6/+18
| | | | | | | | This is only part of the PR; the behaviour for unknown/invalid pids/jobs remains unchanged (aborts the builtin with status 2). PR: 176916 Submitted by: Vadim Goncharov
* sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call.jilles2013-05-051-8/+4
|
* sh: Don't consider jobs -s/-p as reporting the status of jobs.jilles2013-04-271-7/+9
| | | | | This ensures that something like j=$(jobs -p) does not prevent any status from being written to the terminal.
* sh: Fix various compiler warnings.jilles2013-04-011-2/+3
| | | | | | | It now passes WARNS=7 with clang on i386. GCC 4.2.1 does not understand setjmp() properly so will always trigger -Wuninitialized. I will not add the volatile keywords to suppress this.
* sh: Recognize "--" and explicitly reject options in wait builtin.jilles2013-03-151-3/+4
| | | | | | If syntactically invalid job identifiers are to be taken as jobs that exited with status 127, this should not apply to options, so that we can add options later if need be.
* sh: If a SIGINT or SIGQUIT interrupts "wait", return status 128+sig.jilles2013-02-231-1/+1
|
* Catch TRACE parameters up with r238888. This change is only needed whendelphij2013-02-071-1/+1
| | | | debugging is enabled.
* sh: Show negated commands (!) in jobs output.jilles2013-01-311-0/+4
|
* sh: Prefer strsignal() to accessing sys_siglist directly.jilles2012-12-251-8/+13
| | | | | | | | Accessing sys_siglist directly requires rtld to copy it from libc to the sh executable's BSS. Also, strsignal() will put in the signal number for unknown signals (FreeBSD-specific) so we need not do that ourselves. Unfortunately, there is no function for sys_signame.
* sh: Prefer internal nextopt() to libc getopt().jilles2012-09-151-11/+4
| | | | | | | | | This reduces code duplication and code size. /usr/bin/printf is not affected. Side effect: different error messages when certain builtins are passed invalid options.
* sh: Fix EINTR race condition in "wait" and "set -T" using sigsuspend().jilles2012-07-291-4/+40
| | | | | | | | | | | | | | | | | When waiting for child processes using "wait" or if "set -T" is in effect, a signal interrupts the wait. Make sure there is no window where the signal handler may be invoked (setting a flag) just before going to sleep. There is a similar race condition in the shell language, but scripts can avoid it by exiting from the trap handler or enforcing synchronization using a fifo. If SIGCHLD is not trapped, a signal handler must be installed for it. Only install this handler for the duration of the wait to avoid triggering unexpected [EINTR] errors elsewhere. Note that for some reason only SIGINT and SIGQUIT interrupt a "wait" command. This remains the case.
* sh: Do not ask for stopped/continued processes if we do not need themjilles2012-07-281-6/+5
| | | | rather than retrying wait3 if they happen.
* sh: Inline waitproc() into its only caller.jilles2012-07-281-22/+9
|
* sh: Track continued jobs (even if not continued by bg or fg).jilles2012-07-281-3/+8
| | | | | | | This uses wait3's WCONTINUED flag. There is no message for this. The change is visible in "jobs" or if the job stops again.
* sh: Remove unused variable in_dowait.jilles2012-07-151-3/+0
|
* sh: Fix build with -DDEBUG=2.jilles2012-04-021-2/+2
| | | | | Reported by: Kristof Provost MFC after: 1 week
* sh: Use vfork in a few common cases.jilles2012-02-041-0/+49
| | | | | | | | | | | | | | | | | This uses vfork() for simple commands and command substitutions containing a single simple command, invoking an external program under certain conditions (no redirections or variable assignments, non-interactive shell, no job control). These restrictions limit the amount of code executed in a vforked child. There is a large speedup (for example 35%) in microbenchmarks. The difference in buildkernel is smaller (for example 0.5%) but still statistically significant. See http://lists.freebsd.org/pipermail/freebsd-hackers/2012-January/037581.html for some numbers. The use of vfork() can be disabled by setting a variable named SH_DISABLE_VFORK.
* Add prototypes, ANSIfy functions definitions to reduce WARNS=6 output.charnier2012-01-251-0/+1
|
* sh: Fix duplicate prototypes for builtins.jilles2011-06-131-0/+1
| | | | | | Have mkbuiltins write the prototypes for the *cmd functions to builtins.h instead of builtins.c and include builtins.h in more .c files instead of duplicating prototypes for *cmd functions in other headers.
* sh: Save/restore changed variables in optimized command substitution.jilles2011-06-121-1/+3
| | | | | | | | | | | In optimized command substitution, save and restore any variables changed by expansions (${var=value} and $((var=assigned))), instead of trying to determine if an expansion may cause such changes. If $! is referenced in optimized command substitution, do not cause jobs to be remembered longer. This fixes $(jobs $!) again, simplifies the man page and shortens the code.
* sh: Reduce more needless differences between error messages.jilles2011-06-041-2/+2
|
* sh: Remove special code for shell scripts without magic number.jilles2011-02-041-16/+0
| | | | | | | | | | These are called "shell procedures" in the source. If execve() failed with [ENOEXEC], the shell would reinitialize itself and execute the program as a script. This requires a fair amount of code which is not frequently used (most scripts have a #! magic number). Therefore just execute a new instance of sh (_PATH_BSHELL) to run the script.
* sh: Send messages about signals to stderr.jilles2011-01-301-5/+5
| | | | | | This is required by POSIX and seems to make more sense. See also r217557.
* sh: Fix signal messages being sent to the wrong file sometimes.jilles2011-01-181-0/+1
| | | | | | | | | | | | | When a foreground job exits on a signal, a message is printed to stdout about this. The buffer was not flushed after this which could result in the message being written to the wrong file if the next command was a builtin and had stdout redirected. Example: sh -c 'kill -9 $$'; : > foo; echo FOO:; cat foo Reported by: gcooper MFC after: 1 week
* sh: Add kill builtin.jilles2010-12-211-0/+8
| | | | | | | | | | | | | | | | | This allows specifying a %job (which is equivalent to the corresponding process group). Additionally, it improves reliability of kill from sh in high-load situations and ensures "kill" finds the correct utility regardless of PATH, as required by POSIX (unless the undocumented %builtin mechanism is used). Side effect: fatal errors (any error other than kill(2) failure) now return exit status 2 instead of 1. (This is consistent with other sh builtins, but not in NetBSD.) Code size increases about 1K on i386. Obtained from: NetBSD
* sh: Various simplifications to jobs.c:jilles2010-12-121-11/+5
| | | | | | | | * Prefer kill(-X) to killpg(X). * Remove some dead code. * No additional SIGINT is needed if int_pending() is already true. No functional change is intended.
* sh: Improve internal-representation-to-text code to avoid binary output.jilles2010-12-061-3/+36
| | | | | | | | | | | The code to translate the internal representation to text did not know about various additions to the internal representation since the original ash and therefore wrote binary stuff to the terminal. The code is used in the jobs command and similar output. Note that the output is far from complete and mostly serves for recognition purposes.
* sh: POSIX says there should not be a space between Done and (exitstatus).jilles2010-12-051-1/+1
| | | | (On the other hand, (core dumped) does need a space and so does [1] +.)
* sh: Improve jobs output of pipelines.jilles2010-12-051-66/+83
| | | | | | | | | | | | | | If describing the status of a pipeline, write all elements of the pipeline and show the status of the last process (which would also end up in $?). Only write one report per job, not one for every process that exits. To keep some earlier behaviour, if any process started by the shell in a foreground job terminates because of a signal, write a message about the signal (at most one message per job, however). Also, do not write messages about signals in the wait builtin in non-interactive shells. Only true foreground jobs now write such messages (for example, "Terminated").
* sh: Avoid marking a job as done before it is fully created.jilles2010-12-051-2/+2
| | | | | | | | | In r208489, I added code to reap zombies when forking new processes, to limit the amount of zombies. However, this can lead to marking a job as done or stopped if it consists of multiple processes and the first process ends very quickly. Fix this by only checking for zombies before forking the first process of a job and not marking any jobs without processes as done or stopped.
* sh: jobs -p: Do not ask the kernel for the pgid.jilles2010-12-051-4/+1
| | | | | | | | The getpgid() call will fail if the first process in the job has already terminated, resulting in output of "-1". The pgid of a job is always the pid of the first process in the job and other code already relies on this.
* sh: Use <stddef.h> rather than <sys/stddef.h>.jilles2010-10-161-1/+1
| | | | <sys/stddef.h> is only for the kernel and conflicts with <stddef.h>.
OpenPOWER on IntegriCloud