diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-04-18 15:23:44 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-04-18 19:48:44 (GMT) |
commit | bd2086f3b71ae83f458fc24c710b4ad9d1312183 (patch) | |
tree | 454fc86bbe9df0f6fb8589c90ac7ae7101a61a47 /src/corelib/io | |
parent | 7e2041554870ad21699eef8d39ddf35f408be0e6 (diff) | |
download | Qt-bd2086f3b71ae83f458fc24c710b4ad9d1312183.zip Qt-bd2086f3b71ae83f458fc24c710b4ad9d1312183.tar.gz Qt-bd2086f3b71ae83f458fc24c710b4ad9d1312183.tar.bz2 |
Make temporary files close-on-exec
Reviewed-By: thiago
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
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) { |