diff options
author | Peter Stephenson <pws@zsh.org> | 2016-10-05 12:14:43 +0100 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2016-10-05 12:14:43 +0100 |
commit | dc517212caf3a8263cea9587bc6e96f7ff129b59 (patch) | |
tree | ab199c0936a8de2bc3c3e81661f7cee6b0e0c2d8 /Src | |
parent | 429f8ae71dc7f84b799a6d0a1f96716a7cde8806 (diff) | |
download | zsh-dc517212caf3a8263cea9587bc6e96f7ff129b59.tar.gz zsh-dc517212caf3a8263cea9587bc6e96f7ff129b59.tar.xz 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')
-rw-r--r-- | Src/exec.c | 13 |
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); |