mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 00:50:26 +00:00
ignoring signals on windows in os/proc-kill again
This commit is contained in:
parent
53afc2e50a
commit
e53c03028f
@ -628,6 +628,8 @@ struct keyword_signal {
|
|||||||
const char *keyword;
|
const char *keyword;
|
||||||
int signal;
|
int signal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef JANET_WINDOWS
|
||||||
static const struct keyword_signal signal_keywords[] = {
|
static const struct keyword_signal signal_keywords[] = {
|
||||||
#ifdef SIGKILL
|
#ifdef SIGKILL
|
||||||
{"kill", SIGKILL},
|
{"kill", SIGKILL},
|
||||||
@ -705,6 +707,7 @@ static const struct keyword_signal signal_keywords[] = {
|
|||||||
#endif
|
#endif
|
||||||
{NULL, 0},
|
{NULL, 0},
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
JANET_CORE_FN(os_proc_kill,
|
JANET_CORE_FN(os_proc_kill,
|
||||||
"(os/proc-kill proc &opt wait signal)",
|
"(os/proc-kill proc &opt wait signal)",
|
||||||
@ -712,12 +715,21 @@ JANET_CORE_FN(os_proc_kill,
|
|||||||
"handle on windows. If `wait` is truthy, will wait for the process to finish and "
|
"handle on windows. If `wait` is truthy, will wait for the process to finish and "
|
||||||
"returns the exit code. Otherwise, returns `proc`. If signal is specified send it instead."
|
"returns the exit code. Otherwise, returns `proc`. If signal is specified send it instead."
|
||||||
"Signal keywords are named after their C counterparts but in lowercase with the leading "
|
"Signal keywords are named after their C counterparts but in lowercase with the leading "
|
||||||
"`SIG` stripped") {
|
"`SIG` stripped. Signals are ignored on windows.") {
|
||||||
janet_arity(argc, 1, 3);
|
janet_arity(argc, 1, 3);
|
||||||
JanetProc *proc = janet_getabstract(argv, 0, &ProcAT);
|
JanetProc *proc = janet_getabstract(argv, 0, &ProcAT);
|
||||||
if (proc->flags & JANET_PROC_WAITED) {
|
if (proc->flags & JANET_PROC_WAITED) {
|
||||||
janet_panicf("cannot kill process that has already finished");
|
janet_panicf("cannot kill process that has already finished");
|
||||||
}
|
}
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
if (proc->flags & JANET_PROC_CLOSED) {
|
||||||
|
janet_panicf("cannot close process handle that is already closed");
|
||||||
|
}
|
||||||
|
proc->flags |= JANET_PROC_CLOSED;
|
||||||
|
TerminateProcess(proc->pHandle, 1);
|
||||||
|
CloseHandle(proc->pHandle);
|
||||||
|
CloseHandle(proc->tHandle);
|
||||||
|
#else
|
||||||
int signal = -1;
|
int signal = -1;
|
||||||
if(argc == 3){
|
if(argc == 3){
|
||||||
JanetKeyword signal_kw = janet_getkeyword(argv, 2);
|
JanetKeyword signal_kw = janet_getkeyword(argv, 2);
|
||||||
@ -733,24 +745,7 @@ JANET_CORE_FN(os_proc_kill,
|
|||||||
janet_panic("undefined signal");
|
janet_panic("undefined signal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef JANET_WINDOWS
|
int status = kill(proc->pid, signal == -1 ? SIGKILL : signal);
|
||||||
if (proc->flags & JANET_PROC_CLOSED) {
|
|
||||||
janet_panicf("cannot close process handle that is already closed");
|
|
||||||
}
|
|
||||||
proc->flags |= JANET_PROC_CLOSED;
|
|
||||||
if(signal == -1){
|
|
||||||
TerminateProcess(proc->pHandle, 1);
|
|
||||||
}else{
|
|
||||||
int status = kill(proc->pid, signal);
|
|
||||||
if (status) {
|
|
||||||
janet_panic(strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CloseHandle(proc->pHandle);
|
|
||||||
CloseHandle(proc->tHandle);
|
|
||||||
#else
|
|
||||||
if(signal == -1){signal=SIGKILL;}
|
|
||||||
int status = kill(proc->pid, signal);
|
|
||||||
if (status) {
|
if (status) {
|
||||||
janet_panic(strerror(errno));
|
janet_panic(strerror(errno));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user