From 4b53b42be19a1e4435b87262dee6e025da399ca6 Mon Sep 17 00:00:00 2001 From: David Dollar Date: Wed, 11 Jul 2012 15:05:28 -0400 Subject: [PATCH] 1.8 compatibility --- lib/foreman.rb | 4 ++++ lib/foreman/engine.rb | 2 +- lib/foreman/process.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/foreman.rb b/lib/foreman.rb index 5b661a4..888247a 100644 --- a/lib/foreman.rb +++ b/lib/foreman.rb @@ -12,6 +12,10 @@ module Foreman defined?(RUBY_PLATFORM) and RUBY_PLATFORM == "java" end + def self.ruby_18? + defined?(RUBY_VERSION) and RUBY_VERSION =~ /^1\.8\.\d+/ + end + def self.windows? defined?(RUBY_PLATFORM) and RUBY_PLATFORM =~ /(win|w)32$/ end diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index dd09c14..05ea01a 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -260,7 +260,7 @@ private loop do (IO.select(@readers.values).first || []).each do |reader| data = reader.gets - output_with_mutex name_for(@readers.key(reader)), data + output_with_mutex name_for(@readers.invert[reader]), data end end rescue Exception => ex diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 911f17b..d208c3a 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -43,6 +43,15 @@ class Foreman::Process require "posix/spawn" POSIX::Spawn.spawn env, command, :out => output, :err => output end + elsif Foreman.ruby_18? + Dir.chdir(cwd) do + fork do + $stdout.reopen output + $stderr.reopen output + env.each { |k,v| ENV[k] = v } + exec command + end + end else Dir.chdir(cwd) do Process.spawn env, command, :out => output, :err => output