aboutsummaryrefslogtreecommitdiff
path: root/win32/process.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-07-21 08:33:25 +0100
committerRon Yorston <rmy@pobox.com>2017-07-21 08:33:25 +0100
commitac181bf548a3dd1aabaf8263d255936f66866cc7 (patch)
treed8142b74b8567a1ca2e45503959b22cbd1858d25 /win32/process.c
parent304e170c10b459bf6913da2924f8b362f104884d (diff)
downloadbusybox-w32-ac181bf548a3dd1aabaf8263d255936f66866cc7.tar.gz
busybox-w32-ac181bf548a3dd1aabaf8263d255936f66866cc7.tar.bz2
busybox-w32-ac181bf548a3dd1aabaf8263d255936f66866cc7.zip
win32: simplify spawning applets
The original WIN32 code used the BUSYBOX_APPLET_NAME environment variable to pass the applet name to the spawned process. This was based on the (apparently) mistaken idea that WIN32 would replace argv[0] with the path to the executable.
Diffstat (limited to 'win32/process.c')
-rw-r--r--win32/process.c28
1 files changed, 4 insertions, 24 deletions
diff --git a/win32/process.c b/win32/process.c
index 9a4b05597..6b579637d 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -237,19 +237,10 @@ spawnveq(int mode, const char *path, const char *const *argv, const char *const
237 237
238static intptr_t 238static intptr_t
239mingw_spawn_applet(int mode, 239mingw_spawn_applet(int mode,
240 const char *applet,
241 const char *const *argv, 240 const char *const *argv,
242 const char *const *envp) 241 const char *const *envp)
243{ 242{
244 char **env = copy_environ(envp); 243 return spawnveq(mode, bb_busybox_exec_path, argv, envp);
245 char path[MAX_PATH+20];
246 intptr_t ret;
247
248 sprintf(path, "BUSYBOX_APPLET_NAME=%s", applet);
249 env = env_setenv(env, path);
250 ret = spawnveq(mode, get_busybox_exec_path(), argv, (const char *const *)env);
251 free_environ(env);
252 return ret;
253} 244}
254 245
255static intptr_t 246static intptr_t
@@ -275,7 +266,7 @@ mingw_spawn_interpreter(int mode, const char *prog, const char *const *argv, con
275 266
276 if (ENABLE_FEATURE_PREFER_APPLETS && find_applet_by_name(interpr) >= 0) { 267 if (ENABLE_FEATURE_PREFER_APPLETS && find_applet_by_name(interpr) >= 0) {
277 new_argv[0] = interpr; 268 new_argv[0] = interpr;
278 ret = mingw_spawn_applet(mode, interpr, new_argv, envp); 269 ret = mingw_spawn_applet(mode, new_argv, envp);
279 } 270 }
280 else { 271 else {
281 char *path = xstrdup(getenv("PATH")); 272 char *path = xstrdup(getenv("PATH"));
@@ -303,7 +294,7 @@ mingw_spawn_1(int mode, const char *cmd, const char *const *argv, const char *co
303 294
304 if (ENABLE_FEATURE_PREFER_APPLETS && 295 if (ENABLE_FEATURE_PREFER_APPLETS &&
305 find_applet_by_name(cmd) >= 0) 296 find_applet_by_name(cmd) >= 0)
306 return mingw_spawn_applet(mode, cmd, argv, envp); 297 return mingw_spawn_applet(mode, argv, envp);
307 else if (is_absolute_path(cmd)) 298 else if (is_absolute_path(cmd))
308 return mingw_spawn_interpreter(mode, cmd, argv, envp); 299 return mingw_spawn_interpreter(mode, cmd, argv, envp);
309 else { 300 else {
@@ -362,18 +353,7 @@ mingw_execve(const char *cmd, const char *const *argv, const char *const *envp)
362 int ret; 353 int ret;
363 int mode = P_WAIT; 354 int mode = P_WAIT;
364 355
365 if (ENABLE_FEATURE_PREFER_APPLETS && 356 ret = (int)mingw_spawn_interpreter(mode, cmd, argv, envp);
366 find_applet_by_name(cmd) >= 0)
367 ret = mingw_spawn_applet(mode, cmd, argv, envp);
368 /*
369 * execve(bb_busybox_exec_path, argv, envp) won't work
370 * because argv[0] will be replaced to bb_busybox_exec_path
371 * by MSVC runtime
372 */
373 else if (argv && cmd != argv[0] && cmd == bb_busybox_exec_path)
374 ret = mingw_spawn_applet(mode, argv[0], argv, envp);
375 else
376 ret = mingw_spawn_interpreter(mode, cmd, argv, envp);
377 if (ret != -1) 357 if (ret != -1)
378 exit(ret); 358 exit(ret);
379 return ret; 359 return ret;