Closed HenrikBengtsson closed 2 years ago
Posted to R-devel thread 'Rscript -e EXPR fails to launch if stdin is closed' on 2022-10-09 (https://stat.ethz.ch/pipermail/r-devel/2022-October/082084.html).
Yes, a bug in R;
On Mon, Oct 10, 2022 at 2:07 AM peter dalgaard wrote: ...
Yes, that looks like a blunder.
mkstemp() returns -1 on failure, not 0, so the test on ifd (and I suppose also the one on ifp) is wrong. And of course, once you close file descriptor 0, mkstemp() chooses the 1st available fd, i.e. 0, for its return value.
and a bit later:
It seems to work simply to do "if (ifd >= 0)..." (the ifp test is fine since ifp is FILE* and initialized to NULL). Will commit (to r-devel for now).
Now fixed in R-devel r83051 (https://github.com/wch/r-source/commit/97b3dfb71aeff4a6acb72d400bb1fba8e6b2ed37).
Now also in R-patch (to become R 4.2.2), cf. https://github.com/wch/r-source/commit/ab754c2f6581c81c687ba4115d32e80e0da9fabb
Issue
Rscript
fails to launch if the standard input (stdin) is closed, e.g.One rationale for having closed standard files (including stdin) is to avoid leaking file descriptors, cf. https://wiki.sei.cmu.edu/confluence/display/c/FIO22-C.+Close+files+before+spawning+processes and https://danwalsh.livejournal.com/53603.html.
Wish(?)
Can Rscript be updated to handle the case when stdin is closed?
Troubleshooting
This happens in src/unix/system.c:
Rscript script.R
works fine when stdin is closed;and so does
R
;Background
/ht Gábor Csárdi