| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
zsh typically runs the final command in a pipeline in the main shell
instead of a subshell. However, POSIX specifies that all commands in a
pipeline run in a subshell, but permits zsh's behavior as an extension.
The default /bin/sh implementations on various Linux distros and the
BSDs always use a subshell for all components of a pipeline.
Since zsh may be used as /bin/sh in some cases (such as macOS Catalina),
it makes sense to have the common sh behavior when emulating sh, so do
that by checking for being the final item of a multi-item pipeline and
creating a subshell in that case.
From the comment above execpline(), we know the following:
last1 is a flag that this command is the last command in a shell that
is about to exit, so we can exec instead of forking. It gets passed
all the way down to execcmd() which actually makes the decision. A 0
is always passed if the command is not the last in the pipeline. […]
If last1 is zero but the command is at the end of a pipeline, we pass
2 down to execcmd().
So there are three cases to consider in this code:
• last1 is 0, which means we are not at the end of a pipeline, in which
case we should not change behavior.
• last1 is 1, which means we are effectively running in a subshell,
because nothing that happens due to the exec is going to affect the
actual shell, since it will have been replaced. So there is nothing
to do here.
• last1 is 2, which means our command is at the end of the pipeline, so
in sh mode we should create a subshell by forking.
input is nonzero if the input to this process is a pipe that we've
opened. At the end of a multi-stage pipeline, it will necessarily be
nonzero.
Note that several of the tests may appear bizarre, since most developers
do not place useless variable assignments directly at the end of a
pipeline. However, as the function tests demonstrate, there are cases
where assignments may occur when a shell function is used at the end of
a command. The remaining assignment tests simply test additional cases,
such as the use of local, that would otherwise be untested.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This change modifies the zsh binary safety check surrounding execve() so
it can run shell scripts having concatenated binary content. We're using
the same safety check as FreeBSD /bin/sh [1]. POSIX was recently revised
to require this behavior:
"The input file may be of any type, but the initial portion of the
file intended to be parsed according to the shell grammar (XREF to
XSH 2.10.2 Shell Grammar Rules) shall consist of characters and
shall not contain the NUL character. The shell shall not enforce
any line length limits."
"Earlier versions of this standard required that input files to the
shell be text files except that line lengths were unlimited.
However, that was overly restrictive in relation to the fact that
shells can parse a script without a trailing newline, and in
relation to a common practice of concatenating a shell script
ending with an 'exit' or 'exec $command' with a binary data payload
to form a single-file self-extracting archive." [2] [3]
One example use case of such scripts, is the Cosmopolitan C Library [4]
which configuse the GNU Linker to output a polyglot shell+binary format
that runs on Linux / Mac / Windows / FreeBSD / OpenBSD.
[1] https://github.com/freebsd/freebsd-src/commit/9a1cd363318b7e9e70ef6af27d1675b371c16b1a
[2] http://austingroupbugs.net/view.php?id=1250
[3] http://austingroupbugs.net/view.php?id=1226#c4394
[4] https://justine.lol/cosmopolitan/index.html
|
|
|
|
|
|
|
| |
From nice(2):
To detect an error, set errno to 0 before the call, and check
whether it is nonzero after nice() returns -1.
|
| |
|
| |
|
|
|
|
|
| |
When running a function, remove special files used for substitution
after the function has run rather than before.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
functions as though they were a single function named "(anon)".
Before:
% zmodload zsh/zprof
% () :
% () :
% zprof
num calls time self name
-----------------------------------------------------------------------------------
1) 2 0.08 0.04 100.00% 0.08 0.04 100.00% (anon)
After:
% zmodload zsh/zprof
% () :
% () :
% zprof
num calls time self name
-----------------------------------------------------------------------------------
1) 1 0.04 0.04 50.45% 0.04 0.04 50.45% (anon) [:3]
2) 1 0.04 0.04 49.55% 0.04 0.04 49.55% (anon) [:2]
|
|
|
|
| |
Config/version.mk was bumped in the previous commit.
|
| |
|
|
|
|
| |
The value is overwritten five lines below, without being read in the interim.
|
|\
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
* Test/D02glob.ztst:
On the "unreadable directories can be globbed (users/24619, users/24626)"
test, resolve conflicts by removing the Cygwin-only skip that has been added
in master, since the test is passing on this branch. This effectively reverts
workers/45492. See discussion starting in workers/45504.
* origin/master:
unposted: Remove 'sgi', as that OpenBSD port has been discontinued.
45509: fix typos in B01cd.ztst
45490 (+45495 and a test): refactor rlimits.c
github #49: Fix typo: longson should be loongson
users/24710: Fix job control problem with sudo.
45492: skip test added by users/24633 on Cygwin
45488: COMP_WORDS for bash need "$@"-style quoting
45487: Missing mod_export declarations for AIX
45447: Complete vcs_info_hookadd and vcs_info_hookdel. Expose _vcs_info_hooks as a top-level helper function.
45463: test: kill: Document why we use SIGURG
45453: builtins: kill: Do not signal current process group when pid is empty
45452: builtins: kill: Add `kill ''` regression test with explicit sigspec
45451: builtins: kill: Add basic test suite
github #48/0002: vcs_info git: properly detect bare repositories
github #48/0001: vcs_info git: avoid warnings in bare repositories
unposted: Post-release version bump
unposted: Release 5.8
CVE-2019-20044: Update change log for preceding commits
Update NEWS/README
Add unsetopt/PRIVILEGED tests
Clean up error-message white space
Improve PRIVILEGED fixes (again)
Improve PRIVILEGED fixes
Drop privileges securely
unposted: V01zmodload: Fix failing test from workers/45385
45423: _su: Improve arg handling, shell look-ups
unposted: _zip: Recognise '--'
45385: Add a test for 'zmodload -Fa' preemptively disabling ("blacklisting"?) features.
unposted: Test release: 5.7.1-test-3
zsh/system: Fix infinite loop in sysread
_diff_options: Restore -w completion lost in workers/43351
unposted: Fix ChangeLog typo.
45368: Add tests for workers/45367's issue about double slashes in 'cd -P' and /home/daniel/in/zsh.
45373: Fix ERR_EXIT bug in else branch of if.
45372: Record a symlink loop bug involving :P
45365: _git: Fix __git_recent_branches for the case when a commit has an empty message
45343: Queue signals around arithmetic evaluations
45344: Document where third-party completion functions should be installed.
45345: internal: ztst.vim: Fix highlighting of zsh comments in test payload
unposted: internal: Add some comments and fix indentation. No functional change.
45340: internal: Document the difference between paramtab and realparamtab.
45332: _git: add completion for git-version
_brace_parameter: add missing \
Conflicts:
ChangeLog
Test/D02glob.ztst
Test/V01zmodload.ztst
|
| |
| |
| |
| |
| |
| |
| | |
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.
|
| |
| |
| |
| |
| | |
The queueing added in execarith() in 45083 is reverted since the callee
does this now.
|
|/
|
|
|
| |
This makes it easy to apply local tracing ('functions -T') to autoloadable
functions that redefines themselves when first loaded.
|
|
|
|
|
| |
Otherwise we could get re-entrancy in memory functions when
setting variables.
|
| |
|
|
|
|
| |
"from_where" parameter. No functional change.
|
|
|
|
| |
This could cause a signal received during $(...) to corrupt memory.
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
| |
These are descriptors marked FDT_EXTERNAL.
Make all sysopen'ed file descriptors FDT_EXTERNAL.
Make =(...) call closem() consistent with other substitutions.
Document file descriptors are left open.
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
Silences a compiler warning (write(2) is declared with warn_unused_result
in current Debian Unstable).
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
Fix additional races by passing back use of list_pipe_job
from subshell.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
See NEWS for more information.
Patch by Anthony Sottile and Buck Evan.
|
|
|
|
| |
The point can now increment twice per iteration.
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
This was occurring in a multiple function definition where a
function name is duplicated.
|
| |
|
| |
|
|
|
|
| |
This improves the consistency of error reporting from $(...) constructs.
|
|
|
|
|
| |
Handling of white space in particular was confusing and inconsistent
with other shells.
|
| |
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
"[n] No" to the RM_STAR_SILENT prompt.
Patch by Stephane, rebased by Mikael.
|