Commit Graph

165 Commits (master)

Author SHA1 Message Date
Oliver Kiddle 69c5887461 52622 (tweaked, c.f. 52626): adjust number of columns and drop right-parenthesis in "kill -L" output 3 months ago
Oliver Kiddle 5331ff11c6 52594: support for POSIX real-time signals with kill and trap
Also add new -L option to kill for a more verbose listing of signals
3 months ago
Bart Schaefer 0ecc456fb2 52365: record state of exited background jobs so as to be visible in TRAPCHLD 5 months ago
Oliver Kiddle 618f842b46 52326, 52372: add -q option to kill for sigqueue 6 months ago
Peter Stephenson 03695f4b58 51977: PIPEFAIL interaction with ERREXIT / ERRRETURN
Ensure the list-level error handling code is executed if we detect pipe failure for a foreground job.

Add tests.
10 months ago
Oliver Kiddle f80ad32c3f 51769: fix compilation when HAVE_GETRUSAGE is not defined
Also silence compiler warning when HAVE_SETUPTERM is not defined.
1 year ago
Jun-ichi Takimoto c006d76097 51604: %M in TIMEFMT should report in kilobytes 1 year ago
Mikael Magnusson 6d40d9b63b 51602: Handle SIGIOT as an alias to SIGABRT if they are the same signal number 1 year ago
Bart Schaefer d3edf31830 51404: Nullify filelist after deleting (fix segfault) 1 year ago
Bart Schaefer 61610ea4bd 50922: fix additional cases of signals for current shell jobs on the right of a pipeline.
Backs out part of 188c5cd5 (workers/50874).  With this change, after a
new subshell is forked upon suspend of the right side of a pipeline, the
previous foreground subjob is resumed first and the new subshell remains
stopped until that job finishes.
2 years ago
Bart Schaefer 188c5cd518 50874: fix handling of tty signals for jobs in the current shell when waiting for the right side of a pipeline.
Reverts 15bf8ace (workers/50134).  Thanks to Jun T. for debugging assistance.

Issues came down to two things:
1. update_job() may be called on a process group leader even when a
   signal was NOT sent to any process in that process group.  This
   caused jobs to be resumed or backgrounded incorrectly or in the
   wrong order.
2. When there is a current-shell complex command (in braces) on the
   right side of a pipeline, external processes within it have their
   own process groups, but a tty signal sent to such a process should
   be treated as if received by the whole complex command.

This fixes:
* Suspend/resume of a foreground pipeline within a shell function
* Interrupt or suspend/resume of processes in a pipeline ending in { ... }
* Interrupt of such a pipeline after exit of the last process in { ... }

These affected interactive shells only (MONITOR set plus tty signals).
2 years ago
Bart Schaefer cb59dfb3a6 50379/50380: fix off-by-one side-effect of workers/49906 that broke $(jobs -l) 2 years ago
Jun-ichi Takimoto c36068357b 50342: fix test added by 50306 2 years ago
Jun-ichi Takimoto 22b1a91c2a 50306: fix wait for child that was stopped/continued
do not call addbgstatus() when child is stopped/continued
2 years ago
Bart Schaefer e127ceaae8 50149: Remove all remaining =(...) files at shell exit 2 years ago
Bart Schaefer 15bf8ace16 50134: Tweak process group handling to prevent unkillable pipelines
In some cases the process group leader of the forked-left side of a
pipe needs to be set to the pipe process PID rather than to the group
leader PID returned by entersubsh().
2 years ago
Peter Stephenson 98e4634086 49906 (Bart), 49911: Fixes to querying jobs in subshell.
Don't attempt to query invalid job off end of table, resulting in
crashes from $jobtstates.

If background task started in subshell, look at tatsks within subshell
instead of main shell.  Document and add test.
2 years ago
Peter Stephenson 6a8aa2aa5a 49783: Consistently use old job table in parameter module 2 years ago
Han Pingtian 8bdbc61497 33465: use prctl() for "jobs -Z" where available
Bart apologizes for waiting 7 years to apply this change.
3 years ago
Peter Stephenson baf4fa3621 46060: Fix spurious actions on exit status 130 or 131.
Ensure process has taken a signal before looking for SIGINT or SIGQUIT.
4 years ago
Peter Stephenson 14ea665a90 users/24710: Fix job control problem with sudo.
If we use kill to test for continued existence of a process group,
we should check on failure that the error is ESRCH, as EPERM
indicates the group still has memebers but running privileged
so should be left alone.
4 years ago
Chris Down 5c55b3fb50 45453: builtins: kill: Do not signal current process group when pid is empty
The following case was encountered in the wild:

    % zsh; echo "$?"
    % trap 'exit 5' TERM
    % kill ''
    5

