cosmic-comp/src/systemd.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

2022-04-27 20:08:05 +02:00
// SPDX-License-Identifier: GPL-3.0-only
2024-04-24 09:34:46 -07:00
use crate::state::Common;
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
2024-04-24 09:34:46 -07:00
pub fn ready(common: &Common) {
2022-04-27 20:08:05 +02:00
if booted() {
match Command::new("systemctl")
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
2024-04-24 09:34:46 -07:00
.env("WAYLAND_DISPLAY", &common.socket)
.env(
"DISPLAY",
2025-10-16 13:50:32 +02:00
common
.xwayland_state
2023-03-07 20:28:41 +01:00
.as_ref()
.map(|s| format!(":{}", s.display))
2025-10-16 13:50:32 +02:00
.unwrap_or_default(),
)
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
}