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.



51
52
53
54
55
56
# 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) ⇒ 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.



39
40
41
42
43
44
45
# 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) ⇒ 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

#run!(action, *args) ⇒ Object

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.

Raises:

  • (SystemCallError)


25
26
27
28
29
30
# 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