summaryrefslogtreecommitdiff
path: root/Src/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 5b17371bb..2d9f7ed26 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3436,17 +3436,22 @@ 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, oldnumpipestats;
+ int oldzoptind, oldlastval, oldoptcind, oldnumpipestats, ret;
int *oldpipestats = NULL;
char saveopts[OPT_SIZE], *oldscriptname = scriptname, *fname = dupstring(name);
int obreaks;
@@ -3577,6 +3582,7 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
if (trapreturn < -1)
trapreturn++;
+ ret = lastval;
if (noreturnval) {
lastval = oldlastval;
numpipestats = oldnumpipestats;
@@ -3599,6 +3605,8 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
zexit(exit_pending >> 1, 0);
}
}
+
+ return ret;
}
/* This finally executes a shell function and any function wrappers *