From 9e12622a8706a0d23a3ff8792773e73b0d6108b4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 4 Nov 2021 12:27:45 +0000 Subject: win32: move UCRT hack to process.c Only apply the UCRT hack if we're about to call spawnve() with a non-NULL environment pointer. Add the pid of the process to the name of the environment variable to provide greater assurance that the environment will be changed. --- libbb/appletlib.c | 3 --- win32/process.c | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index f0ed85215..6c0be4a83 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -1248,9 +1248,6 @@ int main(int argc UNUSED_PARAM, char **argv) /* Ignore critical errors, such as calling GetVolumeInformation() on * a floppy or CDROM drive with no media. */ SetErrorMode(SEM_FAILCRITICALERRORS); -# ifdef _UCRT - SetEnvironmentVariable("BB_HELLO", "world"); -# endif #endif #if defined(__MINGW64_VERSION_MAJOR) diff --git a/win32/process.c b/win32/process.c index 812e259f4..137cb6a39 100644 --- a/win32/process.c +++ b/win32/process.c @@ -268,6 +268,14 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env) new_path = xasprintf("%s.", path); } +#if defined(_UCRT) + if (env) { + char buffer[64]; + + sprintf(buffer, "BB_HELLO_%d", getpid()); + SetEnvironmentVariable(buffer, "1"); + } +#endif errno = 0; ret = spawnve(mode, new_path ? new_path : path, new_argv, env); -- cgit v1.2.3-55-g6feb