Skip to content
Permalink
Browse files

Clean up FDs on Unix wait() interrupt

Using r-lib/cleancall.
  • Loading branch information
gaborcsardi committed Apr 8, 2019
1 parent a8f09d1 commit d05aadd4b0975a391d35a05958421f242bf96d23
Showing with 18 additions and 1 deletion.
  1. +5 −0 DESCRIPTION
  2. +2 −1 R/process.R
  3. +2 −0 src/processx-connection.c
  4. +9 −0 src/unix/processx.c
@@ -22,9 +22,12 @@ BugReports: https://github.com/r-lib/processx/issues
RoxygenNote: 6.1.1
Roxygen: list(markdown = TRUE)
Imports:
cleancall,
ps (>= 1.2.0),
R6,
utils
LinkingTo:
cleancall
Suggests:
callr,
covr,
@@ -33,4 +36,6 @@ Suggests:
parallel,
testthat,
withr
Remotes:
r-lib/cleancall
Encoding: UTF-8
@@ -633,7 +633,8 @@ process <- R6::R6Class(

process_wait <- function(self, private, timeout) {
"!DEBUG process_wait `private$get_short_name()`"
.Call(c_processx_wait, private$status, as.integer(timeout))
cleancall::call_with_cleanup(c_processx_wait, private$status,
as.integer(timeout))
invisible(self)
}

@@ -16,6 +16,8 @@

#include "processx.h"

#include <cleancall.h>

#ifdef _WIN32
#include "win/processx-win.h"
#else
@@ -3,6 +3,8 @@

#include "../processx.h"

#include "cleancall.h"

#include <stdio.h>

/* Internals */
@@ -504,6 +506,11 @@ void processx__collect_exit_status(SEXP status, int retval, int wstat) {
* 7. We keep polling until the timeout expires or the process finishes.
*/

static void processx__close_fd(void *ptr) {
int *fd = ptr;
if (*fd >= 0) close(*fd);
}

SEXP processx_wait(SEXP status, SEXP timeout) {
processx_handle_t *handle = R_ExternalPtrAddr(status);
int ctimeout = INTEGER(timeout)[0], timeleft = ctimeout;
@@ -535,6 +542,8 @@ SEXP processx_wait(SEXP status, SEXP timeout) {
processx__unblock_sigchld();
error("processx error: %s", strerror(errno));
}
r_call_on_exit(processx__close_fd, handle->waitpipe);
r_call_on_exit(processx__close_fd, handle->waitpipe + 1);
processx__nonblock_fcntl(handle->waitpipe[0], 1);
processx__nonblock_fcntl(handle->waitpipe[1], 1);

0 comments on commit d05aadd

Please sign in to comment.
You can’t perform that action at this time.