cosmic-comp/src/systemd.rs

38 lines
1.2 KiB
Rust
Raw Normal View History

2022-04-27 20:08:05 +02:00
// SPDX-License-Identifier: GPL-3.0-only
2022-05-03 13:37:51 +02:00
use crate::state::State;
2022-04-27 20:08:05 +02:00
use libsystemd::daemon::{booted, notify, NotifyState};
use std::process::Command;
use tracing::{error, warn};
2022-04-27 20:08:05 +02:00
pub fn ready(state: &State) {
if booted() {
match Command::new("systemctl")
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
2022-04-27 20:08:05 +02:00
.env("WAYLAND_DISPLAY", &state.common.socket)
.env(
"DISPLAY",
&state
.common
2023-11-22 12:44:11 +01:00
.shell
.xwayland_state
2023-03-07 20:28:41 +01:00
.as_ref()
.map(|s| format!(":{}", s.display))
.unwrap_or(String::new()),
)
2022-04-27 20:08:05 +02:00
.status()
{
2022-05-03 13:37:51 +02:00
Ok(x) if x.success() => {}
Ok(x) => warn!(
exit_code = ?x.code(),
"Failed to import WAYLAND_DISPLAY/DISPLAY into systemd",
2022-05-03 13:37:51 +02:00
),
Err(err) => error!(?err, "Failed to run systemctl although booted with systemd",),
2022-04-27 20:08:05 +02:00
};
if let Err(err) = notify(false, &[NotifyState::Ready]) {
error!(?err, "Failed to notify systemd");
2022-04-27 20:08:05 +02:00
}
}
2022-05-03 13:37:51 +02:00
}