Module: DEBUGGER__::ForkInterceptor

Defined in:
lib/debug/session.rb

Defined Under Namespace

Modules: DaemonInterceptor

Instance Method Summary collapse

Instance Method Details

#_forkObject



2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
# File 'lib/debug/session.rb', line 2399

def _fork
  return super unless defined?(SESSION) && SESSION.active?

  parent_hook, child_hook = __fork_setup_for_debugger

  super.tap do |pid|
    if pid != 0
      # after fork: parent
      parent_hook.call pid
    else
      # after fork: child
      child_hook.call
    end
  end
end

#fork(&given_block) ⇒ Object



2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
# File 'lib/debug/session.rb', line 2415

def fork(&given_block)
  return super unless defined?(SESSION) && SESSION.active?
  parent_hook, child_hook = __fork_setup_for_debugger

  if given_block
    new_block = proc {
      # after fork: child
      child_hook.call
      given_block.call
    }
    super(&new_block).tap{|pid| parent_hook.call(pid)}
  else
    super.tap do |pid|
      if pid
        # after fork: parent
        parent_hook.call pid
      else
        # after fork: child
        child_hook.call
      end
    end
  end
end