Class: OsCtld::KernelParams

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/osctld/kernel_params.rb

Overview

Interface to kernel command line parameters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKernelParams

Returns a new instance of KernelParams.



18
19
20
21
# File 'lib/osctld/kernel_params.rb', line 18

def initialize
  @cache = {}
  @params = File.read('/proc/cmdline').strip.split
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



16
17
18
# File 'lib/osctld/kernel_params.rb', line 16

def params
  @params
end

Instance Method Details

#autostart_cts?Boolean

Check parameter osctl.autostart

Enabled by default.

Returns:

  • (Boolean)


57
58
59
# File 'lib/osctld/kernel_params.rb', line 57

def autostart_cts?
  cache(:autostart) { read_kv('osctl.autostart', '1') == '1' }
end

#cache(name) ⇒ Object (protected)



63
64
65
66
67
# File 'lib/osctld/kernel_params.rb', line 63

def cache(name)
  return @cache[name] if @cache.has_key?(name)

  @cache[name] = yield
end

#import_pools?Boolean

Check parameter osctl.pools

Enabled by default.

Returns:

  • (Boolean)


50
51
52
# File 'lib/osctld/kernel_params.rb', line 50

def import_pools?
  cache(:pools) { read_kv('osctl.pools', '1') == '1' }
end

#include?(name) ⇒ Boolean

Check if parameter is set

Parameters:

  • name (String)

Returns:

  • (Boolean)


25
26
27
# File 'lib/osctld/kernel_params.rb', line 25

def include?(name)
  params.include?(name)
end

#read_kv(k, default_v) ⇒ String

Extract key-value parameter

Parameters:

  • k (String)

    parameter name

  • default_v (String)

    default value

Returns:

  • (String)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/osctld/kernel_params.rb', line 33

def read_kv(k, default_v)
  params.each do |param|
    eq = param.index('=')
    next if eq.nil?

    param_k = param[0..eq - 1]
    next if param_k != k

    return param[eq + 1..]
  end

  default_v
end