1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-07-14 05:41:31 +02:00
Commit graph

428 commits

Author SHA1 Message Date
Peter Stephenson
bbccbe0c85 43660: extend 43653 when final exit is implicit.
Combine logic for case after committed to exit (shell_exiting) with
case where exit occurred in a function we nee to unwind (exit_pending).

Add sarky note for future generations to be confused at.
2018-10-09 14:38:26 +01:00
Daniel Shahaf
db67cc2f4b 43489: Add error checking on a new write() call.
Silences a compiler warning (write(2) is declared with warn_unused_result
in current Debian Unstable).
2018-09-25 19:35:15 +00: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
Anthony Sottile
1c4c7b6a4d
CVE-2018-0502, CVE-2018-13259: Fix two security issues in shebang line parsing.
See NEWS for more information.

Patch by Anthony Sottile and Buck Evan.
2018-09-03 15:07:47 +00:00
Peter Stephenson
3e9fc32fc3 43156, 43157: Need to allow for extra space in gethere().
The point can now increment twice per iteration.
2018-07-10 14:42:02 +01:00
Peter Stephenson
17178db1a4 users/23531: Error exit/return fixes.
Fix regression with trap on left hand side of pipe.

Fix forced return from shell structure within nested function.

Fix tests exiting too early.

Add new test case.
2018-07-09 11:07:53 +01:00
Peter Stephenson
9408c4825b users/23472: Add $sysparams[procsubstpid] to zsh/system 2018-06-15 15:02:36 +01:00
dana
805192311f 42101 (tweaked): assigning shell status to array was broken 2018-05-11 09:29:14 +01:00
Peter Stephenson
faf0035e53 unposted (branch fork_early): Fork early for pipelines.
If executing a command not at the end of a pipeline, and
not optimised in the calling code, we can fork before
"prefork" substitutions, at the same point as
for background commands.

Move fork before our preliminary scan of arguments to find
a command: in the cases of early fork
we don't need this information before forking.

Ensure we _exit if forked in execcmd_exec().

Rationalise use of forks and pipes.

Ensure we _exit instead of returning from execcmd_exec() if we
have forked.  Before the optimisation code after the fork always ran
to the check at the end, but that code is overkill for the logic
between the early fork and the existing one.

Remove old workaround to fork in caller of execcmd for current shell
constructs as no longer needed with early fork below.

Close input of newly created pipe on fork (destined for RHS of pipe
which we never execute): this replaces a workaround from
zsh-workers/32171, commit 9887fc3d7b.

Set last1 on early fork as needed by some instances of shell
constructs on LHS of pipeline to know they are exiting.
2018-05-01 10:27:35 +01:00
Ricardo Giorni
f7519811e1 47201: fix 42355 for multiple backslashes 2018-04-29 12:05:39 -07:00
Daniel Shahaf
76b5b3a504 unposted: Correct process substitution buffer size in the PATH_DEV_FD codepath. 2018-04-25 15:31:39 +00:00
Peter Stephenson
95d861d028 42708: fix for process substitution.
Don't close associated file descriptors in the closem()
tidy up function as they should remain visible to external
processes.  Override if about to exit.

Unit test for the failing case: note this relies on the
existence of /proc/self/fd or equivalent.
2018-04-24 11:48:11 +01:00
Peter Stephenson
9e2afb9298 42684 (with extra comments): Fork early if in bg.
In execcmd the case of running the last command in a pipeline
asynchronously for the purpose of & and &! is easy to work out,
and we can avoid side effects and unnecessary execution time in
the parent shell by forking earlier.
2018-04-20 10:36:39 +01:00
Peter Stephenson
3c74891fcd 42630: Improve process group handling in pipelines.
If process group leader exits, allow a newly forked process to become
process leader.  If a foreground job, reattach the shell to the
terminal until that happens.

