class KeyControl::System

Public Instance Methods

error() click to toggle source

Public: Get a symbol representing the reason for the last error set by a system call.

Returns a Symbol or nil.

# File lib/key_control/system.rb, line 51
def error
  Errno.constants.detect do |error_name|
    errno = Errno.const_get(error_name)
    errno::Errno == Fiddle.last_error
  end
end
get(action, *args) click to toggle source

Public: Execute the requested keyctl action, buffering the output into a string in multiple passes.

action - The action to perform. args - A list of arguments which should be passed to the action.

Returns a String containing the buffered output.

# File lib/key_control/system.rb, line 39
def get(action, *args)
  length = run(action, *args, "", 0)
  buffer = "\x00" * length
  run(action, *args, buffer, length)

  buffer
end
run(action, *args) click to toggle source

Public: Execute the requested action in keyctl.

action - The action to perform. args - A list of arguments which should be passed to the action.

Returns the stdout value returned by the call.

# File lib/key_control/system.rb, line 13
def run(action, *args)
  send(action).call(*args)
end
run!(action, *args) click to toggle source

Public: Execute the requested action in keyctl, raising an error on failure.

action - The action to perform. args - A list of arguments which should be passed to the action.

Returns the stdout value returned by the call. Raises a SystemCallError if the requested system call fails.

# File lib/key_control/system.rb, line 25
def run!(action, *args)
  result = run(action, *args)
  raise SystemCallError.new(action.to_s, Fiddle.last_error) if result == -1

  result
end

Private Instance Methods

add() click to toggle source

Private: Get a proc representing the add_key system call.

Returns a Fiddle::Function.

# File lib/key_control/system.rb, line 77
def add
  @add ||= Fiddle::Function.new(
    keyutils["add_key"],
    [ Fiddle::ALIGN_CHAR,
      Fiddle::ALIGN_CHAR,
      Fiddle::TYPE_VOIDP,
      Fiddle::TYPE_SIZE_T,
      Fiddle::TYPE_INT ],
    Fiddle::TYPE_INT )
end
keyutils() click to toggle source

Private: Get a handle representing the system calls available through libkeyutils.so.

Returns a Fiddle::Handle.

# File lib/key_control/system.rb, line 64
def keyutils
  @keyutils ||= KeyControl::LIBRARIES.detect do |library|
    begin
      break Fiddle::Handle.new(library)
    rescue Fiddle::DLError
      nil
    end
  end
end
read() click to toggle source

Private: Get a proc representing the keyctl_read system call.

Returns a Fiddle::Function.

# File lib/key_control/system.rb, line 91
def read
  @read ||= Fiddle::Function.new(
    keyutils["keyctl_read"],
    [ Fiddle::TYPE_INT,
      Fiddle::ALIGN_CHAR,
      Fiddle::TYPE_SIZE_T ],
    Fiddle::TYPE_LONG )
end
set_timeout() click to toggle source

Private: Get a proc representing the keyctl_set_timeout system call.

Returns a Fiddle::Function.

# File lib/key_control/system.rb, line 116
def set_timeout
  @set_timeout ||= Fiddle::Function.new(
    keyutils["keyctl_set_timeout"],
    [ Fiddle::TYPE_INT,
      Fiddle::TYPE_INT ],
    Fiddle::TYPE_LONG )
end