Skip to content

Commit fa0cafe

Browse files
committed
fix: use systemd first-boot detection for rollback check
Fixes misleading warning on first boot and on systems with non-persistent journald storage. Signed-off-by: Sarita Mahajan <sarmahaj@redhat.com>
1 parent 4c7211f commit fa0cafe

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ where
167167
fn check_previous_rollback() -> Result<bool> {
168168
log::debug!("Checking journalctl for previous rollback attempts...");
169169

170+
// Use systemd's first-boot detection to skip the rollback check on first boot.
171+
// This is more reliable than journalctl --list-boots, which would also skip
172+
// on systems with non-persistent journald storage.
173+
let first_boot_check = Command::new("systemd-analyze")
174+
.arg("condition")
175+
.arg("ConditionFirstBoot=yes")
176+
.output()
177+
.context("Failed to execute 'systemd-analyze condition ConditionFirstBoot=yes'")?;
178+
179+
if first_boot_check.status.success() {
180+
log::debug!("First boot detected, skipping rollback check");
181+
return Ok(false);
182+
}
183+
170184
let output = Command::new("journalctl")
171185
.arg("-b")
172186
.arg("-1")
@@ -186,8 +200,7 @@ fn check_previous_rollback() -> Result<bool> {
186200
return Ok(false);
187201
}
188202

189-
let journal_output =
190-
String::from_utf8(output.stdout).context("Failed to parse journalctl output as UTF-8")?;
203+
let journal_output = String::from_utf8_lossy(&output.stdout);
191204

192205
if journal_output.trim().is_empty() {
193206
log::debug!("No rollback service logs found in previous boot");

0 commit comments

Comments
 (0)