Permalink
Browse files

16289 - Log something more than 'wtf'

Upgrade the vendored systemu gem to avoid rude error messages
  • Loading branch information...
1 parent 40e8db8 commit 3337bd17fcbe55e9d95ca6f04c0170391d92970e @ripienaar ripienaar committed Sep 10, 2012
@@ -4,7 +4,8 @@ NAME
SYNOPSIS
- univeral capture of stdout and stderr and handling of child process pid for windows, *nix, etc.
+ universal capture of stdout and stderr and handling of child process pid for
+ windows, *nix, etc.
URIS
@@ -53,7 +54,7 @@ SAMPLES
~ > ruby samples/a.rb
- [#<Process::Status: pid 16667 exit 0>, "2011-09-13 20:50:37 -0600\n", "2011-09-13 20:50:37 -0600\n"]
+ [#<Process::Status: pid 50931 exit 0>, "2011-12-11 22:07:30 -0700\n", "2011-12-11 22:07:30 -0700\n"]
<========< samples/b.rb >========>
@@ -75,7 +76,7 @@ SAMPLES
~ > ruby samples/b.rb
- [#<Process::Status: pid 16672 exit 0>, "2011-09-13 20:50:37 -0600\n", "2011-09-13 20:50:37 -0600\n"]
+ [#<Process::Status: pid 50936 exit 0>, "2011-12-11 22:07:30 -0700\n", "2011-12-11 22:07:30 -0700\n"]
<========< samples/c.rb >========>
@@ -116,7 +117,7 @@ SAMPLES
~ > ruby samples/d.rb
- /private/var/folders/nO/nOjBCb30ELegrm98Bhyvbk+++TM/-Tmp-
+ /private/var/folders/sp/nwtflj890qnb6z4b53dqxvlw0000gp/T
<========< samples/e.rb >========>
@@ -163,7 +164,7 @@ SAMPLES
~ > ruby samples/f.rb
- #<Process::Status: pid 16692 SIGKILL (signal 9)>
- "1315968638\n1315968639\n1315968640\n"
+ #<Process::Status: pid 50956 SIGKILL (signal 9)>
+ "1323666451\n1323666452\n1323666453\n"
@@ -277,7 +277,7 @@ BEGIN {
# discover full path to this ruby executable
#
- c = Config::CONFIG
+ c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
bindir = c["bindir"] || c['BINDIR']
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
ruby_ext = c['EXEEXT'] || ''
@@ -1,4 +1,5 @@
-# vim: ts=2:sw=2:sts=2:et:fdm=marker
+# encoding: utf-8
+
require 'tmpdir'
require 'socket'
require 'fileutils'
@@ -13,7 +14,7 @@ class SystemUniversal
#
# constants
#
- SystemUniversal::VERSION = '2.4.0' unless SystemUniversal.send(:const_defined?, :VERSION)
+ SystemUniversal::VERSION = '2.5.2' unless SystemUniversal.send(:const_defined?, :VERSION)
def SystemUniversal.version() SystemUniversal::VERSION end
def version() SystemUniversal::VERSION end
#
@@ -76,7 +77,7 @@ def systemu
line = pipe.gets
case line
when %r/^pid: \d+$/
- cid = Integer line[%r/\d+/]
+ cid = Integer line[%r/\d+/]
else
begin
buf = pipe.read
@@ -85,7 +86,7 @@ def systemu
raise unless Exception === e
raise e
rescue
- raise "wtf?\n#{ buf }\n"
+ raise "systemu: Error - process interrupted!\n#{ buf }\n"
end
end
thread = new_thread cid, @block if @block
@@ -120,12 +121,12 @@ def quote *args, &block
SystemUniversal.quote(*args, &block)
end
- def new_thread cid, block
+ def new_thread cid, block
q = Queue.new
- Thread.new(cid) do |cid|
- current = Thread.current
+ Thread.new(cid) do |cid|
+ current = Thread.current
current.abort_on_exception = true
- q.push current
+ q.push current
block.call cid
end
q.pop
@@ -150,10 +151,10 @@ def child_setup tmp
c['argv'] = @argv
c['env'] = @env
c['cwd'] = @cwd
- c['stdin'] = stdin
- c['stdout'] = stdout
- c['stderr'] = stderr
- c['program'] = program
+ c['stdin'] = stdin
+ c['stdout'] = stdout
+ c['stderr'] = stderr
+ c['program'] = program
open(config, 'w'){|f| Marshal.dump(c, f)}
open(program, 'w'){|f| f.write child_program(config)}
@@ -171,6 +172,8 @@ def quietly
def child_program config
<<-program
+ # encoding: utf-8
+
PIPE = STDOUT.dup
begin
config = Marshal.load(IO.read('#{ config }'))
@@ -190,7 +193,7 @@ def child_program config
STDERR.reopen stderr
PIPE.puts "pid: \#{ Process.pid }"
- PIPE.flush ### the process is ready yo!
+ PIPE.flush ### the process is ready yo!
PIPE.close
exec *argv
@@ -221,9 +224,9 @@ def tmpdir d = Dir.tmpdir, max = 42, &b
tmp = File.join d, "systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }"
begin
- Dir.mkdir tmp
+ Dir.mkdir tmp
rescue Errno::EEXIST
- raise if i >= max
+ raise if i >= max
next
end
@@ -232,7 +235,7 @@ def tmpdir d = Dir.tmpdir, max = 42, &b
begin
b.call tmp
ensure
- FileUtils.rm_rf tmp unless SystemU.turd
+ FileUtils.rm_rf tmp unless SystemU.turd
end
else
tmp
@@ -259,45 +262,48 @@ def getopts opts = {}
# some monkeypatching for JRuby
if defined? JRUBY_VERSION
require 'jruby'
- import org.jruby.RubyProcess
-
+ java_import org.jruby.RubyProcess
+
class SystemUniversal
def systemu
split_argv = JRuby::PathHelper.smart_split_command @argv
process = java.lang.Runtime.runtime.exec split_argv.to_java(:string)
-
+
stdout, stderr = [process.input_stream, process.error_stream].map do |stream|
StreamReader.new(stream)
end
exit_code = process.wait_for
+ field = process.get_class.get_declared_field("pid")
+ field.set_accessible(true)
+ pid = field.get(process)
[
- RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code),
- stdout.join,
+ RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code, pid),
+ stdout.join,
stderr.join
]
end
-
+
class StreamReader
def initialize(stream)
@data = ""
@thread = Thread.new do
reader = java.io.BufferedReader.new java.io.InputStreamReader.new(stream)
-
+
while line = reader.read_line
@data << line << "\n"
end
end
end
-
+
def join
@thread.join
@data
end
end
end
end
-
+
SystemU = SystemUniversal unless defined? SystemU
@@ -333,20 +339,20 @@ def join
# sleep
#
sleep = %q( ruby -e" p(sleep(1)) " )
- status, stdout, stderr = systemu sleep
+ status, stdout, stderr = systemu sleep
p [status, stdout, stderr]
sleep = %q( ruby -e" p(sleep(42)) " )
status, stdout, stderr = systemu(sleep){|cid| Process.kill 9, cid}
p [status, stdout, stderr]
#
-# env
+# env
#
env = %q( ruby -e" p ENV['A'] " )
- status, stdout, stderr = systemu env, :env => {'A' => 42}
+ status, stdout, stderr = systemu env, :env => {'A' => 42}
p [status, stdout, stderr]
#
-# cwd
+# cwd
#
env = %q( ruby -e" p Dir.pwd " )
status, stdout, stderr = systemu env, :cwd => Dir.tmpdir
@@ -3,7 +3,7 @@
Gem::Specification::new do |spec|
spec.name = "systemu"
- spec.version = "2.3.1"
+ spec.version = "2.5.2"
spec.platform = Gem::Platform::RUBY
spec.summary = "systemu"
spec.description = "description: systemu kicks the ass"
@@ -22,7 +22,10 @@ Gem::Specification::new do |spec|
"samples/d.rb",
"samples/e.rb",
"samples/f.rb",
- "systemu.gemspec"]
+ "systemu.gemspec",
+ "test",
+ "test/systemu_test.rb",
+ "test/testing.rb"]
spec.executables = []
View
@@ -8,6 +8,7 @@ toc: false
|Date|Description|Ticket|
|----|-----------|------|
+|2012/09/10|Update the vendored systemu gem|16289|
|2012/09/06|Improve error reporting for empty certificate files|15924|
|2012/09/05|Restore the verbose behavior while building packages|16216|
|2012/09/04|Add a fetch method that mimic Hash#fetch to RPC Results and Requests|16222|

0 comments on commit 3337bd1

Please sign in to comment.