aboutsummaryrefslogtreecommitdiffhomepage
path: root/wutil.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-03-02 09:58:29 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-03-02 09:58:29 -0800
commit17a75a5aa5039de8359b859b7631e135cbdef81b (patch)
tree4073348f759615e6270720ea4a50e30fd159286d /wutil.cpp
parent8b26d0104c1d85c271e5ce6e08bfe64a779beba7 (diff)
Change to detect and use O_CLOEXEC
Diffstat (limited to 'wutil.cpp')
-rw-r--r--wutil.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/wutil.cpp b/wutil.cpp
index af73c5ce..6ef3642f 100644
--- a/wutil.cpp
+++ b/wutil.cpp
@@ -201,6 +201,13 @@ bool set_cloexec(int fd) {
static int wopen_internal(const wcstring &pathname, int flags, mode_t mode, bool cloexec)
{
cstring tmp = wcs2string(pathname);
+ /* Prefer to use O_CLOEXEC. It has to both be defined and nonzero */
+#ifdef O_CLOEXEC
+ if (cloexec && O_CLOEXEC) {
+ flags |= O_CLOEXEC;
+ cloexec = false;
+ }
+#endif
int fd = ::open(tmp.c_str(), flags, mode);
if (cloexec && fd >= 0 && ! set_cloexec(fd)) {
close(fd);