mirror of
https://github.com/janet-lang/janet
synced 2024-12-28 09:20:26 +00:00
Fix os/spawn - os/execute switch.
This commit is contained in:
parent
0145b133a1
commit
821a8dca3b
@ -332,6 +332,25 @@ typedef struct {
|
|||||||
JanetFile *err;
|
JanetFile *err;
|
||||||
} JanetProc;
|
} JanetProc;
|
||||||
|
|
||||||
|
static int janet_proc_gc(void *p, size_t s) {
|
||||||
|
(void) s;
|
||||||
|
JanetProc *proc = (JanetProc *) p;
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
if (!(proc->flags & JANET_PROC_CLOSED)) {
|
||||||
|
CloseHandle(proc->pHandle);
|
||||||
|
CloseHandle(proc->tHandle);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (!(proc->flags & JANET_PROC_WAITED)) {
|
||||||
|
/* Kill and wait to prevent zombies */
|
||||||
|
kill(proc->pid, SIGKILL);
|
||||||
|
int status;
|
||||||
|
waitpid(proc->pid, &status, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int janet_proc_mark(void *p, size_t s) {
|
static int janet_proc_mark(void *p, size_t s) {
|
||||||
(void) s;
|
(void) s;
|
||||||
JanetProc *proc = (JanetProc *)p;
|
JanetProc *proc = (JanetProc *)p;
|
||||||
@ -371,6 +390,9 @@ static Janet os_proc_wait(int32_t argc, Janet *argv) {
|
|||||||
static Janet os_proc_kill(int32_t argc, Janet *argv) {
|
static Janet os_proc_kill(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
JanetProc *proc = janet_getabstract(argv, 0, &ProcAT);
|
JanetProc *proc = janet_getabstract(argv, 0, &ProcAT);
|
||||||
|
if (proc->flags & JANET_PROC_WAITED) {
|
||||||
|
janet_panicf("cannot kill process that has already finished");
|
||||||
|
}
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
if (proc->flags & JANET_PROC_CLOSED) {
|
if (proc->flags & JANET_PROC_CLOSED) {
|
||||||
janet_panicf("cannot close process handle that is already closed");
|
janet_panicf("cannot close process handle that is already closed");
|
||||||
@ -422,7 +444,7 @@ static int janet_proc_get(void *p, Janet key, Janet *out) {
|
|||||||
|
|
||||||
static const JanetAbstractType ProcAT = {
|
static const JanetAbstractType ProcAT = {
|
||||||
"core/process",
|
"core/process",
|
||||||
NULL,
|
janet_proc_gc,
|
||||||
janet_proc_mark,
|
janet_proc_mark,
|
||||||
janet_proc_get,
|
janet_proc_get,
|
||||||
JANET_ATEND_GET
|
JANET_ATEND_GET
|
||||||
@ -608,11 +630,11 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, int is_async) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Janet os_execute(int32_t argc, Janet *argv) {
|
static Janet os_execute(int32_t argc, Janet *argv) {
|
||||||
return os_execute_impl(argc, argv, 1);
|
return os_execute_impl(argc, argv, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet os_spawn(int32_t argc, Janet *argv) {
|
static Janet os_spawn(int32_t argc, Janet *argv) {
|
||||||
return os_execute_impl(argc, argv, 0);
|
return os_execute_impl(argc, argv, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet os_shell(int32_t argc, Janet *argv) {
|
static Janet os_shell(int32_t argc, Janet *argv) {
|
||||||
|
1682
src/core/os.c.orig
Normal file
1682
src/core/os.c.orig
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user