aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-05-04 14:26:39 +0100
committerRon Yorston <rmy@pobox.com>2022-05-04 14:27:32 +0100
commit9e535b09a70a1ef7a2260e6d6955f7bbf291a08f (patch)
treeb07f66df7442bcc119e9b62e113ad4cc1d4aa32e
parent386fd4d71956d16b1e649c3b3e14f75e84e40310 (diff)
downloadbusybox-w32-9e535b09a70a1ef7a2260e6d6955f7bbf291a08f.tar.gz
busybox-w32-9e535b09a70a1ef7a2260e6d6955f7bbf291a08f.tar.bz2
busybox-w32-9e535b09a70a1ef7a2260e6d6955f7bbf291a08f.zip
win32: revert changes related to environment variables
Revert the change to mingw_putenv() in the previous commit. When compiling for MSVCRT (i.e. not for UCRT) revert some of the changes from commit 5b48ca53b (win32: pass NULL to spawnve, not environ). (GitHub issue #250)
-rw-r--r--win32/env.c20
-rw-r--r--win32/process.c13
2 files changed, 21 insertions, 12 deletions
diff --git a/win32/env.c b/win32/env.c
index 5de581e3d..4d4e9c8fd 100644
--- a/win32/env.c
+++ b/win32/env.c
@@ -78,7 +78,7 @@ int clearenv(void)
78 78
79int mingw_putenv(const char *env) 79int mingw_putenv(const char *env)
80{ 80{
81 char *s; 81 char *s, **envp;
82 int ret = 0; 82 int ret = 0;
83 83
84 if ( (s=strchr(env, '=')) == NULL ) { 84 if ( (s=strchr(env, '=')) == NULL ) {
@@ -90,13 +90,17 @@ int mingw_putenv(const char *env)
90 return _putenv(env); 90 return _putenv(env);
91 } 91 }
92 else { 92 else {
93 /* set empty value using WIN32 API*/ 93 /* set empty value by setting a non-empty one then truncating */
94 char *name = xstrdup(env); 94 char *envstr = xasprintf("%s0", env);
95 name[s - env] = '\0'; 95 ret = _putenv(envstr);
96 SetEnvironmentVariable(name, ""); 96
97 free(name); 97 for (envp = environ; *envp; ++envp) {
98 /* set a dummy variable to force CRT housekeeping */ 98 if (strcmp(*envp, envstr) == 0) {
99 _putenv("BB_DUMMY=0"); 99 (*envp)[s - env + 1] = '\0';
100 break;
101 }
102 }
103 free(envstr);
100 } 104 }
101 105
102 return ret; 106 return ret;
diff --git a/win32/process.c b/win32/process.c
index d4ab07ad8..5978226f0 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -345,27 +345,32 @@ mingw_spawnvp(int mode, const char *cmd, char *const *argv)
345{ 345{
346 char *prog; 346 char *prog;
347 intptr_t ret; 347 intptr_t ret;
348#if !defined(_UCRT)
349 char *const *envp = environ;
350#else
351 char *const *envp = NULL;
352#endif
348 353
349#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1 354#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1
350 if (find_applet_by_name(cmd) >= 0) 355 if (find_applet_by_name(cmd) >= 0)
351 return mingw_spawn_applet(mode, argv, NULL); 356 return mingw_spawn_applet(mode, argv, envp);
352 else 357 else
353#endif 358#endif
354 if (has_path(cmd)) { 359 if (has_path(cmd)) {
355 char *path = alloc_system_drive(cmd); 360 char *path = alloc_system_drive(cmd);
356 add_win32_extension(path); 361 add_win32_extension(path);
357 ret = mingw_spawn_interpreter(mode, path, argv, NULL, 0); 362 ret = mingw_spawn_interpreter(mode, path, argv, envp, 0);
358 free(path); 363 free(path);
359#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1 364#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1
360 if (ret == -1 && unix_path(cmd) && 365 if (ret == -1 && unix_path(cmd) &&
361 find_applet_by_name(bb_basename(cmd)) >= 0) { 366 find_applet_by_name(bb_basename(cmd)) >= 0) {
362 return mingw_spawn_applet(mode, argv, NULL); 367 return mingw_spawn_applet(mode, argv, envp);
363 } 368 }
364#endif 369#endif
365 return ret; 370 return ret;
366 } 371 }
367 else if ((prog=find_first_executable(cmd)) != NULL) { 372 else if ((prog=find_first_executable(cmd)) != NULL) {
368 ret = mingw_spawn_interpreter(mode, prog, argv, NULL, 0); 373 ret = mingw_spawn_interpreter(mode, prog, argv, envp, 0);
369 free(prog); 374 free(prog);
370 return ret; 375 return ret;
371 } 376 }