Issue #5664 has been reported by Brian Candler.

----------------------------------------
Bug #5664: Webrick broken FD_CLOEXEC
http://redmine.ruby-lang.org/issues/5664

Author: Brian Candler
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]


ruby-1.8.7-p352 $ grep -R CLOEXEC .
./ext/fcntl/fcntl.c: * - FD_CLOEXEC - the value of the close-on-exec flag.
./ext/fcntl/fcntl.c:#ifdef FD_CLOEXEC
./ext/fcntl/fcntl.c:    rb_define_const(mFcntl, "FD_CLOEXEC", INT2NUM(FD_CLOEXEC));
./lib/drb/drb.rb:      soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
./lib/drb/unix.rb:      soc.fcntl(Fcntl::F_SETFL, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
./lib/resolv.rb:            sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
./lib/resolv.rb:          sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
./lib/resolv.rb:          sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
./lib/webrick/utils.rb:      if defined?(Fcntl::FD_CLOEXEC)
./lib/webrick/utils.rb:        io.fcntl(Fcntl::FD_CLOEXEC, 1)

There you can see lots of examples of FD_CLOEXEC being used correctly: fcntl (command F_SETFD, value FD_CLOEXEC)

But in the last line, Webrick is calling fcntl wrongly: it is calling command FD_CLOEXEC with value 1 !! So what it's actually calling is command F_GETFD, which does nothing.

>> Fcntl.constants.select { |x| Fcntl.const_get(x) == Fcntl::FD_CLOEXEC }
=> ["F_GETFD", "FD_CLOEXEC", "O_WRONLY", "F_RDLCK"]

I have checked this in the latest 1.8.7-p352 source too, and it's the same there.



-- 
http://redmine.ruby-lang.org