Skip to content

Hijacking Passenger #2

@jeroenvandijk

Description

@jeroenvandijk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions