summaryrefslogtreecommitdiff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2016-10-05 12:14:43 +0100
committerPeter Stephenson <pws@zsh.org>2016-10-05 12:14:43 +0100
commitdc517212caf3a8263cea9587bc6e96f7ff129b59 (patch)
treeab199c0936a8de2bc3c3e81661f7cee6b0e0c2d8 /Src/exec.c
parent429f8ae71dc7f84b799a6d0a1f96716a7cde8806 (diff)
downloadzsh-dc517212caf3a8263cea9587bc6e96f7ff129b59.tar.gz
zsh-dc517212caf3a8263cea9587bc6e96f7ff129b59.zip
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.
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 9890286b2..f248ca288 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -568,11 +568,14 @@ commandnotfound(char *arg0, LinkList args)
Shfunc shf = (Shfunc)
shfunctab->getnode(shfunctab, "command_not_found_handler");
- if (!shf)
- return 127;
+ if (!shf) {
+ lastval = 127;
+ return 1;
+ }
pushnode(args, arg0);
- return doshfunc(shf, args, 1);
+ lastval = doshfunc(shf, args, 1);
+ return 0;
}
/*
@@ -703,7 +706,7 @@ execute(LinkList args, int flags, int defpath)
if (!search_defpath(arg0, pbuf, PATH_MAX)) {
if (commandnotfound(arg0, args) == 0)
- _exit(0);
+ _exit(lastval);
zerr("command not found: %s", arg0);
_exit(127);
}
@@ -767,7 +770,7 @@ execute(LinkList args, int flags, int defpath)
if (eno)
zerr("%e: %s", eno, arg0);
else if (commandnotfound(arg0, args) == 0)
- _exit(0);
+ _exit(lastval);
else
zerr("command not found: %s", arg0);
_exit((eno == EACCES || eno == ENOEXEC) ? 126 : 127);