From 071ceba1e38f93ba2d937ae7fad037c5a9493655 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Fri, 13 Apr 2012 14:02:47 +0800 Subject: 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 --- common/hush.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'common/hush.c') 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 #include #include +#include +#include /*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 -- cgit v1.2.3