From eea6647c658b56cd9fb99544e4c96b3628d0cd79 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 13 Jul 2007 10:09:06 +0000 Subject: 23671: command not found handler --- Src/exec.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Src') diff --git a/Src/exec.c b/Src/exec.c index 015753a83..ad088001e 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -468,6 +468,25 @@ isgooderr(int e, char *dir) e != ENOENT && e != ENOTDIR); } +/* + * Attempt to handle command not found. + * Return 0 if the condition was handled, non-zero otherwise. + */ + +/**/ +static int +commandnotfound(char *arg0, LinkList args) +{ + Shfunc shf = (Shfunc) + shfunctab->getnode(shfunctab, "command_not_found_handler"); + + if (!shf) + return 127; + + pushnode(args, arg0); + return doshfunc(shf->node.nam, shf->funcdef, args, shf->node.flags, 1); +} + /* execute an external command */ /**/ @@ -562,6 +581,8 @@ execute(LinkList args, int flags, int defpath) } if (!ps) { + if (commandnotfound(arg0, args) == 0) + _exit(0); zerr("command not found: %s", arg0); _exit(127); } @@ -624,6 +645,8 @@ execute(LinkList args, int flags, int defpath) if (eno) zerr("%e: %s", eno, arg0); + else if (commandnotfound(arg0, args) == 0) + _exit(0); else zerr("command not found: %s", arg0); _exit((eno == EACCES || eno == ENOEXEC) ? 126 : 127); -- cgit 1.4.1