From normalperson at yhbt.net Mon Aug 18 17:59:21 2008 From: normalperson at yhbt.net (Eric Wong) Date: Mon, 18 Aug 2008 14:59:21 -0700 Subject: [Mongrel-development] Mongrel doesn't set close-on-exec on its listen socket In-Reply-To: <20080722163104.GA82787@lizzy.catnook.local> References: <20080722163104.GA82787@lizzy.catnook.local> Message-ID: <20080818215844.GA1441@yp-box.dyndns.org> Jos Backus wrote: > Mongrel, at least in 1.1.4, doesn't set the close-on-exec flag on the listen > socket. This leads to trouble in programs that use Mongrel and fork other > programs (like puppetmasterd, part of Puppet). For an example, see > http://groups.google.com/group/puppet-dev/browse_thread/thread/463f0f8cfc80cc43 > > Please consider applying something like the following patch: > > --- lib/mongrel.rb.orig 2008-07-17 17:44:42.000000000 -0400 > +++ lib/mongrel.rb 2008-07-17 17:44:53.000000000 -0400 > @@ -92,7 +92,9 @@ > > tries = 0 > @socket = TCPServer.new(host, port) > + @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) > + > @classifier = URIClassifier.new > @host = host > @port = port > > If somebody can show me what the Mongrel way of making this (POSIX) > platform-specific, that would be appreciated. This probably works: diff --git a/lib/mongrel.rb b/lib/mongrel.rb index 8b5dfe2..027bfdb 100644 --- a/lib/mongrel.rb +++ b/lib/mongrel.rb @@ -91,6 +91,9 @@ module Mongrel tries = 0 @socket = TCPServer.new(host, port) + if defined?(Fcntl::FD_CLOEXEC) + @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + end @classifier = URIClassifier.new @host = host -- Eric Wong From jos at catnook.com Mon Aug 18 23:08:44 2008 From: jos at catnook.com (Jos Backus) Date: Mon, 18 Aug 2008 20:08:44 -0700 Subject: [Mongrel-development] Mongrel doesn't set close-on-exec on its listen socket In-Reply-To: <20080818215844.GA1441@yp-box.dyndns.org> References: <20080722163104.GA82787@lizzy.catnook.local> <20080818215844.GA1441@yp-box.dyndns.org> Message-ID: <20080819030844.GA53303@lizzy.catnook.local> On Mon, Aug 18, 2008 at 02:59:21PM -0700, Eric Wong wrote: > This probably works: > > diff --git a/lib/mongrel.rb b/lib/mongrel.rb > index 8b5dfe2..027bfdb 100644 > --- a/lib/mongrel.rb > +++ b/lib/mongrel.rb > @@ -91,6 +91,9 @@ module Mongrel > > tries = 0 > @socket = TCPServer.new(host, port) > + if defined?(Fcntl::FD_CLOEXEC) > + @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) > + end > > @classifier = URIClassifier.new > @host = host Looks reasonable to me. Thanks, Eric. Can somebody commit, please? -- Jos Backus jos at catnook.com From normalperson at yhbt.net Wed Aug 20 04:27:37 2008 From: normalperson at yhbt.net (Eric Wong) Date: Wed, 20 Aug 2008 01:27:37 -0700 Subject: [Mongrel-development] Mongrel doesn't set close-on-exec on its listen socket In-Reply-To: <20080819030844.GA53303@lizzy.catnook.local> References: <20080722163104.GA82787@lizzy.catnook.local> <20080818215844.GA1441@yp-box.dyndns.org> <20080819030844.GA53303@lizzy.catnook.local> Message-ID: <20080820082737.GA2403@yp-box.dyndns.org> Jos Backus wrote: > On Mon, Aug 18, 2008 at 02:59:21PM -0700, Eric Wong wrote: > > This probably works: > > > > diff --git a/lib/mongrel.rb b/lib/mongrel.rb > > index 8b5dfe2..027bfdb 100644 > > --- a/lib/mongrel.rb > > +++ b/lib/mongrel.rb > > @@ -91,6 +91,9 @@ module Mongrel > > > > tries = 0 > > @socket = TCPServer.new(host, port) > > + if defined?(Fcntl::FD_CLOEXEC) > > + @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) > > + end > > > > @classifier = URIClassifier.new > > @host = host > > Looks reasonable to me. Thanks, Eric. Can somebody commit, please? I've just committed it, r1036 to trunk. Thanks for the report! -- Eric Wong