Class: KeyControl::System

Inherits:
Object
  • Object
show all
Defined in:
lib/key_control/system.rb

Instance Method Summary collapse

Instance Method Details

#errorObject

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

Returns a Symbol or nil.



36
37
38
39
40
41
# File 'lib/key_control/system.rb', line 36

def error
  Errno.constants.detect do |error_name|
    errno = Errno.const_get(error_name)
    errno::Errno == Fiddle.last_error
  end
end

#get(action, *args) ⇒ Object

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.



24
25
26
27
28
29
30
# File 'lib/key_control/system.rb', line 24

def get(action, *args)
  length = run(action, *args, "", 0)
  buffer = "\x00" * length
  run(action, *args, buffer, length)

  buffer
end

#run(action, *args) ⇒ Object

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.



13
14
15
# File 'lib/key_control/system.rb', line 13

def run(action, *args)
  send(action).call(*args)
end