main: Add (optional) systemd notify
This commit is contained in:
parent
75173fe697
commit
90d349a8e7
4 changed files with 30 additions and 2 deletions
|
|
@ -25,6 +25,7 @@ indexmap = "1.8.0"
|
||||||
xdg = "^2.1"
|
xdg = "^2.1"
|
||||||
ron = "0.7"
|
ron = "0.7"
|
||||||
atomic_float = "0.1"
|
atomic_float = "0.1"
|
||||||
|
libsystemd = "0.5"
|
||||||
|
|
||||||
[dependencies.smithay]
|
[dependencies.smithay]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
@ -57,3 +58,4 @@ lto = "fat"
|
||||||
|
|
||||||
[patch."https://github.com/Smithay/smithay.git"]
|
[patch."https://github.com/Smithay/smithay.git"]
|
||||||
smithay = { git = "https://github.com/pop-os/smithay", branch = "main" }
|
smithay = { git = "https://github.com/pop-os/smithay", branch = "main" }
|
||||||
|
#smithay = { path = "../smithay" }
|
||||||
|
|
@ -6,7 +6,7 @@ After=cosmic-session-pre.target
|
||||||
Before=cosmic-session.target
|
Before=cosmic-session.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=notify
|
||||||
ExecStart=/usr/bin/cosmic-comp
|
ExecStart=/usr/bin/cosmic-comp
|
||||||
Restart=never
|
Restart=never
|
||||||
ExecStopPost=/usr/bin/systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY
|
ExecStopPost=/usr/bin/systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY
|
||||||
|
|
@ -14,6 +14,7 @@ pub mod input;
|
||||||
mod logger;
|
mod logger;
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
pub mod systemd;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod wayland;
|
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);
|
let mut state = state::State::new(display, socket, event_loop.handle(), event_loop.get_signal(), log);
|
||||||
// init backend
|
// init backend
|
||||||
backend::init_backend_auto(&mut event_loop, &mut state)?;
|
backend::init_backend_auto(&mut event_loop, &mut state)?;
|
||||||
|
// potentially tell systemd we are setup now
|
||||||
|
systemd::ready(&state);
|
||||||
|
|
||||||
// run the event loop
|
// run the event loop
|
||||||
event_loop.run(None, &mut state, |state| {
|
event_loop.run(None, &mut state, |state| {
|
||||||
|
|
|
||||||
23
src/systemd.rs
Normal file
23
src/systemd.rs
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue