1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-05-12 10:36:17 +02:00
Commit Graph

147 Commits

Author SHA1 Message Date
Han Pingtian 8bdbc61497 33465: use prctl() for "jobs -Z" where available
Bart apologizes for waiting 7 years to apply this change.
2021-05-15 14:23:28 -07:00
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.
2020-06-18 09:27:05 +01:00
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.
2020-02-27 20:42:16 +00:00
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.
2020-02-18 12:59:53 +00:00
Martijn Dekker c578f0a08b 45004: Fix typos in comments 2019-12-11 02:37:39 +00:00
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.
2019-10-28 11:56:19 +00:00
Oliver Kiddle b5519b372b 44290: job number exceeding int range and wrapping to a negative number crashed the shell 2019-05-14 23:22:24 +02:00
Martijn Dekker 2d056ebc31 43945 (tweaked to remove test failure, noted in test):
Fix exit statuses from wait for POSIX_BUILTINS mode.
Also add tests.
2018-12-30 18:11:43 +00:00
Peter Stephenson 623294a3ed 43589: Further improved subjob reporting.
Show subjob status instead of user-visible superjob any time
the subjob still has associated processes.
2018-10-03 11:32:39 +01:00
Daniel Shahaf 80ff65dc42 43570: Start documenting jobs.c, in particular superjobs. 2018-09-28 16:21:47 +00:00
Peter Stephenson c2d65a3a6e 43564: improve job control report about stopped subjob 2018-09-26 16:23:00 +01:00
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.
2018-09-25 19:25:10 +01:00
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.
2018-09-24 21:32:40 +01:00
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.
2018-09-16 19:13:38 +01:00
Peter Stephenson 7c5241edf3 43446: More entersubsh() / addproc() wiring.
Fix additional races by passing back use of list_pipe_job
from subshell.
2018-09-12 09:22:10 +01:00
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.
2018-09-07 17:49:35 +01:00
Peter Stephenson 1d2f684c9b 42793: Always define FDT_PROC_SUBST even if not needed.
This avoids proliferating #ifdef's.
2018-05-17 10:00:37 +01:00
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.
2018-03-12 15:26:34 +00:00
Peter Stephenson 5b946f6c4d 42362: protect REPORTTIME logic from bad status 2018-02-17 22:35:32 +00:00
dana cb04ae40af add millisecond and microsecond options to TIMEFMT variable 2017-12-14 15:36:46 +00:00
Peter Stephenson da4146bdff 41688: builtin wait for all jobs should ignore STAT_NOPRINT 2017-09-13 10:49:06 +01:00
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.
2017-07-04 09:40:45 +01:00
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.
2017-07-02 21:00:56 +01:00
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.
2016-09-16 17:23:12 +01:00
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.
2016-09-16 09:39:33 +01:00
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. 2016-07-23 10:27:59 -07:00
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.
2016-06-13 16:06:22 +01:00
Barton E. Schaefer 8cca444824 38622: consistent handling of "--" in "kill" builtin 2016-06-05 17:37:08 -07:00
Jun-ichi Takimoto a4020e10a3 37868: add 'static' to file local variables 2016-02-03 01:25:33 +09:00
Barton E. Schaefer 5d019f426a 36180: avoid infinite job stop/continue loop on "wait PID" for a background job 2015-08-15 10:15:30 -07:00
Barton E. Schaefer 128bf385b1 36104: change order of child_block() and dont_queue_signals() to resolve yet another race condition 2015-08-11 08:55:23 -07:00
Jun-ichi Takimoto b0ebabdc65 35929: protect FDT_PROC_SUBST by #ifdef 2015-08-09 00:06:57 +09:00
Peter Stephenson 28a962f557 35849: close fd's from process substitution after fork
Leaving these hanging in parent could cause deadlock: test added.
2015-07-23 09:34:11 +01:00
Peter Stephenson e6638bbd70 35032: Handle SIGCONT for process better.
Update job status as well as process status.
2015-05-05 19:17:36 +01:00
Mikael Magnusson 38dc59907b 34120: compctl, jobs: Check contents instead of array
text is an array in the struct, and can never be null.

