diff options
author | Markus Roberts <Markus@reality.com> | 2010-09-28 11:16:45 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-09-28 20:23:13 -0700 |
commit | 25738726526c6618906eb02878f32bb276fec26f (patch) | |
tree | 9320cdf2cd712370052247c3137236466f6b48ab /lib | |
parent | eb9279c69d74f1a86a79df9319eab42fefe308ee (diff) | |
download | puppet-25738726526c6618906eb02878f32bb276fec26f.tar.gz puppet-25738726526c6618906eb02878f32bb276fec26f.tar.xz puppet-25738726526c6618906eb02878f32bb276fec26f.zip |
Fix for #4649 -- avoid unsupported features on non-posix systems
MS Windows is apparently only "posix curious;" many of the usual fcntl flags
are not defined when running under MS Windows. It also appears that we are
only using a small subset of the vendored event-loop library and could replace
it with a handful of (portable) extracted methods. This, however, would be
too agressive of a refactor for 2.6.2 and so this commit simply avoids referring
to the unsupported flag values in environments where they are not defined.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/external/event-loop/event-loop.rb | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/puppet/external/event-loop/event-loop.rb b/lib/puppet/external/event-loop/event-loop.rb index dc51a55ae..3b40f6e71 100644 --- a/lib/puppet/external/event-loop/event-loop.rb +++ b/lib/puppet/external/event-loop/event-loop.rb @@ -75,8 +75,10 @@ class EventLoop @notify_src, @notify_snk = IO.pipe # prevent file descriptor leaks - @notify_src.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) - @notify_snk.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + if @notify_src.respond_to?(:fcntl) and defined?(Fcntl) and defined?(Fcntl::F_SETFD) and defined?(Fcntl::FD_CLOEXEC) + @notify_src.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + @notify_snk.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + end @notify_src.will_block = false @notify_snk.will_block = false @@ -234,19 +236,21 @@ class IO end def will_block? - require "fcntl" - fcntl(Fcntl::F_GETFL, 0) & Fcntl::O_NONBLOCK == 0 + if respond_to?(:fcntl) and defined?(Fcntl) and defined?(Fcntl::F_GETFL) and defined?(Fcntl::O_NONBLOCK) + fcntl(Fcntl::F_GETFL, 0) & Fcntl::O_NONBLOCK == 0 + end end def will_block= (wants_blocking) - require "fcntl" - flags = fcntl(Fcntl::F_GETFL, 0) - if wants_blocking - flags &= ~Fcntl::O_NONBLOCK - else - flags |= Fcntl::O_NONBLOCK + if respond_to?(:fcntl) and defined?(Fcntl) and defined?(Fcntl::F_GETFL) and defined?(Fcntl::O_NONBLOCK) + flags = fcntl(Fcntl::F_GETFL, 0) + if wants_blocking + flags &= ~Fcntl::O_NONBLOCK + else + flags |= Fcntl::O_NONBLOCK + end + fcntl(Fcntl::F_SETFL, flags) end - fcntl(Fcntl::F_SETFL, flags) end end |