Unblock signals when reading output for command subsitution so that
we can do this reattaching immediately.
2018-04-17 17:14:20 +01:00
Oliver Kiddle
65b265f3c0 42624 (plus test): avoid freeing memory that's still needed
This was occurring in a multiple function definition where a
function name is duplicated.
2018-04-12 23:15:29 +02:00
Oliver Kiddle
679b71ec4d 42518, CVE-2018-1071: check bounds when copying path in hashcmd() 2018-03-24 15:04:02 +01:00
Stephane Chazelas
d2350a1e80 42469: necessary repairs to 42465 found by "make check" 2018-03-18 16:49:42 -07:00
Stephane Chazelas
1219eae829 42465: Pass up error status from readoutput().
This improves the consistency of error reporting from $(...) constructs.
2018-03-15 09:21:47 +00:00
Peter Stephenson
47aa60950c 42355: Fix use of backslashes on here doc input.
Handling of white space in particular was confusing and inconsistent
with other shells.
2018-02-12 10:06:45 +00:00
Barton E. Schaefer
b476d89fa2 42043: ZSH_DEBUG_CMD should not WARN_CREATE_GLOBAL 2018-01-14 03:07:32 -08:00
Peter Stephenson
8ec3d17b4b 33395: Improvments for function managment.
Functions defined inside other fucntions needs file line number
adding.  Particularly useful for anonymous fucntions.

Add flag to indicate a function is anonymous.  Done up to now
by comparing the name to a pointer but this is more consistent.
2017-12-22 19:51:04 +00:00
Daniel Shahaf
a9e60dc179 users/13148 (and workers/42060): Abort the command line when replying
"[n] No" to the RM_STAR_SILENT prompt.

Patch by Stephane, rebased by Mikael.
2017-12-20 04:13:01 +00:00
Peter Stephenson
aab0f6d763 42123 (tweaked): take account of Dash in function names.
Needed when comparing word code function name with autoload request.

Add test.
2017-12-15 09:00:37 +00:00
Peter Stephenson
e573857a03 41802 (minor tweaks): use heap during shell function call.
Replaces stack for more efficient memory management.

Also fix debug message when FUNCNEST is increased.
2017-10-04 09:18:51 +01:00
Peter Stephenson
174e560a23 41787 (plus minor tweaks): use $FUNCSTACK for function nesting depth.
Initialised from existing configuration value.
2017-10-02 09:44:26 +01:00
Peter Stephenson
a1276c88e1 41789: Don't save fd if -1.
We try to move an fd which isn't opend but it will feel.
This needs handling specially in the new code for marking
saved fd's.
2017-09-29 16:29:49 +01:00
Barton E. Schaefer
7a0718796a 41767: preserve nonzero exit status on interrupt 2017-09-27 20:34:11 -07:00
Peter Stephenson
03af5fdbee 41761: Ensure status from interrupt is propagated by builtin 2017-09-26 09:26:57 +01:00
Peter Stephenson
85b0dd7133 Updates for ksh array element syntax.
Move detection of key/value pairs down into prefork().

Detect normal array assignment and [key]=val array assignemnt
separately.  Mark key / value pairs with Marker and pass up flag.  Deal
with marked triads specially later on.
2017-09-24 17:33:07 +01:00
Barton E. Schaefer
d1914c5af4 41736: NO_INTERACTIVE_COMMENTS in $(...) 2017-09-20 10:17:59 -07:00
Peter Stephenson
54b3958440 First go at var=([key]=value) syntax.
Works for both normal and typeset case, also var+=...

Still to do: allow to be mixed with straight array assignment,
improve typeset -p, implement [key]+=value.
2017-09-13 20:54:00 +01:00
Peter Stephenson
c9df6bc8d4 41662: exec -a arguments weren't sanitised 2017-09-10 18:02:52 +01:00
Peter Stephenson
7d1877da4e 41608 (plus tests): restore ERR_EXIT before function.
There was an exception to the usual ERR_EXIT pattern that causes
problems when executing a function in an else branch.  It seems
the exception is no longer needed as the regression tests pass
without it.
2017-08-29 19:52:18 +01:00
Peter Stephenson
97d4bdbc7e 41590 modified as 41595: make ERR_RETURN more logical.
It now operates separately at each function depth.

To keep ERR_EXIT global, make the noerrexit variable usd bit flags.

