aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox/0001-ash-add-support-for-command_not_found_handle-hook-fu.patch
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-10-20 05:55:08 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2017-10-20 05:55:51 +0000
commitdcad9af52a05da2ee6f3b12bcbb23c225b95417a (patch)
tree4e64dab8df9bf880e05cb2d322e6767b4c333e41 /main/busybox/0001-ash-add-support-for-command_not_found_handle-hook-fu.patch
parent30e67c63dba1de11cfe9a7af61304af3e00a3eff (diff)
downloadaports-dcad9af52a05da2ee6f3b12bcbb23c225b95417a.tar.bz2
aports-dcad9af52a05da2ee6f3b12bcbb23c225b95417a.tar.xz
main/busybox: ash: add support for bash-style command_not_found_handle hook function
This implements support for the command_not_found_handle hook function, which is useful for allowing package managers to suggest packages which could provide the command. Unlike bash, however, we ignore exit codes from the hook function and always return the correct POSIX error code (EX_NOTFOUND).
Diffstat (limited to 'main/busybox/0001-ash-add-support-for-command_not_found_handle-hook-fu.patch')
-rw-r--r--main/busybox/0001-ash-add-support-for-command_not_found_handle-hook-fu.patch63
1 files changed, 63 insertions, 0 deletions
diff --git a/main/busybox/0001-ash-add-support-for-command_not_found_handle-hook-fu.patch b/main/busybox/0001-ash-add-support-for-command_not_found_handle-hook-fu.patch
new file mode 100644
index 0000000000..e4ba6ece5b
--- /dev/null
+++ b/main/busybox/0001-ash-add-support-for-command_not_found_handle-hook-fu.patch
@@ -0,0 +1,63 @@
+From f76c1ddd625b3d9912d9e6df2e90fcb94d08be99 Mon Sep 17 00:00:00 2001
+From: William Pitcock <nenolod@dereferenced.org>
+Date: Thu, 19 Oct 2017 17:24:40 +0000
+Subject: [PATCH] ash: add support for command_not_found_handle hook function,
+ like bash
+
+This implements support for the command_not_found_handle hook function, which is
+useful for allowing package managers to suggest packages which could provide the
+command.
+
+Unlike bash, however, we ignore exit codes from the hook function and always return
+the correct POSIX error code (EX_NOTFOUND).
+
+Signed-off-by: William Pitcock <nenolod@dereferenced.org>
+---
+ shell/ash.c | 24 ++++++++++++++++++++++--
+ 1 file changed, 22 insertions(+), 2 deletions(-)
+
+diff --git a/shell/ash.c b/shell/ash.c
+index 88e607f08..c3c4f4e93 100644
+--- a/shell/ash.c
++++ b/shell/ash.c
+@@ -132,6 +132,15 @@
+ //config: you to run the specified command or builtin,
+ //config: even when there is a function with the same name.
+ //config:
++//config:config ASH_COMMAND_NOT_FOUND_HOOK
++//config: bool "command_not_found_handle hook support"
++//config: default y
++//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
++//config: help
++//config: Enable support for the 'command_not_found_handle' hook function,
++//config: from GNU bash, which allows for alternative command not found
++//config: handling.
++//config:
+ //config:endif # ash options
+
+ //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
+@@ -13123,8 +13132,19 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
+ /* We failed. If there was an entry for this command, delete it */
+ if (cmdp && updatetbl)
+ delete_cmd_entry();
+- if (act & DO_ERR)
+- ash_msg("%s: %s", name, errmsg(e, "not found"));
++ if (act & DO_ERR) {
++#ifdef CONFIG_ASH_COMMAND_NOT_FOUND_HOOK
++#define HOOKFN_NAME "command_not_found_handle"
++ char hookfn_name[] = HOOKFN_NAME;
++ struct tblentry *hookp = cmdlookup(hookfn_name, 0);
++ if (hookp != NULL && hookp->cmdtype == CMDFUNCTION) {
++ evalfun(hookp->param.func, 2, (char *[]){ hookfn_name, name }, 0);
++ entry->cmdtype = CMDUNKNOWN;
++ return;
++ } else
++#endif
++ ash_msg("%s: %s", name, errmsg(e, "not found"));
++ }
+ entry->cmdtype = CMDUNKNOWN;
+ return;
+
+--
+2.14.2
+