Skip to content

Commit

Permalink
Move posix-fork inside correct if-def
Browse files Browse the repository at this point in the history
Don't compile if processes are disabled.
  • Loading branch information
bakpakin committed Oct 15, 2023
1 parent 15d67e9 commit 21ebede
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/core/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,34 @@ JANET_CORE_FN(os_posix_exec,
return os_execute_impl(argc, argv, JANET_EXECUTE_EXEC);
}

JANET_CORE_FN(os_posix_fork,
"(os/posix-fork)",
"Make a `fork` system call and create a new process. Return nil if in the new process, otherwise a core/process object (as returned by os/spawn). "
"Not supported on all systems (POSIX only).") {
janet_sandbox_assert(JANET_SANDBOX_SUBPROCESS);
janet_fixarity(argc, 0);
(void) argv;
#ifdef JANET_WINDOWS
janet_panic("not supported");
#else
pid_t result;
do {
result = fork();
} while (result == -1 && errno == EINTR);
if (result == -1) {
janet_panic(strerror(errno));
}
if (result) {
JanetProc *proc = janet_abstract(&ProcAT, sizeof(JanetProc));
memset(proc, 0, sizeof(JanetProc));
proc->pid = result;
proc->flags = JANET_PROC_ALLOW_ZOMBIE;
return janet_wrap_abstract(proc);
}
return janet_wrap_nil();
#endif
}

#ifdef JANET_EV
/* Runs in a separate thread */
static JanetEVGenericMessage os_shell_subr(JanetEVGenericMessage args) {
Expand Down Expand Up @@ -2371,34 +2399,6 @@ JANET_CORE_FN(os_permission_int,
return janet_wrap_integer(os_get_unix_mode(argv, 0));
}

JANET_CORE_FN(os_posix_fork,
"(os/posix-fork)",
"Make a `fork` system call and create a new process. Return nil if in the new process, otherwise a core/process object (as returned by os/spawn). "
"Not supported on all systems (POSIX only).") {
janet_sandbox_assert(JANET_SANDBOX_SUBPROCESS);
janet_fixarity(argc, 0);
(void) argv;
#ifdef JANET_WINDOWS
janet_panic("not supported");
#else
pid_t result;
do {
result = fork();
} while (result == -1 && errno == EINTR);
if (result == -1) {
janet_panic(strerror(errno));
}
if (result) {
JanetProc *proc = janet_abstract(&ProcAT, sizeof(JanetProc));
memset(proc, 0, sizeof(JanetProc));
proc->pid = result;
proc->flags = JANET_PROC_ALLOW_ZOMBIE;
return janet_wrap_abstract(proc);
}
return janet_wrap_nil();
#endif
}

#ifdef JANET_EV

/*
Expand Down

0 comments on commit 21ebede

Please sign in to comment.