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 /
PermissionDenied→Ok(None). - File size ≠ 4 bytes →
Ok(None)with alog::debug!entry (defensive: sheared reads, FreeBSD text-UUID/etc/hostidmistakenly placed on Linux). - Value
0x00000000or0xffffffff→Ok(None)with alog::debug!entry (unset or known-garbage sentinels). - Other I/O error →
Err(Error::Io). - Otherwise →
Ok(Some(Probe::new(SourceKind::LinuxHostId, "<hex>"))).
Implementations§
Trait Implementations§
Source§impl Clone for LinuxHostIdFile
impl Clone for LinuxHostIdFile
Source§fn clone(&self) -> LinuxHostIdFile
fn clone(&self) -> LinuxHostIdFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more