Permalink
Browse files

Added a --mute option to skip starting the OutputReceiver

  • Loading branch information...
Ian Leitch
Ian Leitch committed Sep 16, 2009
1 parent af962e0 commit fd6c8aaca4fa2236dc231e7b36c6c86c7882d2d6
Showing with 27 additions and 21 deletions.
  1. +2 −1 bin/hijack
  2. +21 −19 lib/hijack/console.rb
  3. +1 −1 lib/hijack/helper.rb
  4. +3 −0 test/test.rb
View
@@ -11,7 +11,8 @@ new_argv.delete(pid)
new_argv.options do |opts|
opts.banner = usage
- opts.on("--gdb-debug", "Print gdb activity to the console.") { |v| options[:gdb_debug] = v }
+ opts.on("--gdb-debug", "Print gdb activity to the console.") { |v| options[:gdb_debug] = true }
+ opts.on("--mute", "Ignore stdout/stderr writes from the remote process.") { |v| options[:mute] = true }
opts.on("-e", "--execute=FILE", String, "Execute the specified file in the remote process and then disconnect.") { |v| options[:execute] = v }
opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
opts.parse!
View
@@ -15,7 +15,7 @@ def initialize(pid)
mirror_process
banner
execute_file
- start_output_receiver
+ OutputReceiver.start(@remote) unless Hijack.options[:mute]
start_irb
end
@@ -36,7 +36,7 @@ def signal_drb_start
Process.kill('USR2', @pid.to_i)
loop do
break if File.exists?(Hijack.socket_path_for(@pid))
- sleep 0.1
+ sleep 0.01
end
end
@@ -45,30 +45,32 @@ def connect
end
module OutputReceiver
- @@mute = false
+ class << self
+ def mute
+ @mute = true
+ end
- def self.mute
- @@mute = true
- end
+ def unmute(remote)
+ start(remote) unless @started
+ @mute = false
+ end
- def self.unmute
- @@mute = false
- end
+ def write(where, str)
+ Object.const_get(where.upcase).write(str) unless @mute
+ end
- def self.write(where, str)
- Object.const_get(where.upcase).write(str) unless @@mute
- end
+ def puts(where, str)
+ Object.const_get(where.upcase).puts(str) unless @mute
+ end
- def self.puts(where, str)
- Object.const_get(where.upcase).puts(str) unless @@mute
+ def start(remote)
+ DRb.start_service(Hijack.socket_for(Process.pid), self)
+ remote.evaluate("__hijack_output_receiver_ready_#{Process.pid}")
+ @started = true
+ end
end
end
- def start_output_receiver
- DRb.start_service(Hijack.socket_for(Process.pid), OutputReceiver)
- @remote.evaluate("__hijack_output_receiver_ready_#{Process.pid}")
- end
-
def mirror_process
# Attempt to require all files currently loaded by the remote process so DRb can dump as many objects as possible.
#
View
@@ -20,7 +20,7 @@ def hijack_mute(remote)
end
def hijack_unmute(remote)
- Hijack::Console::OutputReceiver.unmute
+ Hijack::Console::OutputReceiver.unmute(remote)
true
end
View
@@ -1,5 +1,8 @@
#!/usr/bin/ruby
+class SomeClass
+end
+
def do_shit(i)
puts i
end

0 comments on commit fd6c8aa

Please sign in to comment.