Skip to content

Commit 2304a78

Browse files
committed
feat(r6): user services get the login session environment; graphical sessions run without systemd
r6-user passes an explicit list of session variables (HOME, USER, XDG_RUNTIME_DIR, XDG_SESSION_*, locale, XDG paths, session bus address) to its services, which otherwise start with a clean environment. raze-session starts r6-user, waits for the session bus, runs the compositor and stops the user services on logout; raze-session-ready publishes WAYLAND_DISPLAY to r6 and D-Bus activation. Verified in a VM with r6 as PID 1: greetd login -> elogind session -> r6-user (session D-Bus, PipeWire, PipeWire-Pulse, WirePlumber) -> sway session with waybar, mako, polkit agent, D-Bus-activated portals and gvfs.
1 parent 18fae53 commit 2304a78

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎r6/src/bin/r6-user.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@ fn main() {
2626
std::process::exit(1);
2727
}
2828
};
29+
// Services get a clean environment; pass on the login session's identity and
30+
// locations (an explicit list, not everything the session happens to have).
31+
const SESSION_VARS: &[&str] = &[
32+
"HOME",
33+
"USER",
34+
"LOGNAME",
35+
"SHELL",
36+
"LANG",
37+
"LANGUAGE",
38+
"XDG_RUNTIME_DIR",
39+
"XDG_SESSION_ID",
40+
"XDG_SESSION_TYPE",
41+
"XDG_SESSION_CLASS",
42+
"XDG_SEAT",
43+
"XDG_VTNR",
44+
"XDG_DATA_DIRS",
45+
"XDG_CONFIG_DIRS",
46+
"XDG_CONFIG_HOME",
47+
"XDG_DATA_HOME",
48+
"XDG_STATE_HOME",
49+
"XDG_CACHE_HOME",
50+
"DBUS_SESSION_BUS_ADDRESS",
51+
"LOCALE_ARCHIVE",
52+
"TZDIR",
53+
];
54+
sup.set_env(
55+
std::env::vars()
56+
.filter(|(k, _)| SESSION_VARS.contains(&k.as_str()) || k.starts_with("LC_")),
57+
);
2958
sup.reap_stale();
3059
if !args.iter().any(|a| a == "--no-boot") {
3160
sup.activate_boot_set();

‎r6/src/supervisor.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ impl Supervisor {
309309
}
310310
}
311311

312+
/// Add variables to the environment of every service started from now on (the
313+
/// same mechanism as `r6 setenv`).
314+
pub fn set_env(&mut self, vars: impl IntoIterator<Item = (String, String)>) {
315+
self.extra_env.extend(vars);
316+
}
317+
312318
pub fn activate_boot_set(&mut self) {
313319
let enabled: Vec<String> = self
314320
.set

‎r6/tests/supervisor.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ fn user_supervisor_uses_session_locations() {
647647
std::fs::write(
648648
home.join(".config/r6/services/hello.toml"),
649649
format!(
650-
"command = [\"/bin/sh\", \"-c\", \"echo hi > {}; exec sleep 1000\"]\nenable = true\n",
650+
"command = [\"/bin/sh\", \"-c\", \"echo $XDG_RUNTIME_DIR > {}; exec sleep 1000\"]\nenable = true\n",
651651
out.display()
652652
),
653653
)
@@ -665,6 +665,11 @@ fn user_supervisor_uses_session_locations() {
665665
let mut guard = KillOnDrop(child);
666666
assert!(wait_until(Duration::from_secs(5), || out.exists()));
667667
assert!(runtime.join("r6/control.sock").exists());
668+
// Session variables reach user services.
669+
let ok = wait_until(Duration::from_secs(2), || {
670+
std::fs::read_to_string(&out).unwrap_or_default().trim() == runtime.display().to_string()
671+
});
672+
assert!(ok, "service saw XDG_RUNTIME_DIR={:?}", std::fs::read_to_string(&out));
668673
let mut st = Command::new(env!("CARGO_BIN_EXE_r6"));
669674
env(&mut st);
670675
let o = st

0 commit comments

Comments
 (0)