How Do I Create an XDG_RUNTIME_DIR
2026-05-05
In Linux distributions without systemd (such as Void, Alpine, or Gentoo), configuring the XDG_RUNTIME_DIR environment variable is required for running Wayland compositors, PipeWire, and D-Bus user sessions.
The Freedesktop base directory specification mandates that this directory must be owned by the user (0700 permissions), created on login, removed on full logout, and must not survive a reboot.
I. User-Space and Scripting Solutions
These operate in the user's login shell. Due to privilege and phase limitations, they rarely meet the specification securely.
-
Fixed Path Scripts (
mkdir /tmp/run-$UID) -
Mechanism: Creates a directory in a globally writable path.
-
Flaws: High security risk. Predictable paths allow malicious users to hijack the directory via symlinks or cause DoS.
-
Random Paths & File Locks (mkrundir)
-
Mechanism: Creates a randomized directory in
/tmpand uses locks in$HOMEto sync sessions. -
Flaws: Breaks graphical Display Managers (GDM/SDDM) because they bypass shell profiles. Causes issues if
$HOMEis shared over NFS.
II. System-Level and Session Management Solutions
These operate within the PAM stack using root privileges, resolving permission and DM compatibility issues.
-
Status: Fully compliant.
-
Mechanism: Independent session manager extracted from systemd.
-
Flaws: Heavy and maintains a hard dependency on D-Bus.
-
Status: Fully compliant.
-
Mechanism: A lightweight, modern PAM module + daemon solution that uses process-level reference counters.
-
Flaws: Requires a permanent background daemon.
-
Status: Fully compliant.
-
Mechanism: A pure C PAM module using
flockto maintain a hidden session counter. -
Flaws: Only tracks PAM login sessions. It is unaware of lingering processes like
tmuxorgpg-agent. When the last terminal closes, it runsrm -rf, deleting the runtime directory and severing the active UNIX sockets of your background tasks. -
Status: Non-compliant.
-
Mechanism: Creates the directory at
/run/user/$UIDwith correct permissions upon login. It performs no cleanup on logout.
III. Conclusion and Final Selection
Considering security, complexity, and background process compatibility, pam_dumb_runtime_dir is my choice.
As the author states:
"Creates an
XDG_RUNTIME_DIRdirectory on login per the freedesktop.org base directory spec. Flaunts the spec and never removes it, even after last logout. This keeps things simple and predictable."
Why this is acceptable:
- Memory Management:
/runis almost always atmpfs(RAM-based filesystem). Although files persist after logout, they are wiped instantly upon reboot or power loss. - Safety: By refusing to clean up, it avoids the "murderous" behavior of
pam_rundir, ensuringtmuxsockets and background daemons remain accessible until the system shuts down. - Simplicity: It avoids background daemons, complex counting logic, and external dependencies.