PATCH: _exit in zexecve when the interpreter doesn't work

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
---

Otherwise we keep searching path after printing the error message, which is
unexpected. I checked what bash does here and it also returns 126 and stops
searching, which seems more reasonable.

Reported on IRC:

23:35:26 <bitblt> Having two identically named scripts in the path, e.g. 
with PATH having both ~/.bin and /usr/local/bin in it and a foobar script 
existing in both ~/.bin and /usr/local/bin, if I have a 'bad' shebang in 
the first one of them, like a non-existing interpreter path, then it 
prints the error, and continues to try and execute the next 
similarily-named script in the path successfully?
23:35:42 <bitblt> Is this expected zsh functionality? Bash just errors out 
and stops
23:42:51 <Riviera> bitblt: that's apparently indeed what zsh does. how 
weird.
23:43:37 <Riviera> bitblt: fwiw i do not see it documented or 
configurable, but i really don't have a clue about zsh. i'm pretty certain 
though that i'd not want this behaviour.
23:43:43 <bitblt> Is this a bug or some kind of weird feature that is by 
default on?
23:44:38 <bitblt> yeah this caught me off guard too, and I almost blamed 
another thing before I discover this behavior
23:53:18 <Mikachu> it's because the missing interpreter sets the errno to 
ENOENT which is (mis)interpreted as "no file was found at this path entry, 
keep searching"

 Src/exec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index 8216ca727d..f5a615b182 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -557,10 +557,11 @@ zexecve(char *pth, char **argv, char **newenvp)
 		    for (t0 = 0; t0 != ct; t0++)
 			if (execvebuf[t0] == '\n')
 			    break;
-		    if (t0 == ct)
+		    if (t0 == ct) {
 			zerr("%s: bad interpreter: %s: %e", pth,
 			     metafy(execvebuf + 2, -1, META_STATIC), eno);
-		    else {
+			_exit(126);
+		    } else {
 			while (inblank(execvebuf[t0]))
 			    execvebuf[t0--] = '\0';
 			for (ptr = execvebuf + 2; *ptr && *ptr == ' '; ptr++);
@@ -584,6 +585,7 @@ zexecve(char *pth, char **argv, char **newenvp)
 			    }
 			    zerr("%s: bad interpreter: %s: %e", pth,
 				 metafy(ptr2, -1, META_STATIC), eno);
+			    _exit(126);
 			} else if (*ptr) {
 			    *ptr = '\0';
 			    argv[-2] = ptr2;
-- 
2.38.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.