- Hold_optional_lock hl(this->lock_);
-
- if (static_cast<size_t>(new_descriptor)
- >= this->open_descriptors_.size())
- this->open_descriptors_.resize(new_descriptor + 64);
-
- Open_descriptor* pod = &this->open_descriptors_[new_descriptor];
- pod->name = name;
- pod->stack_next = -1;
- pod->inuse = true;
- pod->is_write = (flags & O_ACCMODE) != O_RDONLY;
+ // If we have any plugins, we really do need to set the
+ // close-on-exec flag, even if O_CLOEXEC is not defined.
+ // FIXME: In some cases O_CLOEXEC may be defined in the
+ // header file but not supported by the kernel.
+ // Unfortunately there doesn't seem to be any obvious way to
+ // detect that, as unknown flags passed to open are ignored.
+ if (O_CLOEXEC == 0
+ && parameters->options_valid()
+ && parameters->options().has_plugins())
+ set_close_on_exec(new_descriptor);
+
+ {
+ Hold_optional_lock hl(this->lock_);
+
+ if (static_cast<size_t>(new_descriptor)
+ >= this->open_descriptors_.size())
+ this->open_descriptors_.resize(new_descriptor + 64);
+
+ Open_descriptor* pod = &this->open_descriptors_[new_descriptor];
+ pod->name = name;
+ pod->stack_next = -1;
+ pod->inuse = true;
+ pod->is_write = (flags & O_ACCMODE) != O_RDONLY;
+ pod->is_on_stack = false;