forge
Explore
Log in

Don't you dare go Hollow

Add systemd feature flag for systemd-specific things

Browse files at this commit

d58a45a96c2fce2602224cd246b3576d0c975cf3Ivan MolodetskikhParent: 9f1b4ee
Cargo.tomlmodified+4 -2
@@ -97,9 +97,11 @@ proptest-derive = "0.4.0"
97 xshell = "0.2.5"97 xshell = "0.2.5"
98 98
99 [features]99 [features]
100-default = ["dbus", "xdp-gnome-screencast"]100+default = ["dbus", "systemd", "xdp-gnome-screencast"]
101-# Enables DBus support (required for xdp-gnome and power button inhibiting).101+# Enables D-Bus support (serve various freedesktop and GNOME interfaces, power button handling).
102 dbus = ["zbus", "async-channel", "async-io", "notify-rust", "url"]102 dbus = ["zbus", "async-channel", "async-io", "notify-rust", "url"]
103+# Enables systemd integration (global environment, apps in transient scopes).
104+systemd = ["dbus"]
103 # Enables screencasting support through xdg-desktop-portal-gnome.105 # Enables screencasting support through xdg-desktop-portal-gnome.
104 xdp-gnome-screencast = ["dbus", "pipewire"]106 xdp-gnome-screencast = ["dbus", "pipewire"]
105 # Enables the Tracy profiler instrumentation.107 # Enables the Tracy profiler instrumentation.
src/main.rsmodified+16 -3
@@ -38,7 +38,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
38 REMOVE_ENV_RUST_LIB_BACKTRACE.store(true, Ordering::Relaxed);38 REMOVE_ENV_RUST_LIB_BACKTRACE.store(true, Ordering::Relaxed);
39 }39 }
40 40
41- IS_SYSTEMD_SERVICE.store(env::var_os("NOTIFY_SOCKET").is_some(), Ordering::Relaxed);41+ if env::var_os("NOTIFY_SOCKET").is_some() {
42+ IS_SYSTEMD_SERVICE.store(true, Ordering::Relaxed);
43+
44+ #[cfg(not(feature = "systemd"))]
45+ warn!(
46+ "running as a systemd service, but systemd support is compiled out. \
47+ Are you sure you did not forget to set `--features systemd`?"
48+ );
49+ }
42 50
43 let directives = env::var("RUST_LOG").unwrap_or_else(|_| "niri=debug".to_owned());51 let directives = env::var("RUST_LOG").unwrap_or_else(|_| "niri=debug".to_owned());
44 let env_filter = EnvFilter::builder().parse_lossy(directives);52 let env_filter = EnvFilter::builder().parse_lossy(directives);
@@ -249,11 +257,16 @@ fn import_environment() {
249 ]257 ]
250 .join(" ");258 .join(" ");
251 259
260+ #[cfg(feature = "systemd")]
261+ let systemctl = format!("systemctl --user import-environment {variables} && ");
262+ #[cfg(not(feature = "systemd"))]
263+ let systemctl = String::new();
264+
252 let rv = Command::new("/bin/sh")265 let rv = Command::new("/bin/sh")
253 .args([266 .args([
254 "-c",267 "-c",
255 &format!(268 &format!(
256- "systemctl --user import-environment {variables} && \269+ "{systemctl}\
257 hash dbus-update-activation-environment 2>/dev/null && \270 hash dbus-update-activation-environment 2>/dev/null && \
258 dbus-update-activation-environment {variables}"271 dbus-update-activation-environment {variables}"
259 ),272 ),
@@ -273,7 +286,7 @@ fn import_environment() {
273 }286 }
274 },287 },
275 Err(err) => {288 Err(err) => {
276- warn!("error spawning shell to import environment into systemd: {err:?}");289+ warn!("error spawning shell to import environment: {err:?}");
277 }290 }
278 }291 }
279 }292 }
src/niri.rsmodified+0 -2
@@ -1063,8 +1063,6 @@ impl Niri {
1063 pub fn inhibit_power_key(&mut self) -> anyhow::Result<()> {1063 pub fn inhibit_power_key(&mut self) -> anyhow::Result<()> {
1064 let conn = zbus::blocking::ConnectionBuilder::system()?.build()?;1064 let conn = zbus::blocking::ConnectionBuilder::system()?.build()?;
1065 1065
1066- // logind-zbus has a wrong signature for this method, so do it manually.
1067- // https://gitlab.com/flukejones/logind-zbus/-/merge_requests/5
1068 let message = conn.call_method(1066 let message = conn.call_method(
1069 Some("org.freedesktop.login1"),1067 Some("org.freedesktop.login1"),
1070 "/org/freedesktop/login1",1068 "/org/freedesktop/login1",
src/utils.rsmodified+2 -2
@@ -229,7 +229,7 @@ fn spawn_sync(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl As
229 trace!("spawned PID: {pid}");229 trace!("spawned PID: {pid}");
230 230
231 // Start a systemd scope for the grandchild.231 // Start a systemd scope for the grandchild.
232- #[cfg(feature = "dbus")]232+ #[cfg(feature = "systemd")]
233 if let Err(err) = start_systemd_scope(command, child.id(), pid as u32) {233 if let Err(err) = start_systemd_scope(command, child.id(), pid as u32) {
234 trace!("error starting systemd scope for spawned command: {err:?}");234 trace!("error starting systemd scope for spawned command: {err:?}");
235 }235 }
@@ -292,7 +292,7 @@ pub static IS_SYSTEMD_SERVICE: AtomicBool = AtomicBool::new(false);
292 ///292 ///
293 /// This separates the pid from the compositor scope, which for example prevents the OOM killer293 /// This separates the pid from the compositor scope, which for example prevents the OOM killer
294 /// from bringing down the compositor together with a misbehaving client.294 /// from bringing down the compositor together with a misbehaving client.
295-#[cfg(feature = "dbus")]295+#[cfg(feature = "systemd")]
296 fn start_systemd_scope(name: &OsStr, intermediate_pid: u32, child_pid: u32) -> anyhow::Result<()> {296 fn start_systemd_scope(name: &OsStr, intermediate_pid: u32, child_pid: u32) -> anyhow::Result<()> {
297 use std::fmt::Write as _;297 use std::fmt::Write as _;
298 use std::path::Path;298 use std::path::Path;