nmh-workers
[Top] [All Lists]

Re: [nmh-workers] closefds() _before_ fork?

2019-04-23 11:29:48
I realize that dup2() clears the FD_CLOEXEC flag on the new file
descriptor so the "normal" case of an opened file being dup2() down to
0 would work correctly, but the wrinkle is that it does NOT if the old
and new file descriptor are the same.  That is admittedly unlikely,
but it could happen in a few cases so I'd like to be as robust as
possible.

Are you aware of dup3(2)?

Hm, I had to poke around for that one.  I see:

        dup3() is Linux-specific.

(I'm aware that it seems to have made it to other operating systems, but
I don't think we can rely on it).  Also, it seems like dup3() doesn't
do what I want, exactly.  Specifically:

        If oldfd equals newfd, then dup3() fails with the error EINVAL.

What I would like is a dup4(), where even if oldfd == newfd, then the
close-on-exec flag is cleared.  Not really a huge issue; we can work
around it.

--Ken

-- 
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>