From 6fcc010ce084741313610ff64824c2384dcc29e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Ravier?= Date: Mon, 2 Sep 2024 16:58:27 +0200 Subject: [PATCH] bootupctl: Clear failure status from previous runs If for whatever reason a bootupd command fails, it will leave the systemd service unit in a failed state and systemd will then refuse to run a unit under the same name with `systemd-run` again until the failure is cleared. Thus systematically call `systemctl reset-failed` before calling `systemd-run` to clear any potential failures from previous calls. Do not check the return code of the systemctl command on purpose as it may fail if the unit does not exists yet, i.e. if no bootupctl command has been run yet. Also ignore stdout/stderr to avoid showing unexpected errors messages to users. See: https://github.com/coreos/bootupd/issues/707 See: https://github.com/coreos/bootupd/pull/663 --- src/cli/bootupctl.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cli/bootupctl.rs b/src/cli/bootupctl.rs index 123d42bd..ab86f9f8 100644 --- a/src/cli/bootupctl.rs +++ b/src/cli/bootupctl.rs @@ -4,7 +4,7 @@ use clap::Parser; use log::LevelFilter; use std::os::unix::process::CommandExt; -use std::process::Command; +use std::process::{Command, Stdio}; static SYSTEMD_ARGS_BOOTUPD: &[&str] = &[ "--unit", @@ -154,6 +154,14 @@ fn ensure_running_in_systemd() -> Result<()> { require_root_permission()?; let running_in_systemd = running_in_systemd(); if !running_in_systemd { + // Clear any failure status that may have happened previously + let _r = Command::new("systemctl") + .arg("reset-failed") + .arg("bootupd.service") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn()? + .wait()?; let r = Command::new("systemd-run") .args(SYSTEMD_ARGS_BOOTUPD) .args(std::env::args())