[Rd] certain pipe() use cases not working in r-devel

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Thu Feb 15 14:47:16 CET 2024


On 2/15/24 14:09, Ivan Krylov via R-devel wrote:
> В Wed, 14 Feb 2024 14:43:12 -0800
> Jennifer Bryan <jenny.f.bryan using gmail.com> пишет:
>
>> But in r-devel on macOS, this is silent no-op, i.e. "hello, world"
>> does not print:
>>
>>> R.version.string
>> [1] "R Under development (unstable) (2024-02-13 r85895)"
>>> con <- pipe("cat")
>>> writeLines("hello, world", con)
> I can reproduce this on 64-bit Linux.
>
> I think that this boils down to problems with cleanup in R_pclose_pg
> [*]. The FILE* fp corresponding to the child process pipe is created
> using fdopen() in R_popen_pg(), but R_pclose_pg() only performs close()
> on the file descriptor returned by fileno(). The FILE* itself is
> leaked, and any buffered content waiting to be written out is lost.
>
> One of the last few lines in the strace output before the process
> terminates is the standard C library cleaning up the FILE* object and
> trying to flush the buffer:
>
> $ strace -f bin/R -q -s \
>   -e 'writeLines("hello", x <- pipe("cat")); close(x)'
> ...skip...
> write(5, "hello\n", 6)                  = -1 EBADF (Bad file descriptor)
> exit_group(0)                           = ?
> +++ exited with 0 +++
>
> There is a comment saying "see timeout_wait for why not to use fclose",
> which I think references a different function, R_pclose_timeout():
>
>>> Do not use fclose, because on Solaris it sets errno to "Invalid
>>> seek" when the pipe is already closed (e.g. because of timeout).
>>> fclose would not return an error, but it would set errno and the
>>> non-zero errno would then be reported by R's "system" function.
> (There are no comments about fclose() in timeout_wait() itself.)
>
> Is there a way to work around the errno problem without letting the
> FILE* leak?
Thanks for the analysis, I will look into that.

Tomas


>



More information about the R-devel mailing list