commit 9c4658bccc906a7464e7ee0115683e96938b8cd2 Author: Pavel Chupin Date: Sun Jan 20 00:45:35 2013 +0400 Enforce descriptor close on release when plugins used Signed-off-by: Pavel Chupin diff --git a/gold/descriptors.cc b/gold/descriptors.cc index f3f071e..5915dfd 100644 --- a/gold/descriptors.cc +++ b/gold/descriptors.cc @@ -157,6 +157,15 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode) pod->inuse = true; pod->is_write = (flags & O_ACCMODE) != O_RDONLY; pod->is_on_stack = false; + // If we have any plugin, we should try to close all handles on + // release. That's required for systems such as Windows that don't + // have O_CLOEXEC and forbid removal of files with open handles. + if (O_CLOEXEC == 0 + && parameters->options_valid() + && parameters->options().has_plugins()) + pod->close_on_release = true; + else + pod->close_on_release = false; ++this->current_; if (this->current_ >= this->limit_) @@ -191,7 +200,7 @@ Descriptors::release(int descriptor, bool permanent) < this->open_descriptors_.size())); Open_descriptor* pod = &this->open_descriptors_[descriptor]; - if (permanent + if (permanent || pod->close_on_release || (this->current_ > this->limit_ && !pod->is_write)) { if (::close(descriptor) < 0) diff --git a/gold/descriptors.h b/gold/descriptors.h index 8e154a6..4fce5b5 100644 --- a/gold/descriptors.h +++ b/gold/descriptors.h @@ -71,6 +71,8 @@ class Descriptors bool is_write; // Whether the descriptor is on the stack. bool is_on_stack; + // Whether enforce close on release + bool close_on_release; }; bool