repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
af42d4e
parent
f367693
author
Tristan Partin
date
2025-12-18 19:55:07 -0500 EST
Use XDG_RUNTIME_DIR for the socket directory if defined

XDG_RUNTIME_DIR[0] is a file path for user-specific runtime files, like
sockets.

It will typically be defined on Linux. I can't say for sure on BSDs, and
I know for certain it is not defined on macOS.

Link: https://specifications.freedesktop.org/basedir/latest/ [0]
Signed-off-by: Tristan Partin <tristan@partin.io>
3 files changed,  +17, -9
M CHANGELOG.md
+6, -0
 1@@ -2,6 +2,12 @@
 2 
 3 Use spec: https://common-changelog.org/
 4 
 5+## Unreleased
 6+
 7+### Added
 8+
 9+- Use `XDG_RUNTIME_DIR` environment variable for socket directory (takes precedence over `TMPDIR` and `/tmp`)
10+
11 ## v0.1.1 - 2025-12-16
12 
13 ### Changed
M README.md
+5, -3
 1@@ -160,10 +160,12 @@ Wow! Now you can setup all your os tiling windows how you like them for your pro
 2 
 3 ## socket file location
 4 
 5-Each session gets its own unix socket file. Right now, the default location is `/tmp/zmx-{uid}`. You can configure this using environment variables:
 6+Each session gets its own unix socket file. The default location depends on your environment variables (checked in priority order):
 7 
 8-- `TMPDIR` => overrides `/tmp`
 9-- `ZMX_DIR` => overrides `/tmp/zmx-{uid}`
10+1. `ZMX_DIR` => uses exact path (e.g., `/custom/path`)
11+2. `XDG_RUNTIME_DIR` => uses `{XDG_RUNTIME_DIR}/zmx` (recommended on Linux, typically results in `/run/user/{uid}/zmx`)
12+3. `TMPDIR` => uses `{TMPDIR}/zmx-{uid}` (appends uid for multi-user safety)
13+4. `/tmp` => uses `/tmp/zmx-{uid}` (default fallback, appends uid for multi-user safety)
14 
15 ## debugging
16 
M src/main.zig
+6, -6
 1@@ -79,12 +79,12 @@ const Cfg = struct {
 2         const tmpdir = posix.getenv("TMPDIR") orelse "/tmp";
 3         const uid = posix.getuid();
 4 
 5-        var socket_dir: []const u8 = "";
 6-        if (posix.getenv("ZMX_DIR")) |zmxdir| {
 7-            socket_dir = try alloc.dupe(u8, zmxdir);
 8-        } else {
 9-            socket_dir = try std.fmt.allocPrint(alloc, "{s}/zmx-{d}", .{ tmpdir, uid });
10-        }
11+        const socket_dir: []const u8 = if (posix.getenv("ZMX_DIR")) |zmxdir|
12+            try alloc.dupe(u8, zmxdir)
13+        else if (posix.getenv("XDG_RUNTIME_DIR")) |xdg_runtime|
14+            try std.fmt.allocPrint(alloc, "{s}/zmx", .{xdg_runtime})
15+        else
16+            try std.fmt.allocPrint(alloc, "{s}/zmx-{d}", .{ tmpdir, uid });
17         errdefer alloc.free(socket_dir);
18 
19         const log_dir = try std.fmt.allocPrint(alloc, "{s}/logs", .{socket_dir});