[subproc] kill FIXME; set pipes O_CLOEXEC manually in absence of pipe2()

This commit is contained in:
nick black 2021-09-26 04:39:26 -04:00 committed by nick black
parent 3c7d23b151
commit a5397ea19a
2 changed files with 22 additions and 6 deletions

View File

@ -142,6 +142,26 @@ int ncfdplane_destroy(ncfdplane* n){
return ret;
}
// get 2 pipes, and ensure they're both set to close-on-exec
static int
lay_pipes(int pipes[static 2]){
#ifdef __linux__
if(pipe2(pipes, O_CLOEXEC)){ // can't use O_NBLOCK here (affects client)
#else
if(pipe(pipes)){
#endif
return -1;
}
#ifndef __linux__
if(set_fd_cloexec(pipes[0], 1, NULL) || set_fd_cloexec(pipes[1], 1, NULL)){
close(pipes[0]);
close(pipes[1]);
return -1;
}
#endif
return 0;
}
// ncsubproc creates a pipe, retaining the read end. it clone()s a subprocess,
// getting a pidfd. the subprocess dup2()s the write end of the pipe onto file
// descriptors 1 and 2, exec()s, and begins running. the parent creates an
@ -152,11 +172,7 @@ launch_pipe_process(int* pipefd, int* pidfd){
#ifndef __MINGW64__
*pidfd = -1;
int pipes[2];
#if (defined(__linux__))
if(pipe2(pipes, O_CLOEXEC)){ // can't use O_NBLOCK here (affects client)
#else
if(pipe(pipes)){ // FIXME manually set O_CLOEXEC
#endif
if(lay_pipes(pipes)){
return -1;
}
pid_t p = -1;
@ -185,6 +201,7 @@ launch_pipe_process(int* pipefd, int* pidfd){
}
return p;
#else
// FIXME use CreateProcess()
(void)pipefd;
(void)pidfd;
return -1;

View File

@ -158,7 +158,6 @@ TEST_CASE("FdsAndSubprocs"
opts.curry = &outofline_cancelled;
auto ncsubp = ncsubproc_createvp(n_, &opts, argv[0], argv, testfdcb, testfdeof);
REQUIRE(ncsubp);
// FIXME ought be CHECK, breaking in drone
WARN(0 != ncsubproc_destroy(ncsubp));
CHECK(0 == notcurses_render(nc_));
}