cosmic-comp/src/systemd.rs
2023-11-23 12:57:42 +01:00

37 lines
1.2 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-only
use crate::state::State;
use libsystemd::daemon::{booted, notify, NotifyState};
use std::process::Command;
use tracing::{error, warn};
pub fn ready(state: &State) {
if booted() {
match Command::new("systemctl")
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
.env("WAYLAND_DISPLAY", &state.common.socket)
.env(
"DISPLAY",
&state
.common
.shell
.xwayland_state
.as_ref()
.map(|s| format!(":{}", s.display))
.unwrap_or(String::new()),
)
.status()
{
Ok(x) if x.success() => {}
Ok(x) => warn!(
exit_code = ?x.code(),
"Failed to import WAYLAND_DISPLAY/DISPLAY into systemd",
),
Err(err) => error!(?err, "Failed to run systemctl although booted with systemd",),
};
if let Err(err) = notify(false, &[NotifyState::Ready]) {
error!(?err, "Failed to notify systemd");
}
}
}