2022-04-27 20:08:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2022-05-03 13:37:51 +02:00
|
|
|
use crate::state::State;
|
2022-04-27 20:08:05 +02:00
|
|
|
use libsystemd::daemon::{booted, notify, NotifyState};
|
|
|
|
|
use std::process::Command;
|
2023-02-24 17:41:52 +01:00
|
|
|
use tracing::{error, warn};
|
2022-04-27 20:08:05 +02:00
|
|
|
|
|
|
|
|
pub fn ready(state: &State) {
|
|
|
|
|
if booted() {
|
|
|
|
|
match Command::new("systemctl")
|
2023-01-24 18:08:52 +01:00
|
|
|
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
|
2022-04-27 20:08:05 +02:00
|
|
|
.env("WAYLAND_DISPLAY", &state.common.socket)
|
2023-01-24 18:08:52 +01:00
|
|
|
.env(
|
|
|
|
|
"DISPLAY",
|
|
|
|
|
&state
|
|
|
|
|
.common
|
2023-11-22 12:44:11 +01:00
|
|
|
.shell
|
2023-01-24 18:08:52 +01:00
|
|
|
.xwayland_state
|
2023-03-07 20:28:41 +01:00
|
|
|
.as_ref()
|
2023-01-25 13:20:17 +01:00
|
|
|
.map(|s| format!(":{}", s.display))
|
2023-01-24 18:08:52 +01:00
|
|
|
.unwrap_or(String::new()),
|
|
|
|
|
)
|
2022-04-27 20:08:05 +02:00
|
|
|
.status()
|
|
|
|
|
{
|
2022-05-03 13:37:51 +02:00
|
|
|
Ok(x) if x.success() => {}
|
2023-02-24 17:41:52 +01:00
|
|
|
Ok(x) => warn!(
|
|
|
|
|
exit_code = ?x.code(),
|
|
|
|
|
"Failed to import WAYLAND_DISPLAY/DISPLAY into systemd",
|
2022-05-03 13:37:51 +02:00
|
|
|
),
|
2023-02-24 17:41:52 +01: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]) {
|
2023-02-24 17:41:52 +01:00
|
|
|
error!(?err, "Failed to notify systemd");
|
2022-04-27 20:08:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-05-03 13:37:51 +02:00
|
|
|
}
|