Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hijacking Passenger #2

Open
jeroenvandijk opened this issue Sep 1, 2009 · 1 comment
Open

Hijacking Passenger #2

jeroenvandijk opened this issue Sep 1, 2009 · 1 comment

Comments

@jeroenvandijk
Copy link

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_receiver_ready([\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
Copy link
Owner

ileitch commented Jul 10, 2012

Please try 0.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants