ileitch / hijack

Provides an irb session to a running ruby process.
Other
750 stars 22 forks source link

Hijacking Passenger #2

Open jeroenvandijk opened 15 years ago

jeroenvandijk commented 15 years ago

I'm not sure whether this is an issue or a feature, but I thought it would be handy to hijack a passenger rails process to debug it :) Is this theoretically possible? Anyway, I tried the following without success (I tried with and without sudo):

$ passenger-memory-stats

75.6 MB 1.0 MB /Library/Ruby/Gems/1.8/gems/passenger-2.1.3/ext/apache2/ApplicationPoolServerExecutable

2828 ? 177.7 MB 102.5 MB Rails:

Gives pid 2828

So I try to hijack it :)

$ hijack 2828 --gdb-debug

Ends with:

. done 0x903e16fa in select$DARWIN_EXTSN () (gdb) call (void)rb_eval_string("require 'stringio'\n require 'drb'\n\n unless defined?(Hijack)\n module Hijack\n class OutputCopier\n def self.remote\n @@remote\n end\n\n def self.start(pid)\n @@remote = DRbObject.new(nil, 'drbunix://tmp/hijack.' + pid + '.sock')\n\n class << $stdout\n def write_with_copying(str)\n write_without_copying(str)\n Hijack::OutputCopier.remote.write('stdout', str) rescue nil\n end\n alias_method :write_without_copying, :write\n alias_method :write, :write_with_copying\n end\n\n class << $stderr\n def write_with_copying(str)\n write_without_copying(str)\n Hijack::OutputCopier.remote.write('stderr', str) rescue nil\n end\n alias_method :write_without_copying, :write\n alias_method :write, :write_with_copying\n end\n end\n end\n\n class Evaluator\n def initialize(context)\n @context = context\n @file = FILE\n end\n\n def evaluate(rb)\n if rb =~ /hijack_output_receiverready([\d]+)/\n OutputCopier.start($1)\n elsif rb =~ /hijack_get_remote_file_name/\n @file\n else\n @context.instance_eval(rb)\n end\n end\n end\n\n def self.start(context)\n return if @service && @service.alive?\n evaluator = Hijack::Evaluator.new(context)\n @service = DRb.start_service('drbunix://tmp/hijack.2998.sock', evaluator)\n File.chmod(0600, '/tmp/hijack.2998.sock')\n end\n end\n end\n __hijack_context = self\n Signal.trap('USR2') { Hijack.start(__hijack_context) }") Detaching from program: `/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby', process 2998 thread 0x203.

ileitch commented 12 years ago

Please try 0.2.1.