Skip to main content

LinuxHostIdFile

Struct LinuxHostIdFile 

Source
pub struct LinuxHostIdFile { /* private fields */ }
Expand description

/etc/hostid — the glibc 4-byte binary hostid file read by gethostid(3) and hostid(1).

Opt-in only: not part of crate::sources::default_chain or [crate::sources::network_default_chain]. On stock Linux distros the file is absent (no sethostid has run), so defaulting it would cost every caller a syscall for a near-universal miss. Ship it as a constructible type so operators who know they have /etc/hostid (OpenZFS hosts, minimal non-systemd images, Red Hat containers that bind-mount machine-id but not hostid) can push it explicitly.

§File format

glibc stores the hostid as four raw bytes in native byte order (sethostid(2)). Decoded with u32::from_ne_bytes(...) and formatted as 8-digit lowercase hex to match hostid(1) output.

§Why we don’t call gethostid(3)

When /etc/hostid is absent glibc fabricates a value from gethostname() → IPv4 lookup. That value is neither stable nor unique and would flow through as identity — actively harmful. This source reads the file directly; absence yields Ok(None) so the resolver falls through.

§Probe behaviour

  • File absent / PermissionDeniedOk(None).
  • File size ≠ 4 bytes → Ok(None) with a log::debug! entry (defensive: sheared reads, FreeBSD text-UUID /etc/hostid mistakenly placed on Linux).
  • Value 0x00000000 or 0xffffffffOk(None) with a log::debug! entry (unset or known-garbage sentinels).
  • Other I/O error → Err(Error::Io).
  • Otherwise → Ok(Some(Probe::new(SourceKind::LinuxHostId, "<hex>"))).

Implementations§

Source§

impl LinuxHostIdFile

Source

pub fn new() -> Self

Read from the standard path (/etc/hostid).

Source

pub fn at(path: impl Into<PathBuf>) -> Self

Read from a caller-supplied path. Useful for tests and unusual image layouts.

Source

pub fn path(&self) -> &Path

The configured path.

Trait Implementations§

Source§

impl Clone for LinuxHostIdFile

Source§

fn clone(&self) -> LinuxHostIdFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LinuxHostIdFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LinuxHostIdFile

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Source for LinuxHostIdFile

Source§

fn kind(&self) -> SourceKind

Provenance label for this source. Shown in error messages and the resolved crate::HostId.
Source§

fn probe(&self) -> Result<Option<Probe>, Error>

Attempt to produce a raw identifier. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.