cosmic-comp/src/systemd.rs
Alyssa Ross 2b360a8dd7 main: notify readiness on non-systemd systems
Other service supervisors implement systemd's readiness notification
protocol.  For example, s6 implements it with the
s6-notify-fd-from-socket[1] program.  libsystemd::daemon::notify
already checks for NOTIFY_SOCKET being set, which should be sufficient
to tell if systemd-style readiness notification is wanted.

Link: https://skarnet.org/software/s6/s6-notify-fd-from-socket.html [1]
2026-07-15 22:55:25 +02:00

35 lines
1.1 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-only
use crate::state::Common;
use libsystemd::daemon::{NotifyState, booted, notify};
use std::process::Command;
use tracing::{error, warn};
pub fn ready(common: &Common) {
if booted() {
match Command::new("systemctl")
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
.env("WAYLAND_DISPLAY", &common.socket)
.env(
"DISPLAY",
common
.xwayland_state
.as_ref()
.map(|s| format!(":{}", s.display))
.unwrap_or_default(),
)
.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");
}
}