diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-04-18 17:23:44 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-04-18 21:48:44 +0200 |
commit | bd2086f3b71ae83f458fc24c710b4ad9d1312183 (patch) | |
tree | 454fc86bbe9df0f6fb8589c90ac7ae7101a61a47 /src/corelib/io/qtemporaryfile.cpp | |
parent | 7e2041554870ad21699eef8d39ddf35f408be0e6 (diff) | |
download | qt4-tools-bd2086f3b71ae83f458fc24c710b4ad9d1312183.tar.gz |
Make temporary files close-on-exec
Reviewed-By: thiago
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-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 ad2b11619d..48563539b7 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) { |