From 90d349a8e716502bf0d4966ea98596bfcdc7d3cf Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 27 Apr 2022 20:08:05 +0200 Subject: [PATCH] main: Add (optional) systemd notify --- Cargo.toml | 4 +++- data/cosmic-comp.service | 2 +- src/main.rs | 3 +++ src/systemd.rs | 23 +++++++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/systemd.rs diff --git a/Cargo.toml b/Cargo.toml index 6f97f120..14700a5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ indexmap = "1.8.0" xdg = "^2.1" ron = "0.7" atomic_float = "0.1" +libsystemd = "0.5" [dependencies.smithay] version = "0.3" @@ -56,4 +57,5 @@ debug = true lto = "fat" [patch."https://github.com/Smithay/smithay.git"] -smithay = { git = "https://github.com/pop-os/smithay", branch = "main" } \ No newline at end of file +smithay = { git = "https://github.com/pop-os/smithay", branch = "main" } +#smithay = { path = "../smithay" } \ No newline at end of file diff --git a/data/cosmic-comp.service b/data/cosmic-comp.service index 85a90663..5778da1d 100644 --- a/data/cosmic-comp.service +++ b/data/cosmic-comp.service @@ -6,7 +6,7 @@ After=cosmic-session-pre.target Before=cosmic-session.target [Service] -Type=simple +Type=notify ExecStart=/usr/bin/cosmic-comp Restart=never ExecStopPost=/usr/bin/systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 42845d2d..7c0cca4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ pub mod input; mod logger; pub mod shell; pub mod state; +pub mod systemd; pub mod utils; pub mod wayland; @@ -33,6 +34,8 @@ fn main() -> Result<()> { let mut state = state::State::new(display, socket, event_loop.handle(), event_loop.get_signal(), log); // init backend backend::init_backend_auto(&mut event_loop, &mut state)?; + // potentially tell systemd we are setup now + systemd::ready(&state); // run the event loop event_loop.run(None, &mut state, |state| { diff --git a/src/systemd.rs b/src/systemd.rs new file mode 100644 index 00000000..15ec3765 --- /dev/null +++ b/src/systemd.rs @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-only + +use libsystemd::daemon::{booted, notify, NotifyState}; +use std::process::Command; +use crate::state::State; + +pub fn ready(state: &State) { + if booted() { + match Command::new("systemctl") + .args(["--user", "import-environment", "WAYLAND_DISPLAY"]) + .env("WAYLAND_DISPLAY", &state.common.socket) + .status() + { + Ok(x) if x.success() => {}, + Ok(x) => slog_scope::warn!("Failed to import WAYLAND_DISPLAY into systemd (exit code {:?})", x.code()), + Err(err) => slog_scope::error!("Failed to run systemctl although booted with systemd: {}", err), + }; + + if let Err(err) = notify(false, &[NotifyState::Ready]) { + slog_scope::error!("Failed to notify systemd: {}", err); + } + } +} \ No newline at end of file