mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
osx: ppoll, execvpe, pipe2 workarounds
This commit is contained in:
parent
33752742d1
commit
f3886df67c
13
src/lib/fd.c
13
src/lib/fd.c
@ -169,10 +169,14 @@ int ncfdplane_destroy(ncfdplane* n){
|
|||||||
// ncfdplane around the read end, involving creation of a new thread. the
|
// ncfdplane around the read end, involving creation of a new thread. the
|
||||||
// parent then returns.
|
// parent then returns.
|
||||||
static pid_t
|
static pid_t
|
||||||
launch_pipe_process(int* pipe, int* pidfd){
|
launch_pipe_process(int* pipefd, int* pidfd){
|
||||||
*pidfd = -1;
|
*pidfd = -1;
|
||||||
int pipes[2];
|
int pipes[2];
|
||||||
|
#if (defined(__linux__))
|
||||||
if(pipe2(pipes, O_CLOEXEC)){ // can't use O_NBLOCK here (affects client)
|
if(pipe2(pipes, O_CLOEXEC)){ // can't use O_NBLOCK here (affects client)
|
||||||
|
#else
|
||||||
|
if(pipe(pipes)){ // FIXME manually set O_CLOEXEC
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pid_t p = -1;
|
pid_t p = -1;
|
||||||
@ -197,8 +201,8 @@ launch_pipe_process(int* pipe, int* pidfd){
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}else if(p > 0){ // parent
|
}else if(p > 0){ // parent
|
||||||
*pipe = pipes[0];
|
*pipefd = pipes[0];
|
||||||
set_fd_nonblocking(*pipe, 1, NULL);
|
set_fd_nonblocking(*pipefd, 1, NULL);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -392,6 +396,9 @@ ncsubproc* ncsubproc_createvpe(ncplane* n, const ncsubproc_options* opts,
|
|||||||
if(ret->pid == 0){
|
if(ret->pid == 0){
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
execvpe(bin, arg, env);
|
execvpe(bin, arg, env);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
(void)env;
|
||||||
|
execvp(bin, arg); // FIXME env?
|
||||||
#else
|
#else
|
||||||
exect(bin, arg, env);
|
exect(bin, arg, env);
|
||||||
#endif
|
#endif
|
||||||
|
@ -406,7 +406,12 @@ block_on_input(int fd, const struct timespec* ts, const sigset_t* sigmask){
|
|||||||
pfd.events |= POLLRDHUP;
|
pfd.events |= POLLRDHUP;
|
||||||
#endif
|
#endif
|
||||||
int events;
|
int events;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
int timeoutms = ts->tv_sec * 1000 + ts->tv_nsec / 1000000;
|
||||||
|
while((events = poll(&pfd, 1, timeoutms)) < 0){ // FIXME scratchmask?
|
||||||
|
#else
|
||||||
while((events = ppoll(&pfd, 1, ts, &scratchmask)) < 0){
|
while((events = ppoll(&pfd, 1, ts, &scratchmask)) < 0){
|
||||||
|
#endif
|
||||||
if(events == 0){
|
if(events == 0){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user