This behaviour seems more likely to be the result of bugs in programs
(e.g. `kill -9 "$unsetvar") rather than being desirable
behaviour to me.  It also seems unintentional judging by the code and
documentation, since it comes about as a result of the fact that:

- `isanum` returns true for empty strings (since an empty string
  technically only consists of digits and minuses...);
- `atoi`, when passed a pointer to an invalid number, returns 0;
- `kill(0, signal)` sends the signal in question to all processes in the
  current process group.

There are (at least) two ways to solve this issue:

1. Add special handling to `kill` to avoid this case. See this patch[0]
   for a version that does that.
2. Change how isanum behaves. Since the only two call sites that use it
   both seem like they should handle the case where the input char array
   is empty, that seems like a reasonable overall change to me.[1]

After this patch:

    % trap 'exit 5' TERM
    % kill ''
    kill: illegal pid:

The regression test for `kill` without a sigspec is also included in
this commit, as previously it's not possible to test it trivially as it
would still kill the test runner in expected-to-fail mode; see
discussion in workers/45449.

0: workers/45426: https://www.zsh.org/mla/workers/2020/msg00251.html
1: The other call site using isanum() is the fg builtin, but in that
   case we just fail later since we can't find any job named '', so no
   big deal either way. It's the kill case which is more concerning.
4 years ago
Martijn Dekker c578f0a08b 45004: Fix typos in comments 5 years ago
Peter Stephenson 8c25d92e11 44864: Avoid inifinite loop in tty init.
If we can't grab the terminal in interactive mode, give
up after 100 goes.  This is a completely arbitrary choice;
we simply don't know what in the system could change the
result of looping further.
5 years ago
Oliver Kiddle b5519b372b 44290: job number exceeding int range and wrapping to a negative number crashed the shell 5 years ago
Martijn Dekker 2d056ebc31 43945 (tweaked to remove test failure, noted in test):
Fix exit statuses from wait for POSIX_BUILTINS mode.
Also add tests.
5 years ago
Peter Stephenson 623294a3ed 43589: Further improved subjob reporting.
Show subjob status instead of user-visible superjob any time
the subjob still has associated processes.
6 years ago
Daniel Shahaf 80ff65dc42 43570: Start documenting jobs.c, in particular superjobs. 6 years ago
Peter Stephenson c2d65a3a6e 43564: improve job control report about stopped subjob 6 years ago
Peter Stephenson 464065f429 43543: Further improvements to fg/bg of superjob/subjob.
Attempt to keep STAT_STOPPED correct for superjob, rendering additional
"stopped = 1" unnecessary.

Wait for subjob before superjob.
6 years ago
Peter Stephenson 0a20f4e5a6 43535: Fixes for bg / fg handling of superjobs.
Be more consistent about marking both superjob and subjob as
running when sending SIGCONT.

Send SIGCONT to superjob / subjob combination any time it is put
in foreground, even if thought running, since subjob may invisibly
have suspended.

When waiting for superjob, wait for subjob, too.
6 years ago
Peter Stephenson 551ff84272 43464: Another attachtty() fix.
If list_pipe_job triggered more than once we need to know
the most recent process group leader, so record that
both if the attach happened in the main shell on in
entersubsh().

Also don't pass back proocess group for ESUB_ASYNC subshells.
6 years ago
Peter Stephenson 7c5241edf3 43446: More entersubsh() / addproc() wiring.
Fix additional races by passing back use of list_pipe_job
from subshell.
6 years ago
Peter Stephenson 0d5275c6b9 43409: Fix process group setting in main shell.
A newly forked subshell now reports back the process group it
will be using for the main shell to record.

This prevents an error where the shell incorrectly thought an
exiting process owned the terminal and so grabbed it back,
putting the foreground process into the background.
6 years ago
Peter Stephenson 1d2f684c9b 42793: Always define FDT_PROC_SUBST even if not needed.
This avoids proliferating #ifdef's.
6 years ago
Peter Stephenson 7fd8e380bf 42453: Fix race in look up of status for wait.
Background jobs that had just exited could still be in
the table when the process had already finished and the
status was recorded, causing the wrong status to be reported.
6 years ago
Peter Stephenson 5b946f6c4d 42362: protect REPORTTIME logic from bad status 6 years ago
dana cb04ae40af add millisecond and microsecond options to TIMEFMT variable 7 years ago
Peter Stephenson da4146bdff 41688: builtin wait for all jobs should ignore STAT_NOPRINT 7 years ago
Peter Stephenson a955065cda Delay processing "disown" for superjob.
This is a job forked from the current shell when a job partly
running from the current shell was suspended.  When all associated
processes started from the main shell are finished the job is
continued and at this point the disown can complete.
7 years ago
Peter Stephenson ae10f88bfb 41386: when backgrounding a STAT_CURSH job, remove the flag.
This typical applies to a STAT_SUPERJOB.  It prevents it from
getting copied interrupts as a foreground process.
7 years ago
Peter Stephenson 327f3dd3ad 39359: Fix remaining race with orphaned subjob.
When shell is forked to run right hand side of pipieline it should
use its own PID as process group if the left hand side of the
pipeline has already exited.
8 years ago
Peter Stephenson 01ae64c0d7 39331: Reparent subjob on fork with exited superjob.
Fixes case of
  v() { { vim - } always { true } }
  ls | v
  ^Z
  fg

Tentative fix: still a race at exit where zsh forked by ^Z
is stopped when restarted.
8 years ago
Barton E. Schaefer b7bb60b47e 38923: zwaitjob() continues waiting for children that may have ignored the interrupt signal, even if the current shell has been interrupted. 8 years ago
Peter Stephenson 3859aac04e users/21632: Use of REPORTMEMORY variable
If the child's resisdent set size in megabytes exceeds this, print
out the resource (TIMEFMT) string.  Document you need to add memory
usage to this by hand.
8 years ago
Barton E. Schaefer 8cca444824 38622: consistent handling of "--" in "kill" builtin 8 years ago
Jun-ichi Takimoto a4020e10a3 37868: add 'static' to file local variables 8 years ago
Barton E. Schaefer 5d019f426a 36180: avoid infinite job stop/continue loop on "wait PID" for a background job 9 years ago
Barton E. Schaefer 128bf385b1 36104: change order of child_block() and dont_queue_signals() to resolve yet another race condition 9 years ago
Jun-ichi Takimoto b0ebabdc65 35929: protect FDT_PROC_SUBST by #ifdef 9 years ago