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. --- win32/process.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'win32/process.c') diff --git a/win32/process.c b/win32/process.c index 097a1d71c..e3ce95ca0 100644 --- a/win32/process.c +++ b/win32/process.c @@ -53,14 +53,7 @@ pid_t mingw_wait3(pid_t pid, int *status, int options, struct rusage *rusage) return -1; } -typedef struct { - char *path; - char *name; - char *opts; - char buf[100]; -} interp_t; - -static int +int FAST_FUNC parse_interpreter(const char *cmd, interp_t *interp) { char *path, *t; -- cgit v1.2.3-55-g6feb