summaryrefslogtreecommitdiffstats
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-11-03 13:59:07 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-11-03 13:59:07 +0000
commite78648891926d9efb9e06fed253120c6ec2e6bb8 (patch)
treede2966852c103954b8d764b9ba16d82aed01cb9d /Src/exec.c
parent19209: Rename zcalloc to zshcalloc. (diff)
downloadzsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.gz
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.bz2
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.lz
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.xz
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.tar.zst
zsh-e78648891926d9efb9e06fed253120c6ec2e6bb8.zip
19216: save and restore $pipestatus.
19218: extend 19216 to zle widgets
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 81c6ac641..77b657c18 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3310,17 +3310,23 @@ loadautofn(Shfunc shf, int fksh, int autol)
return shf;
}
-/* execute a shell function */
+/*
+ * execute a shell function
+ *
+ * If noreturnval is nonzero, then reset the current return
+ * value (lastval) to its value before the shell function
+ * was executed. However, in any case return the status value
+ * from the function (i.e. if noreturnval is not set, this
+ * will be the same as lastval).
+ */
/**/
-mod_export void
+mod_export int
doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
-/* If noreturnval is nonzero, then reset the current return *
- * value (lastval) to its value before the shell function *
- * was executed. */
{
char **tab, **x, *oargv0;
- int oldzoptind, oldlastval, oldoptcind;
+ int oldzoptind, oldlastval, oldoptcind, oldnumpipestats, ret;
+ int *oldpipestats = NULL;
char saveopts[OPT_SIZE], *oldscriptname = scriptname, *fname = dupstring(name);
int obreaks;
struct funcstack fstack;
@@ -3335,6 +3341,16 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
if (trapreturn < 0)
trapreturn--;
oldlastval = lastval;
+ oldnumpipestats = numpipestats;
+ if (noreturnval) {
+ /*
+ * Easiest to use the heap here since we're bracketed
+ * immediately by a pushheap/popheap pair.
+ */
+ size_t bytes = sizeof(int)*numpipestats;
+ oldpipestats = (int *)zhalloc(bytes);
+ memcpy(oldpipestats, pipestats, bytes);
+ }
starttrapscope();
@@ -3440,9 +3456,15 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
if (trapreturn < -1)
trapreturn++;
- if (noreturnval)
+ ret = lastval;
+ if (noreturnval) {
lastval = oldlastval;
+ numpipestats = oldnumpipestats;
+ memcpy(pipestats, oldpipestats, sizeof(int)*numpipestats);
+ }
popheap();
+
+ return ret;
}
/* This finally executes a shell function and any function wrappers *