From dc517212caf3a8263cea9587bc6e96f7ff129b59 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 5 Oct 2016 12:14:43 +0100 Subject: 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. --- Src/exec.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'Src') 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); -- cgit 1.4.1