module Systemd::Id128

Provides access to the 128-bit IDs for various items in the systemd ecosystem, such as the machine id and boot id.

Public Class Methods

boot_id() click to toggle source

Get the 128-bit hex string identifying the current system's current boot. Can be used to filter a journal to show only messages originating from the current boot. @example Filter journal to the current boot.

j = Systemd::Journal.new
j.filter(_boot_id: Systemd::Id128.boot_id)

@return [String] 128-bit hex string representing the current boot.

# File lib/systemd/id128.rb, line 25
def self.boot_id
  @boot_id ||= read_id128(:sd_id128_get_boot)
end
machine_id() click to toggle source

Get the 128-bit hex string identifying the current machine. Can be used to filter a journal to show only messages originating from this machine. @example Filter journal to the current machine.

j = Systemd::Journal.new
j.filter(_machine_id: Systemd::Id128.machine_id)

@return [String] 128-bit hex string representing the current machine.

# File lib/systemd/id128.rb, line 14
def self.machine_id
  @machine_id ||= read_id128(:sd_id128_get_machine)
end
random() click to toggle source

Get a random 128-bit hex string. @return [String] 128-bit random hex string.

# File lib/systemd/id128.rb, line 31
def self.random
  read_id128(:sd_id128_randomize)
end

Private Class Methods

read_id128(func) click to toggle source
# File lib/systemd/id128.rb, line 37
def self.read_id128(func)
  ptr = FFI::MemoryPointer.new(Native::Id128, 1)
  rc = Native.send(func, ptr)
  raise JournalError, rc if rc < 0
  Native::Id128.new(ptr).to_s
end