mirror of
https://github.com/janet-lang/janet
synced 2024-12-29 18:00:26 +00:00
Merge branch 'master' of github.com:janet-lang/janet
This commit is contained in:
commit
bdd64f5656
@ -30,6 +30,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef JANET_WINDOWS
|
||||
#include <fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@ -139,6 +140,20 @@ static Janet cfun_io_temp(int32_t argc, Janet *argv) {
|
||||
FILE *tmp = tmpfile();
|
||||
if (!tmp)
|
||||
janet_panicf("unable to create temporary file - %s", strerror(errno));
|
||||
|
||||
#ifndef JANET_WINDOWS
|
||||
/* It seems highly unlikely a typical janet user wants a tempfile to be inherited and
|
||||
libc tmpfile does NOT set O_CLOEXEC by default,
|
||||
|
||||
Even though setting this flag after a delay is racy in threaded programs,
|
||||
It helps in single threaded ones. The fix for threaded programs would be to use mkostemp
|
||||
which is coming to POSIX at a later time. */
|
||||
if (fcntl(fileno(tmp), F_SETFD, FD_CLOEXEC) != 0) {
|
||||
fclose(tmp);
|
||||
janet_panic("unable initialize temporary file");
|
||||
}
|
||||
#endif
|
||||
|
||||
return janet_makefile(tmp, JANET_FILE_WRITE | JANET_FILE_READ | JANET_FILE_BINARY);
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user