Re: [PATCH] redir: Use memfd_create instead of pipe

Jilles Tjoelker <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On Sun, Apr 14, 2024 at 03:51:37PM +0800, Herbert Xu wrote:
> Use memfd_create(2) instead of pipe(2).  With pipe(2), a fork
> is required if the amount of data to be written exceeds the pipe
> size.  This is not the case with memfd_create.

Since a memfd does not behave identically to a pipe, this should be
tested carefully. A memfd does not behave identically to a regular file
either. It may affect programs started from the shell that read
here-documents.

Using pipe or memfd conditionally based on the length of the
here-document and whether memfd_create(2) fails transiently might cause
even more obscure issues.

I suggest using either a pipe for all here-documents or a memfd for all
here-documents. The shell should fall back from memfd_create(2) to
pipe(2) only if memfd_create(2) is not supported or fails for a
persistent reason like [ENOSYS] or [EPERM]; in this case, the shell
should remember the failure and immediately use pipe(2) for subsequent
here-documents.

The dup/close dance with the memfd will look silly in syscall traces,
although it is functionally fine.

-- 
Jilles Tjoelker
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.