Found by Coverity (Issue 1255780).
2015-01-06 23:51:01 +01:00
Barton E. Schaefer bf075b9e0d 33992: do not attempt attachtty() for process group zero (which is possible in a linux pid namespace) 2014-12-18 18:58:25 -08:00
Chirantan Ekbote 0c4cb0cc1b 33982: minimal support for pid namespaces by recognizing that GETPGRP() may return 0 2014-12-16 23:35:57 -08:00
Peter Stephenson d067ebcacd 33876: etc.: Separate errors and keyboards interrupts
Combination of 12 commits from interrupt_abort branch.

Basic strategy is to introduce bits to errflag and to set and
reset them separately.

Remove interrupt status on return to main keymap.

Turn off ERRFLAG_INT for always block.

Restore bit thereafter: we probably need a new variable in order
to allow user interrupts to be reset in the always block.

Add TRY_BLOCK_INTERRUPT

This works the same as TRY_BLOCK_ERROR, but for a SIGINT, too.

Ensure propagation of SIGINT from exited job.

If received by foreground job, shell uses ERRFLAG_INT, not
ERRFLAG_ERROR, to set the new state.

Reset errflag before precmd()

Add always block in _main_completion to fix ZLS_COLORS

Ensures we get the right state of $ZLS_COLORS at the end of _main_complete
even if there's an interrupt.  However, the "right state" is a bit messy
as it depends on styles.
2014-12-11 09:41:17 +00:00
Oliver Kiddle 6a29f66f8a unposted: quash compiler warning 2014-10-31 18:00:05 +01:00
Mikael Magnusson ed90154e58 33562: Fix thinko in previous commit 2014-10-27 20:54:20 +01:00
Mikael Magnusson ded97b8ed9 33561: The time builtin forgot to unmetafy TIMEFMT 2014-10-27 20:46:48 +01:00
Peter Stephenson b4f7ccecd9 33531 with additions: retain status of exited background jobs.
Add linked list of unwaited-for background jobs.
Truncate at value of _SC_CHILD_MAX discarding oldest.
Remove old lastpid_status mechanism for latest exited process only.
Slightly tighten safety of permanently allocated linked lists so
that this doesn't compromise signal handling.
2014-10-26 17:47:42 +00:00
Barton E. Schaefer a65fb0677c 33354: when backgrounding a pipeline, close all pipe descriptors in the parent
Add test for both this and 33345+33346
2014-10-04 21:08:56 -07:00
Barton E. Schaefer cb468501c9 33042: $? and $pipestatus report 128+signal number for stopped jobs 2014-08-22 09:12:23 -07:00
Peter Stephenson 880020ca2e 32624: use correct scaling factor (clock ticks) for times 2014-05-29 21:40:33 +01:00
Barton E. Schaefer 15f4843c67 32178: fix another acquire_pgrp() infinite loop 2013-12-25 16:20:49 -08:00
Peter Stephenson aede5c52bf 32176: plug additional deadlock-inducing pipe descriptor leaks 2013-12-21 17:41:21 -08:00
Barton E. Schaefer ed01d6e1e8 31929: Src/jobs.c: fix DPUTS3() test condition from 31906. 2013-10-29 09:28:20 -07:00
Barton E. Schaefer c3114a7735 31906: fix race-condition interaction of $pipestatus with job control
printjob() should not reference oldjobtab for job numbers unless it is being called from bin_fg().  printjob() also must not attempt to update pipestats when called from bin_fg().  acquire_pgrp() should not loop infintely if the shell is not interactive.  Update the $pipestatus stress test so that it also exercises the oldjobtab repair.
2013-10-26 16:11:40 -07:00
Barton E. Schaefer 5b30149638 31885: fix PIPEFAIL when the last command executes in the current shell 2013-10-24 17:31:13 -07:00