mirror of
https://github.com/janet-lang/janet
synced 2025-06-06 08:34:13 +00:00
Try bsd fix.
This commit is contained in:
parent
bc9ec7ac4a
commit
d481d079ba
@ -409,14 +409,35 @@ static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
|||||||
|
|
||||||
#else /* windows check */
|
#else /* windows check */
|
||||||
|
|
||||||
|
static int proc_get_status(JanetProc *proc) {
|
||||||
|
/* Use POSIX shell semantics for interpreting signals */
|
||||||
|
int status = 0;
|
||||||
|
pid_t result;
|
||||||
|
do {
|
||||||
|
result = waitpid(proc->pid, &status, 0);
|
||||||
|
} while (result == -1 && errno == EINTR);
|
||||||
|
if (WIFEXITED(status)) {
|
||||||
|
status = WEXITSTATUS(status);
|
||||||
|
} else if (WIFSTOPPED(status)) {
|
||||||
|
status = WSTOPSIG(status) + 128;
|
||||||
|
} else {
|
||||||
|
status = WTERMSIG(status) + 128;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/* Function that is called in separate thread to wait on a pid */
|
/* Function that is called in separate thread to wait on a pid */
|
||||||
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
||||||
JanetProc *proc = (JanetProc *) args.argp;
|
JanetProc *proc = (JanetProc *) args.argp;
|
||||||
pid_t result;
|
pid_t result;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
#ifdef WNOWAIT
|
||||||
do {
|
do {
|
||||||
result = waitpid(proc->pid, &status, WNOWAIT);
|
result = waitpid(proc->pid, &status, WNOWAIT);
|
||||||
} while (result == -1 && errno == EINTR);
|
} while (result == -1 && errno == EINTR);
|
||||||
|
#else
|
||||||
|
args.tag = proc_get_status(proc);
|
||||||
|
#endif
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,20 +448,11 @@ static void janet_proc_wait_cb(JanetEVGenericMessage args) {
|
|||||||
janet_ev_dec_refcount();
|
janet_ev_dec_refcount();
|
||||||
JanetProc *proc = (JanetProc *) args.argp;
|
JanetProc *proc = (JanetProc *) args.argp;
|
||||||
if (NULL != proc) {
|
if (NULL != proc) {
|
||||||
/* Wait again without NOWAIT.
|
#ifdef WNOWAIT
|
||||||
* Use POSIX shell semantics for interpreting signals */
|
int status = proc_get_status(proc);
|
||||||
int status = 0;
|
#else
|
||||||
pid_t result;
|
int status = args.tag;
|
||||||
do {
|
#endif
|
||||||
result = waitpid(proc->pid, &status, 0);
|
|
||||||
} while (result == -1 && errno == EINTR);
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
status = WEXITSTATUS(status);
|
|
||||||
} else if (WIFSTOPPED(status)) {
|
|
||||||
status = WSTOPSIG(status) + 128;
|
|
||||||
} else {
|
|
||||||
status = WTERMSIG(status) + 128;
|
|
||||||
}
|
|
||||||
proc->return_code = (int32_t) status;
|
proc->return_code = (int32_t) status;
|
||||||
proc->flags |= JANET_PROC_WAITED;
|
proc->flags |= JANET_PROC_WAITED;
|
||||||
proc->flags &= ~JANET_PROC_WAITING;
|
proc->flags &= ~JANET_PROC_WAITING;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user