From 6977ba09e3d30225eff667f6dfa5095d17073856 Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 18:03:32 -0700 Subject: [PATCH 1/8] Remove trailing whitespace. --- lib/open4.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/open4.rb b/lib/open4.rb index 0bac277..b27e795 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -139,7 +139,7 @@ def exitstatus end def initialize cmd, status @cmd, @status = cmd, status - @signals = {} + @signals = {} if status.signaled? @signals['termsig'] = status.termsig @signals['stopsig'] = status.stopsig @@ -286,7 +286,7 @@ def relay src, dst = nil, t = nil end module_function :relay - def spawn arg, *argv + def spawn arg, *argv argv.unshift(arg) opts = ((argv.size > 1 and Hash === argv.last) ? argv.pop : {}) argv.flatten! @@ -333,7 +333,7 @@ def spawn arg, *argv started = true %w( replace pid= << push update ).each do |msg| - break(pid.send(msg, c)) if pid.respond_to? msg + break(pid.send(msg, c)) if pid.respond_to? msg end te = ThreadEnsemble.new c @@ -372,7 +372,7 @@ def chdir cwd, &block end module_function :chdir - def background arg, *argv + def background arg, *argv require 'thread' q = Queue.new opts = { 'pid' => q, :pid => q } @@ -404,7 +404,7 @@ def maim pid, opts = {} sigs.each do |sig| begin Process.kill sig, pid - existed = true + existed = true rescue Errno::ESRCH return(existed ? nil : true) end @@ -412,7 +412,7 @@ def maim pid, opts = {} sleep suspend return true unless alive? pid end - return(not alive?(pid)) + return(not alive?(pid)) end module_function :maim From b801791c57b1099e34fa64c62abf2a09ede4fe18 Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 18:05:48 -0700 Subject: [PATCH 2/8] Eliminated local variable shadowing in Open4::background. --- lib/open4.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open4.rb b/lib/open4.rb index b27e795..8de2e82 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -382,7 +382,7 @@ def background arg, *argv else argv.push opts end - thread = Thread.new(arg, argv){|arg, argv| spawn arg, *argv} + thread = Thread.new(arg, argv){|p1, p2| spawn p1, *p2} sc = class << thread; self; end sc.module_eval { define_method(:pid){ @pid ||= q.pop } From 253af61acd5827ca2d128c894362f8ffb608afbf Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 18:12:58 -0700 Subject: [PATCH 3/8] Eliminated local variable shadowing in Open4::spawn. --- lib/open4.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/open4.rb b/lib/open4.rb index 8de2e82..71d2f33 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -338,17 +338,17 @@ def spawn arg, *argv te = ThreadEnsemble.new c - te.add_thread(i, stdin) do |i, stdin| - relay stdin, i, stdin_timeout - i.close rescue nil + te.add_thread(i, stdin) do |inc, std_in| + relay std_in, inc, stdin_timeout + inc.close rescue nil end - te.add_thread(o, stdout) do |o, stdout| - relay o, stdout, stdout_timeout + te.add_thread(o, stdout) do |out, std_out| + relay out, std_out, stdout_timeout end - te.add_thread(e, stderr) do |o, stderr| - relay e, stderr, stderr_timeout + te.add_thread(e, stderr) do |out, std_err| + relay e, std_err, stderr_timeout end te.run From 6465660c9cadc9f4466634b0d90cd665645b702f Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 18:16:55 -0700 Subject: [PATCH 4/8] Eliminated local variable shadowing in Open4::relay. --- lib/open4.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/open4.rb b/lib/open4.rb index 71d2f33..039c128 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -255,19 +255,19 @@ def relay src, dst = nil, t = nil q = Queue.new th = nil - timer_set = lambda do |t| - th = new_thread{ to(t){ q.pop } } + timer_set = lambda do |thd| + th = new_thread{ to(thd){ q.pop } } end - timer_cancel = lambda do |t| + timer_cancel = lambda do |thd| th.kill if th rescue nil end timer_set[t] begin - src.each do |buf| + src.each do |buff| timer_cancel[t] - send_dst[buf] + send_dst[buff] timer_set[t] end ensure From a3f3d76682b3d03ba46e376c743fdbc0ebe44b25 Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 18:21:19 -0700 Subject: [PATCH 5/8] Eliminated unused local variable (ignored) in Open4::getopts. --- lib/open4.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/open4.rb b/lib/open4.rb index 039c128..165f131 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -220,9 +220,12 @@ def new_thread *a, &b end module_function :new_thread + def random_dummy_function(*args) + end + def getopts opts = {} lambda do |*args| - keys, default, ignored = args + keys, default, _ = args catch(:opt) do [keys].flatten.each do |key| [key, key.to_s, key.to_s.intern].each do |key| From a4b8db655ecc00966b0796c20855730a1c669a2a Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 19:27:58 -0700 Subject: [PATCH 6/8] Eliminated local variable shadowing in Open4::getopts. --- lib/open4.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open4.rb b/lib/open4.rb index 165f131..6758110 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -228,8 +228,8 @@ def getopts opts = {} keys, default, _ = args catch(:opt) do [keys].flatten.each do |key| - [key, key.to_s, key.to_s.intern].each do |key| - throw :opt, opts[key] if opts.has_key?(key) + [key, key.to_s, key.to_s.intern].each do |k| + throw :opt, opts[k] if opts.has_key?(k) end end default From fd67982704edacec40bbb8850768c0bf4c1c321e Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 19:28:55 -0700 Subject: [PATCH 7/8] Eliminated local variable shadowing in Open4::new_thread. --- lib/open4.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open4.rb b/lib/open4.rb index 6758110..b1d77e7 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -210,9 +210,9 @@ def to timeout = nil def new_thread *a, &b cur = Thread.current - Thread.new(*a) do |*a| + Thread.new(*a) do |*args| begin - b[*a] + b[*args] rescue Exception => e cur.raise e end From 87631dde8c05573a065c53fb4daeec2a991584b7 Mon Sep 17 00:00:00 2001 From: Travis Herrick Date: Sun, 21 Oct 2012 19:31:44 -0700 Subject: [PATCH 8/8] Eliminated local variable shadowing in ThreadEnsemble#run. --- lib/open4.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open4.rb b/lib/open4.rb index b1d77e7..1403b7c 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -179,9 +179,9 @@ def run begin @argv.each do |a, b| - @threads << Thread.new(*a) do |*a| + @threads << Thread.new(*a) do |*args| begin - b[*a] + b[*args] ensure killall rescue nil if $! @done.push Thread.current