Permalink
Browse files

Always use Process.spawn for 1.9

  • Loading branch information...
1 parent c890aac commit 0d94f58e7e2706d7cf0d7df4deab580255a27834 Peter Kieltyka committed Jun 16, 2011
Showing with 18 additions and 11 deletions.
  1. +1 −1 LICENSE
  2. +1 −1 VERSION
  3. +16 −9 lib/subexec.rb
View
@@ -1,6 +1,6 @@
MIT LICENSE
-Copyright (c) 2010 NuLayer Inc. info@nulayer.com
+Copyright (c) 2011 Nulayer Inc. info@nulayer.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
@@ -1 +1 @@
-0.1.0
+0.1.1
View
@@ -48,7 +48,7 @@ def initialize(command, options={})
end
def run!
- if timeout > 0 && RUBY_VERSION >= '1.9'
+ if RUBY_VERSION >= '1.9'
spawn
else
exec
@@ -66,20 +66,28 @@ def spawn
self.timer = Time.now + timeout
timed_out = false
- loop do
+ waitpid = Proc.new do
begin
flags = (timeout > 0 ? Process::WUNTRACED|Process::WNOHANG : 0)
- ret = Process.waitpid(pid, flags)
+ Process.waitpid(pid, flags)
rescue Errno::ECHILD
break
end
+ end
- break if ret == pid
- sleep 0.01
- if Time.now > timer
- timed_out = true
- break
+ if timeout > 0
+ loop do
+ ret = waitpid.call
+
+ break if ret == pid
+ sleep 0.01
+ if Time.now > timer
+ timed_out = true
+ break
+ end
end
+ else
+ waitpid.call
end
if timed_out
@@ -98,7 +106,6 @@ def spawn
def exec
self.output = `export LANG=#{lang} && #{command} 2>&1`
- self.exitstatus = $?.exitstatus
end
end

0 comments on commit 0d94f58

Please sign in to comment.