main: Add (optional) systemd notify

This commit is contained in:
Victoria Brekenfeld 2022-04-27 20:08:05 +02:00
parent 75173fe697
commit 90d349a8e7
4 changed files with 30 additions and 2 deletions

23
src/systemd.rs Normal file
View 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);
}
}
}