summaryrefslogtreecommitdiffstats
path: root/common/hush.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-04-13 14:02:47 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-04-18 20:14:12 +0800
commit071ceba1e38f93ba2d937ae7fad037c5a9493655 (patch)
tree82b4377286c1c701e5a27e4d41b2ad06e1356e5c /common/hush.c
parent733d85510c74d9638dc88e001f45412f30a2f3d0 (diff)
downloadbarebox-071ceba1e38f93ba2d937ae7fad037c5a9493655.tar.gz
barebox-071ceba1e38f93ba2d937ae7fad037c5a9493655.tar.xz
Introduce binfmt support
This will allow to execute any file and detect it's type to handle it. This will allow to use shell for bootp bootfile or dfu. You can register multiple hook for the same filetype. They will be execute in the invert order of register. If a hook does not handle the file you just return -ERESTARTNOHAND; This is only available with hush parser. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'common/hush.c')
-rw-r--r--common/hush.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/common/hush.c b/common/hush.c
index 053d9a583e..2d89f2b3f2 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -124,6 +124,8 @@
#include <libbb.h>
#include <magicvar.h>
#include <linux/list.h>
+#include <binfmt.h>
+#include <init.h>
/*cmd_boot.c*/
extern int do_bootd(int flag, int argc, char *argv[]); /* do_bootd */
@@ -572,8 +574,6 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi)
int nextin;
struct child_prog *child;
char *p;
- char *path;
- int ret;
# if __GNUC__
/* Avoid longjmp clobbering */
(void) &i;
@@ -642,16 +642,7 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi)
if (!strcmp(child->argv[i], "getopt"))
return builtin_getopt(ctx, child);
#endif
- if (strchr(child->argv[i], '/')) {
- return execute_script(child->argv[i], child->argc-i, &child->argv[i]);
- }
- if ((path = find_execable(child->argv[i]))) {
- ret = execute_script(path, child->argc-i, &child->argv[i]);
- free(path);
- return ret;
- }
-
- return execute_command(child->argc - i, &child->argv[i]);
+ return execute_binfmt(child->argc - i, &child->argv[i]);
}
return -1;
}
@@ -1749,6 +1740,22 @@ BAREBOX_MAGICVAR(PATH, "colon seperated list of pathes to search for executables
BAREBOX_MAGICVAR(PS1, "hush prompt");
#endif
+static int binfmt_sh_excute(struct binfmt_hook *b, char *file, int argc, char **argv)
+{
+ return execute_script(file, argc, argv);
+}
+
+static struct binfmt_hook binfmt_sh_hook = {
+ .type = filetype_sh,
+ .hook = binfmt_sh_excute,
+};
+
+static int binfmt_sh_init(void)
+{
+ return binfmt_register(&binfmt_sh_hook);
+}
+fs_initcall(binfmt_sh_init);
+
/**
* @file
* @brief A prototype Bourne shell grammar parser