Merge pull request #141 from kubo39/patch-pipe-cloexec

Set close-on-exec flag for PipeFD
This commit is contained in:
Sönke Ludwig 2020-05-11 11:23:37 +02:00 committed by GitHub
commit 6372b4aabf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,7 +28,8 @@ final class PosixEventDriverPipes(Loop : PosixEventLoop) : EventDriverPipes {
if (m_loop.m_fds[fd].common.refCount) // FD already in use?
return PipeFD.invalid;
() @trusted { fcntl(system_fd, F_SETFL, fcntl(system_fd, F_GETFL) | O_NONBLOCK); } ();
// Suprisingly cannot use O_CLOEXEC here, so use FD_CLOEXEC instead.
() @trusted { fcntl(system_fd, F_SETFL, fcntl(system_fd, F_GETFL) | O_NONBLOCK | FD_CLOEXEC); } ();
m_loop.initFD(fd, FDFlags.none, PipeSlot.init);
m_loop.registerFD(fd, EventMask.read|EventMask.write|EventMask.status);