Extend tests.
2017-08-24 19:46:20 +01:00
Peter Stephenson
ddb8675901 posted but has not shown up: fix fd problem in subshell.
Record fd's that have been saved in fdtable and if the shell
forks close them as they will never be restored.
2017-08-15 20:49:23 +01:00
Peter Stephenson
d4b94b5e83 41464, 41466: With POSIX_BUILTINS, exec only executes sexternal commands.
Document the default behaviour and add a test.
2017-07-27 09:22:04 +01:00
Barton E. Schaefer
a5ed661f25 41317: use heap allocation in getoutputfile() to plug memory leak
Heap is usable ever since addfilelist() of workers/31528 (commit 3c573222).
2017-06-19 16:06:38 -07:00
Peter Stephenson
21b195562a 41043: Close pipes in shell when disowning background job.
This was missing in the case of &,, causing a file descriptor leak.
2017-05-03 11:30:15 +01:00
Peter Stephenson
ed4e37e45c 41020: Fix "command -p"; "-p" was incorrectly left in command arguments
Also add tests for known precommand modifier issues.
2017-04-28 10:22:43 +01:00
Peter Stephenson
d7110d8f01 41012: Fix premature exit from nested function in EXIT trap.
Also add check so we don't delay an exit if we were already in
an EXIT trap for the main shell, as we should in that case leave
immediately.
2017-04-27 18:56:18 +01:00
Peter Stephenson
408b92b168 41008: Handle expansions for precommand modifiers 2017-04-26 09:44:38 +01:00
Peter Stephenson
8b5102ccf5 40933: Ensure we get job text in sourced files.
This was turned off explicitly as it was assumed not to be needed,
but it is when code in a sourced file is suspended.

We'll need to see if this makes start up inefficient.
2017-04-04 18:54:10 +01:00
Peter Stephenson
64559abc1f 40796: MAGIC_EQUAL_SUBST not needed with parsed assignment.
If typeset family builtins are recognised as keywords then the value
is handled as a separate expansion and we don't need the old
magic behaviour, even if the option is set.
2017-03-09 09:52:23 +00:00
Peter Stephenson
f3f8537cfa 40760: Always tokenize unquoted - to Dash.
This fixes use of pattern match character ranges in unusual contexts.

Attempt to detect a tokenized - in cases where we don't care.
2017-03-07 10:43:58 +00:00
Barton E. Schaefer
5e61eaf855 40654: exit cleanly from special POSIXBUILTINS in subshells
This patch overloads the zsh_subshell counter which is meant for $ZSH_SUBSHELL, but no one has suggested a working alternate test.
2017-03-04 15:25:17 -08:00
Barton E. Schaefer
9f447578f0 40576 (tweaked): entersubsh(): unblock any signals that were blocked for trap handling
Also small improvement to loop that resets trap handlers
2017-02-20 13:26:49 -08:00
Peter Stephenson
c861b17bbf 40391: Add WARN_NESTED_VAR option and functions -W.
These are companions to WARN_CREATED_GLOBAL, warning when a variable
from an enclosing scope is altered.
2017-01-23 09:50:57 +00:00
Peter Stephenson
f90a0447aa 40353 with tweaks to whence -v: extend directory cache use.
Now used for all autoloaded functions after load, including those
where the file was found along fpath, reducing duplication of
directory names.
2017-01-16 10:31:56 +00:00
Peter Stephenson
178e62dbfe 40342: Add directory name cache for autoload file paths.
This renders "autoload /blah/blah/*" as efficient as use of
fpath.
2017-01-12 20:56:20 +00:00
Peter Stephenson
33799ae2b0 40335: More care with autoload function path.
If doing "autoload -X", the path present might actually be location
of file containing the function with the autoload -X.  Add
an explicit flag to say it's a directory for autoload.
2017-01-12 13:54:29 +00:00
Peter Stephenson
47b7f2adef unposted: more care with shell function filename.
When updating shfunc structure to change filename we should be
careful to free whatever's there already, we may now be the
directory in which to find the function definition.  After loading
the field contains the full name of the file.
2017-01-11 12:11:22 +00:00
Peter Stephenson
f26d1ba6b0 Add features associated with autoloading a function using an absolute
path.

-d defaults to normal fpath

-r remembers the path without actually loading.  May be combined with -d.

-R does the same but it's an error if not found

