File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ SEXP processx_write(SEXP fd, SEXP data) {
102102#include <fcntl.h>
103103#include <errno.h>
104104#include <unistd.h>
105+ #include <stdlib.h>
105106
106107#include <R_ext/Rdynload.h>
107108#include <Rinternals.h>
@@ -130,8 +131,13 @@ SEXP processx_disable_inheritance() {
130131
131132 /* Set the CLOEXEC flag on all open descriptors. Unconditionally try the
132133 * first 16 file descriptors. After that, bail out after the first error.
133- */
134- for (fd = 0 ; ; fd ++ ) {
134+ * We skip the standard streams, because R and `system()` is not prepared
135+ * to not inheriting stdin and eg. an R subprocess does not even start in
136+ * system(). See https://github.com/r-lib/callr/issues/236. */
137+
138+ int firstfd = 3 ;
139+ if (getenv ("PROCESSX_CLOEXEC_STDIO" )) firstfd = 0 ;
140+ for (fd = firstfd ; ; fd ++ ) {
135141 if (processx__cloexec_fcntl (fd , 1 ) && fd > 15 ) break ;
136142 }
137143
Original file line number Diff line number Diff line change 66#include <errno.h>
77#include <sys/types.h>
88#include <unistd.h>
9+ #include <stdlib.h>
910
1011#ifndef _WIN32
1112#include <sys/uio.h>
@@ -731,8 +732,13 @@ SEXP processx_connection_disable_inheritance() {
731732
732733 /* Set the CLOEXEC flag on all open descriptors. Unconditionally try the
733734 * first 16 file descriptors. After that, bail out after the first error.
734- */
735- for (fd = 0 ; ; fd ++ ) {
735+ * We skip the standard streams, because R and `system()` is not prepared
736+ * to not inheriting stdin and eg. an R subprocess does not even start in
737+ * system(). See https://github.com/r-lib/callr/issues/236. */
738+
739+ int firstfd = 3 ;
740+ if (getenv ("PROCESSX_CLOEXEC_STDIO" )) firstfd = 0 ;
741+ for (fd = firstfd ; ; fd ++ ) {
736742 if (processx__cloexec_fcntl (fd , 1 ) && fd > 15 ) break ;
737743 }
738744
You can’t perform that action at this time.
0 commit comments