Sha256: 40e4e1d77c82811113ebd8fe4025d666fc692ef9d315d24b7df4dfd4f364e32f

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# Monkey patch Signal.trap for Puma to keep it from overriding our handlers
# Also prevent Puma from registering its own SIGHUP handler
module Puma
  class Signal
    class << self
      alias os_trap trap
      def Signal.trap(sig, &block)
        sigshortname = sig.gsub "SIG", ''
        Oxidized::Signals.register_signal(sig, block) unless sigshortname.eql? 'HUP'
      end
    end
  end
end

module Oxidized
  class Signals
    @handlers = Hash.new { |h, k| h[k] = [] }
    class << self
      attr_accessor :handlers

      def register_signal(sig, procobj)
        # Compute short name of the signal (without SIG prefix)
        sigshortname = sig.gsub "SIG", ''
        signum = Signal.list[sigshortname]

        # Register the handler with OS
        Signal.trap signum do
          Oxidized::Signals.handle_signal(signum)
        end

        # Add the proc to the handler list for the requested signal
        @handlers[signum].push(procobj)
      end

      def handle_signal(signum)
        return unless handlers.has_key?(signum)

        @handlers[signum].each do |handler|
          handler.call
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oxidized-0.31.0 lib/oxidized/signals.rb
oxidized-0.30.1 lib/oxidized/signals.rb
oxidized-0.30.0 lib/oxidized/signals.rb