From bd2086f3b71ae83f458fc24c710b4ad9d1312183 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 18 Apr 2009 17:23:44 +0200 Subject: Make temporary files close-on-exec Reviewed-By: thiago --- src/corelib/io/qtemporaryfile.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index ad2b116..4856353 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -219,9 +219,20 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen) # elif defined(Q_OS_WIN) |O_BINARY # endif +# ifdef O_CLOEXEC + // supported on Linux >= 2.6.23; avoids one extra system call + // and avoids a race condition: if another thread forks, we could + // end up leaking a file descriptor... + |O_CLOEXEC +# endif , 0600)) >= 0) #endif // WIN && !CE + { +#if defined(Q_OS_UNIX) && !defined(O_CLOEXEC) + fcntl(*doopen, F_SETFD, FD_CLOEXEC); +#endif return 1; + } if (errno != EEXIST) return 0; } else if (domkdir) { -- cgit v0.12