Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

unix: set close-on-exec flag on received file descriptors #962

Open
bnoordhuis opened this issue Oct 22, 2013 · 3 comments
Open

unix: set close-on-exec flag on received file descriptors #962

bnoordhuis opened this issue Oct 22, 2013 · 3 comments

Comments

@bnoordhuis
Copy link
Contributor

Set the close-on-exec flag on file descriptors that are received with recvmsg().

For reference: https://groups.google.com/forum/#!topic/nodejs/8HbK7MAGAGg (Message-ID <CAPJ5V2bmXQHKzXbu2fN_4zBinjyrbGQ_s7QPEpazDush4SuZbQ@mail.gmail.com>)

Example patch:

diff --git a/deps/uv/src/unix/stream.c b/deps/uv/src/unix/stream.c
index c9df979..dff5f2b 100644
--- a/src/unix/stream.c
+++ b/src/unix/stream.c
@@ -1042,6 +1042,7 @@ static void uv__read(uv_stream_t* stream) {
               void* pv = CMSG_DATA(cmsg);
               int* pi = pv;
               stream->accepted_fd = *pi;
+              uv__cloexec(stream->accepted_fd, 1);
             }

           } else {
@ghost ghost assigned bnoordhuis Oct 22, 2013
@saghul
Copy link
Contributor

saghul commented Jul 30, 2014

This kind of fell through the cracks :-S Looks kind-of important, think we should adapt and land @indutny? Ben?

@bnoordhuis bnoordhuis removed their assignment Jul 30, 2014
@bnoordhuis
Copy link
Contributor Author

Seems like a good idea, yes. I fixed it in master in e9f75fb, introducing a style error in internal.h in the process, it seems.

I would suggest the same approach for v0.10: use recvmsg(MSG_CMSG_CLOEXEC) when available, fall back to uv__cloexec() when it's not.

@saghul
Copy link
Contributor

saghul commented Jul 30, 2014

Will do, thanks for confirming Ben!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants