1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 08:50:27 +00:00

Merge pull request #370 from andrewchambers/spawnrace

Fix (mostly nonsensible) race condition in multi threaded processes
This commit is contained in:
Calvin Rose 2020-05-05 10:33:41 -04:00 committed by GitHub
commit 688fe6db5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -389,15 +389,26 @@ static Janet os_execute(int32_t argc, Janet *argv) {
char *const *cargv = (char *const *)child_argv;
/* Use posix_spawn to spawn new process */
int use_environ = !janet_flag_at(flags, 0);
if (use_environ) {
janet_lock_environ();
}
pid_t pid;
if (janet_flag_at(flags, 1)) {
status = posix_spawnp(&pid,
child_argv[0], NULL, NULL, cargv,
janet_flag_at(flags, 0) ? envp : environ);
use_environ ? environ : envp);
} else {
status = posix_spawn(&pid,
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 */