about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-07-13 10:09:06 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-07-13 10:09:06 +0000
commiteea6647c658b56cd9fb99544e4c96b3628d0cd79 (patch)
tree0f14eae7f41cdf8a2bdae3bcbac87f7397092d2e /Src/exec.c
parenta1374319dcdd81c66aae6bc8cc0adc0889943cd1 (diff)
downloadzsh-eea6647c658b56cd9fb99544e4c96b3628d0cd79.tar.gz
zsh-eea6647c658b56cd9fb99544e4c96b3628d0cd79.tar.xz
zsh-eea6647c658b56cd9fb99544e4c96b3628d0cd79.zip
23671: command not found handler
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c23
1 files changed, 23 insertions, 0 deletions
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);