Method: ComputeUnit::Device.read_kernel_setting

Defined in:
lib/compute_unit/device.rb

.read_kernel_setting(device_path, setting, default = 0) ⇒ String

Returns - read a kernel setting using the device_path.

Parameters:

  • - (String)

    the device_path to read from

  • - (String)

    the name of the kernel file in the device path to read

  • - (Object)

    a default value to use if there is a problem reading the setting

Returns:

  • (String)
    • read a kernel setting using the device_path



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/compute_unit/device.rb', line 265

def self.read_kernel_setting(device_path, setting, default = 0)
  path = File.join(device_path, setting)
  logger.debug("reading kernel file #{path}")
  value = begin
    File.read(path).chomp
          rescue Errno::EINVAL, Errno::EPERM
            logger.fatal(e.message)
            default
          rescue Errno::ENOENT
            logger.debug("File #{path} does not exist")
            default
          rescue Errno::EACCES
            logger.fatal('Run this command as root or with sudo')
            default
  end
end