diff --git a/src/node_file.cc b/src/node_file.cc index 5681f9f742..83e07dcc57 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -51,6 +51,12 @@ static Persistent buf_symbol; static char getbuf[PATH_MAX + 1]; #endif + +static inline bool SetCloseOnExec(int fd) { + return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); +} + + static int After(eio_req *req) { HandleScope scope; @@ -100,6 +106,8 @@ static int After(eio_req *req) { break; case EIO_OPEN: + SetCloseOnExec(req->result); + /* pass thru */ case EIO_SENDFILE: argv[1] = Integer::New(req->result); break; @@ -621,6 +629,7 @@ static Handle Open(const Arguments& args) { ASYNC_CALL(open, args[3], *path, flags, mode) } else { int fd = open(*path, flags, mode); + SetCloseOnExec(fd); if (fd < 0) return ThrowException(ErrnoException(errno, NULL, "", *path)); return scope.Close(Integer::New(fd)); }