-X can now take a directory path: this is used to output not yet loaded
functions that have an associated path.
2017-01-11 11:26:13 +00:00
Peter Stephenson
0e4aa6f2f6 Additional case for ERR_RETURN and ERR_EXIT.
Don't trigger just because status is non-zero at end of
current shell group.
2016-12-05 12:29:23 +00:00
Peter Stephenson
c03228f9ed Extra case for ERR_RETURN and ERR_EXIT.
Don't trigger just because status is non-zero at end of
complex shell construct as this may be a case we've already
suppressed.
2016-12-05 11:21:01 +00:00
Peter Stephenson
a62e1640bc 39958: Add extra byte to PATH_MAX allocations.
This ensures we've got enough space for a null, although this
isn't always needed.
2016-11-17 19:49:17 +00:00
Daniel Shahaf
c392e6c620 39915: whence: Honor PATH_DIRS option for arguments that start with './' or '../'.
While here, add some docstrings.
2016-11-17 15:28:42 +00:00
Peter Stephenson
5f1700755f 39901: No EXIT trap on LHS of pipeline.
There is a special case if the LHS is a shell construct.
Add unit tests for both cases.
2016-11-10 10:37:27 +00:00
Peter Stephenson
bcb52460f3 39571: Fix ERR_EXIT bug with && and function.
"foo && bar" inside a function could cause the code outside
the function not to perform ERR_EXIT or ERR_RETURN when needed.
2016-10-05 17:46:42 +01:00
Peter Stephenson
0854ee56bc 39568: "! <complex-command>" suppresses ERR_EXIT 2016-10-05 13:52:31 +01:00
Peter Stephenson
dc517212ca 39566: Improve usefulness of command_not_found_handler.
Don't behave as if command not found if return status is non-zero

as this may simply be the return status of the replacement command.
Let the function report a command not found instead.
2016-10-05 12:14:43 +01:00
Peter Stephenson
4ab3fcc90d 39545: Add some missing unqueue_signals().
All of these are added simply to fit existing logic in other branches.
2016-10-03 13:43:20 +01:00
Peter Stephenson
36a11804b4 39521: Refactor start of execcmd().
By splitting into _analyse and _exec execpline2() has easier
access to the state at the start of execution.  Use this
to ensure we fork if this is a builtin with no arguments.
2016-10-03 09:59:01 +01:00
Peter Stephenson
6b2585147b 39540: "! command" should suppress ERR_EXIT and ERR_RETURN 2016-10-02 19:17:19 +01:00
Peter Stephenson
bb2bbcc944 39517: back off 39502 (WC_ASSIGN causes fork in pipe).
This isn't a robust fix as WC_ASSIGNs simply precede the main wordcode.
2016-09-30 11:34:15 +01:00
Barton E. Schaefer
736eb433ba 39507: TMPSUFFIX for =(...) 2016-09-29 14:55:49 -07:00
Barton E. Schaefer
e61ed2b80d 39470: failure to open a supposedly unique temp file name should result in an error
Also band-aid for signal-related race conditions in temp file name generation
2016-09-29 11:16:24 -07:00
Peter Stephenson
6ce696f352 39502: Fork for assignment in LHS of pipeline.
foo=bar | stuff

left the value of foo set to bar as we didn't realise we needed to
fork.
2016-09-29 17:29:58 +01:00
Peter Stephenson
07c8fbe596 34943: Fixes for "command" with multiple options.
These need to combine properly, and alos "command -p" with either
-v or -V needs to search for builtins and then using the default
system path.
2016-09-29 11:01:00 +01:00
Barton E. Schaefer
3b6002e53d 39437: use list_pipe_pid in assignment for clarity 2016-09-27 08:48:49 -07:00
Peter Stephenson
e35dcae40f 39436: Pass on status of SIGINT better.
Set lastval to 128 + SIGINT on interrupt.

Don't execute builtin if already interrupted at that point.
2016-09-25 19:18:43 +01:00
Peter Stephenson
759e5912fd 39435: Further fix for pgrp of funny pipelines.
Don't set gleader of SUBJOB at the point of creation if the
SUPERJOB has no processes yet.
2016-09-25 17:14:24 +01:00
Barton E. Schaefer
c8de0af359 39381: handle save/restore of variable values when "typeset"-related reserved words are prefixed by an assignment 2016-09-19 00:26:10 -07:00
Peter Stephenson
c355a5f41f 39362: another race with pipeline handling.
When forking the shell to control the right hand side, the
forked subshell now always starts its own process group, to
avoid getting a spurious additional SIGSTOP.
2016-09-16 21:55:55 +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
Peter Stephenson
23c1c774b9 39305: Fix error handling after parse for here document.
Keep the error status the same as before, but also retain
the interrupt status if that was non-zero.
2016-09-13 09:37:49 +01:00
Stephane Chazelas
8ce98c75f5 39125: More care needed decrementing SHLVL on exec.
Not needed in subshell.
2016-08-31 10:21:00 +01:00
Barton E. Schaefer
b312abc93b 39104: do not hash relative paths in findcmd() 2016-08-26 15:05:15 -07:00
Daniel Shahaf
f026a4dc12 38991: Make 'whence -v autoloaded-function' shows the defining filename.
This may also fix a problem whereby the %x prompt escape evaluated to
a function name rather than a filename, since %x is also backed by
scriptfilename.
2016-08-05 12:37:26 +00:00
Daniel Shahaf
7badf262c1 38653 + 38657: 'functions -T' tracing: recurse into anonymous functions. 2016-06-13 08:53:18 +00:00
Barton E. Schaefer
5ee05cf935 38350 (cf. Glenn Smith: 38348): Remove-all warning should warn about the root directory as well 2016-04-26 10:40:56 -07:00
Peter Stephenson
f4dfca490c 38114: Fix hang using ^Z with command subst.
In subshells started to perform substitutions disable signals
that require interactive handling.
2016-03-09 09:51:14 +00:00
Jun-ichi Takimoto
a4020e10a3 37868: add 'static' to file local variables 2016-02-03 01:25:33 +09:00
Barton E. Schaefer
5c17f9ab3f 37473: check for cshnullglob in command position. 2016-01-01 13:01:16 -08:00
Barton E. Schaefer
fc344465f2 37435 (+ fix typo): allow execution of empty files as "sh" scripts 2015-12-25 00:31:32 -08:00
Barton E. Schaefer
a554c7403a 37434: POSIXBUILTINS "command" should prevent shell exit on errors from special builtins 2015-12-25 00:26:26 -08:00
Peter Stephenson
e40a14c5e4 37202: suppress WARN_CREATE_GLOBAL warnings after a fork 2015-12-04 10:44:33 +00:00
Peter Stephenson
04479a56e0 unposted: fix init_io() calls in previous change 2015-12-04 09:42:35 +00:00
Peter Stephenson
830d54e629 37092: make nested ${(P)name} properly refer to parameter on return 2015-11-11 18:04:20 +00:00
Barton E. Schaefer
827d360776 36853: replace pushheap/popheap by NEWHEAPS/OLDHEAPS in doshfunc() to optimize memory management
Includes re-indentation that was not done in the posted patch.
2015-10-14 21:46:26 -07:00
Barton E. Schaefer
cb26e11c70 unposted: back out 36707, add test case for 36766 2015-10-03 22:11:09 -07:00
Barton E. Schaefer
b581c3fece 36766: fix incorrect reset of noerrexit during "if" conditions 2015-10-03 19:40:14 -07:00
Barton E. Schaefer
2bf4f667fb 36707: distinguish ERR_RETURN value of retflag so that execif() can ignore it in the test sublist 2015-09-30 20:01:13 -07:00
Daniel Shahaf
2654cb43f6 36651: WARN_CREATE_GLOBAL += math expressions
Without this, '() { (( x=42 )) }' and '() { for (( i=0; … )) }' wouldn't warn
about $x and $i, respectively, being created global.
2015-09-27 23:52:25 +00:00
Peter Stephenson
cdbd1b2581 36378: skip directories when looking for files to autoload 2015-09-02 20:19:28 +01: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
Barton E. Schaefer
9958684574 36022 fix bug that some loop constructs could not be interrupted, revise signal queueing
There are two underlying ideas here:  (1) Keeping signals queued around
anything that's doing memory management (including push/pop of the heap)
has become crucial.  (2) Anytime the shell is going to run a command, be
it buitin or external, it must be both safe and necessary to process any
queued signals, so that the apparent order of signal arrival and command
execution is preserved.
2015-08-09 16:13:52 -07: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