Skip to content

Commit

Permalink
Improve wtmp record mangling.
Browse files Browse the repository at this point in the history
This fixes two problems with the current wtmp/utmp record mangling.
First it is not idempotent, the system's notion of boot time is
set to the current time of day whenever sled agent confirms that
time is synchronised. Secondly, this is only approximate even for the
first sled agent start, but it's plain wrong if sled agent restarts
later.

In conjunction with changes to stlouis, the `tmpx` utility is now
able to process all zones itself, and uses the true system boot
time for each zone when updating records.
  • Loading branch information
citrus-it committed Nov 15, 2023
1 parent 9c33a62 commit 7939b9c
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2398,33 +2398,13 @@ impl ServiceManager {
return;
}

let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("SystemTime before UNIX EPOCH");

info!(self.inner.log, "Setting boot time to {:?}", now);

let files: Vec<Utf8PathBuf> = zones
.map(|z| z.root())
.chain(iter::once(Utf8PathBuf::from("/")))
.flat_map(|r| [r.join("var/adm/utmpx"), r.join("var/adm/wtmpx")])
.collect();

for file in files {
let mut command = std::process::Command::new(PFEXEC);
let cmd = command.args(&[
"/usr/platform/oxide/bin/tmpx",
&format!("{}", now.as_secs()),
&file.as_str(),
]);
match execute(cmd) {
Err(e) => {
warn!(self.inner.log, "Updating {} failed: {}", &file, e);
}
Ok(_) => {
info!(self.inner.log, "Updated {}", &file);
}
}
// Call out to the 'tmpx' utility program which will rewrite the wtmpx
// and utmpx databases in every zone, including the global zone, to
// reflect the adjusted system boot time.
let mut command = std::process::Command::new(PFEXEC);
let cmd = command.args(&["/usr/platform/oxide/bin/tmpx", "-Z"]);
if let Err(e) = execute(cmd) {
warn!(self.inner.log, "Updating [wu]tmpx databases failed: {}", e);
}
}

Expand Down

0 comments on commit 7939b9c

Please sign in to comment.