From 4b7b4a960bab5b3e331e130b257fe8280fd9da43 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 19 Aug 2024 08:06:19 +0100 Subject: ash: optimise running of scripts The BusyBox shell detects certain cases where forking a command is unnecessary (last command in a script or subshell, for example) and calls execve(2) instead. This doesn't help in the Windows port because execve(2) is implemented by creating a process. There is one case where it is possible to apply this optimisation: if the command is a script and the script interpreter is an applet. - Have evalcommand() pass a flag to indicate this situation to shellexec(). Also, allocate two spare elements before the start of the argv array. - If the flag is TRUE shellexec() passes the shell's PATH variable down to tryexec() so it can perform a test for applet override. - If tryexec() finds that all the necessary conditions apply it can run a script by directly invoking the interpreter's main(). Adds 192-224 bytes. --- include/mingw.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/mingw.h b/include/mingw.h index adb810ec5..ed7884e39 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -566,6 +566,14 @@ int utimes(const char *file_name, const struct timeval times[2]); #define is_unc_path(x) (strlen(x) > 4 && is_dir_sep(x[0]) && \ is_dir_sep(x[1]) && !is_dir_sep(x[2])) +typedef struct { + char *path; + char *name; + char *opts; + char buf[100]; +} interp_t; + +int FAST_FUNC parse_interpreter(const char *cmd, interp_t *interp); char ** FAST_FUNC grow_argv(char **argv, int n); pid_t FAST_FUNC mingw_spawn(char **argv); intptr_t FAST_FUNC mingw_spawn_detach(char **argv); -- cgit v1.2.3-55-g6feb