diff --git a/rust/src/client.rs b/rust/src/client.rs index 33303d9157..cb0b73c75e 100644 --- a/rust/src/client.rs +++ b/rust/src/client.rs @@ -7,6 +7,7 @@ use crate::utils; use anyhow::{anyhow, Result}; use gio::DBusProxyExt; use std::os::unix::io::IntoRawFd; +use std::process::Command; /// The well-known bus name. const BUS_NAME: &str = "org.projectatomic.rpmostree1"; @@ -126,3 +127,29 @@ pub(crate) fn client_handle_fd_argument(arg: &str, arch: &str) -> CxxResult CxxResult<()> { + let service = "rpm-ostreed.service"; + // Assume non-root can't use systemd right now. + if !nix::unistd::getuid().is_root() { + return Ok(()); + } + let res = Command::new("systemctl") + .args(&["--no-ask-password", "start", service]) + .status()?; + if !res.success() { + let _ = Command::new("systemctl") + .args(&["status", service]) + .status(); + return Err(anyhow!("{}", res).into()); + } + Ok(()) +} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 6bd6de2574..0637434c24 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -63,6 +63,7 @@ pub mod ffi { // client.rs extern "Rust" { + fn client_start_daemon() -> Result<()>; fn client_handle_fd_argument(arg: &str, arch: &str) -> Result>; } diff --git a/src/app/rpmostree-clientlib.cxx b/src/app/rpmostree-clientlib.cxx index 9e278e540e..3754c26922 100644 --- a/src/app/rpmostree-clientlib.cxx +++ b/src/app/rpmostree-clientlib.cxx @@ -82,6 +82,8 @@ app_load_sysroot_impl (const char *sysroot, { const char *bus_name = NULL; + rpmostreecxx::client_start_daemon(); + g_autoptr(GDBusConnection) connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error); if (!connection) return glnx_prefix_error (error, "Connecting to system bus"); diff --git a/tests/kolainst/nondestructive/misc.sh b/tests/kolainst/nondestructive/misc.sh index 91132ba0d6..f51f502ee7 100755 --- a/tests/kolainst/nondestructive/misc.sh +++ b/tests/kolainst/nondestructive/misc.sh @@ -106,6 +106,17 @@ mv /var/lib/rpm{.orig,} systemctl reset-failed rpm-ostreed echo "ok validated rpmdb" +systemctl stop rpm-ostreed +unshare -m /bin/bash -c 'mount -o remount,rw /boot && mkdir /boot/orig-loader && mv /boot/loader* /boot/orig-loader' +if rpm-ostree status &>err.txt; then + fatal "started rpm-ostreed with no /boot/loader" +fi +assert_file_has_content_literal err.txt "Unexpected state: /run/ostree-booted found, but no /boot/loader directory" +rm -f err.txt +unshare -m /bin/bash -c 'mount -o remount,rw /boot && mv /boot/orig-loader/* /boot' +systemctl restart rpm-ostreed +echo "ok daemon statup failure gives useful error" + rpm-ostree cleanup -p originpath=$(ostree admin --print-current-dir).origin unshare -m /bin/bash -c "mount -o remount,rw /sysroot && cp -a ${originpath}{,.orig} &&