Sha256: 0d8448d4b238012492765670773d2198d0cfe2bb5e092f99782ed91ab3b7935f

Contents?: true

Size: 1.68 KB

Versions: 27

Compression:

Stored size: 1.68 KB

Contents

module RSence
  
  # @private RSence async signal communication handler, uses temporary files for communication.
  #   Utilized by ARGVParser and Daemon.
  module SIGComm
    def self.delete_signal_response( pid_fn )
      sig_fn = pid_fn+'.response.'+signal
      if File.file?( sig_fn )
        File.delete( sig_fn )
      end
    end
    def self.write_signal_response( pid, pid_fn, signal )
      sig_fn = pid_fn+'.response.'+signal
      File.open(sig_fn,'w') do |file|
        file.write( pid.to_s )
      end
    end
    def self.wait_signal_response( pid, pid_fn, signal, timeout = 10,
                                   debug_pre = false, debug_suf = false,
                                   sleep_secs = 0.2, verbose=nil )
      sig_fn = pid_fn+'.response.'+signal
      verbose = RSence.args[:verbose] if verbose == nil
      begin
        if verbose and debug_pre
          print debug_pre
        end
        File.delete( sig_fn ) if File.exists?( sig_fn )
        status = Process.kill( signal, pid )
        time_out = Time.now + timeout
        until (time_out < Time.now) or File.exists?( sig_fn )
          if verbose
            print "."
            STDOUT.flush
          end
          sleep sleep_secs
        end
        if File.file?( sig_fn )
          sig_pid = File.read( sig_fn ).to_i
          if sig_pid != pid
            puts "Warning, signal PID mismatch. Expected #{pid}, got #{sig_pid}"
          end
          File.delete( sig_fn )
        else
          puts "Warning, signal response file disappeared! Expected #{sig_fn}"
        end
        puts debug_suf if verbose and debug_suf
        return true
      rescue Errno::ESRCH
        return false
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rsence-pre-2.3.0.22 lib/rsence/sigcomm.rb
rsence-pre-2.3.0.21 lib/rsence/sigcomm.rb
rsence-pre-2.3.0.20 lib/rsence/sigcomm.rb
rsence-pre-2.3.0.19 lib/rsence/sigcomm.rb
rsence-pre-2.3.0.18 lib/rsence/sigcomm.rb
rsence-pre-2.3.0.17 lib/rsence/sigcomm.rb
rsence-pre-2.3.0.16 lib/rsence/sigcomm.rb