mirror of
https://github.com/janet-lang/janet
synced 2024-11-29 03:19:54 +00:00
Fix (mostly nonsensible) race condition in multi threaded processes using os/execute with os/setenv.
This commit is contained in:
parent
f7b49a2c91
commit
a0f351c9fa
@ -389,15 +389,26 @@ static Janet os_execute(int32_t argc, Janet *argv) {
|
|||||||
char *const *cargv = (char *const *)child_argv;
|
char *const *cargv = (char *const *)child_argv;
|
||||||
|
|
||||||
/* Use posix_spawn to spawn new process */
|
/* Use posix_spawn to spawn new process */
|
||||||
|
|
||||||
|
int use_environ = !janet_flag_at(flags, 0);
|
||||||
|
|
||||||
|
if (use_environ) {
|
||||||
|
janet_lock_environ();
|
||||||
|
}
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
if (janet_flag_at(flags, 1)) {
|
if (janet_flag_at(flags, 1)) {
|
||||||
status = posix_spawnp(&pid,
|
status = posix_spawnp(&pid,
|
||||||
child_argv[0], NULL, NULL, cargv,
|
child_argv[0], NULL, NULL, cargv,
|
||||||
janet_flag_at(flags, 0) ? envp : environ);
|
use_environ ? environ : envp);
|
||||||
} else {
|
} else {
|
||||||
status = posix_spawn(&pid,
|
status = posix_spawn(&pid,
|
||||||
child_argv[0], NULL, NULL, cargv,
|
child_argv[0], NULL, NULL, cargv,
|
||||||
janet_flag_at(flags, 0) ? envp : environ);
|
use_environ ? environ : envp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (use_environ) {
|
||||||
|
janet_unlock_environ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for child */
|
/* Wait for child */
|
||||||
|
Loading…
Reference in New Issue
Block a user