Sha256: 921e491acd349795f4158c3eb4db9fd7fa2ebd3b48d2ac10abdb724dd25ce08c

Contents?: true

Size: 976 Bytes

Versions: 17

Compression:

Stored size: 976 Bytes

Contents

begin
  # If rubygems is present, keep it out of the way when loading fiddle,
  # otherwise if fiddle is not installed then rubygems will load all
  # gemspecs in its (futile) search for fiddle, which is slow.
  if respond_to?(:gem_original_require, true)
    gem_original_require 'fiddle'
  else
    require 'fiddle'
  end
rescue LoadError
end

module Spring
  module SID
    def self.fiddle_func
      @fiddle_func ||= Fiddle::Function.new(
        DL::Handle::DEFAULT['getsid'],
        [Fiddle::TYPE_INT],
        Fiddle::TYPE_INT
      )
    end

    def self.sid
      @sid ||= begin
        if Process.respond_to?(:getsid)
          # Ruby 2
          Process.getsid
        elsif defined?(Fiddle)
          # Ruby 1.9.3 compiled with libffi support
          fiddle_func.call(0)
        else
          # last resort: shell out
          `ps -p #{Process.pid} -o sess=`.to_i
        end
      end
    end

    def self.pgid
      Process.getpgid(sid)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
spring-1.1.3 lib/spring/sid.rb
spring-1.1.2 lib/spring/sid.rb
spring-1.1.1 lib/spring/sid.rb
spring-1.1.0 lib/spring/sid.rb
spring-1.1.0.beta4 lib/spring/sid.rb
spring-1.1.0.beta3 lib/spring/sid.rb
spring-1.1.0.beta2 lib/spring/sid.rb
spring-1.1.0.beta1 lib/spring/sid.rb
spring-1.0.0 lib/spring/sid.rb
spring-0.9.2 lib/spring/sid.rb
spring-0.9.1 lib/spring/sid.rb
spring-0.9.0 lib/spring/sid.rb
spring-0.0.11 lib/spring/sid.rb
spring-0.0.10 lib/spring/sid.rb
spring-0.0.9 lib/spring/sid.rb
spring-0.0.8 lib/spring/sid.rb
spring-0.0.7 lib/spring/sid.rb