diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-03-09 17:47:10 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-03-14 21:30:22 +0000 |
| commit | 8ab402b25249cc9659bcd07823b0a4f101f5fec2 (patch) | |
| tree | 1d16c65e8d6fe3ba86243ad145d24fa1748240d8 | |
| parent | .desktop: 'terminal' is not a common icon name (diff) | |
server/client: add XDG_SESSION_ID to the default socket path
This allows multiple foot servers to run in multiple sessions.
| -rw-r--r-- | client.c | 5 | ||||
| -rw-r--r-- | config.c | 8 |
2 files changed, 10 insertions, 3 deletions
@@ -135,10 +135,13 @@ main(int argc, char *const *argv) } else { bool connected = false; + const char *xdg_session_id = getenv("XDG_SESSION_ID"); const char *xdg_runtime = getenv("XDG_RUNTIME_DIR"); if (xdg_runtime != NULL) { - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot.sock", xdg_runtime); + if (xdg_session_id == NULL) + xdg_session_id = "<no-session>"; + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot-%s.sock", xdg_runtime, xdg_session_id); if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0) connected = true; else @@ -561,12 +561,16 @@ err: static char * get_server_socket_path(void) { + const char *xdg_session_id = getenv("XDG_SESSION_ID"); const char *xdg_runtime = getenv("XDG_RUNTIME_DIR"); if (xdg_runtime == NULL) return strdup("/tmp/foot.sock"); - char *path = malloc(strlen(xdg_runtime) + 1 + strlen("foot.sock") + 1); - sprintf(path, "%s/foot.sock", xdg_runtime); + if (xdg_session_id == NULL) + xdg_session_id = "<no-session>"; + + char *path = malloc(strlen(xdg_runtime) + 1 + strlen("foot-.sock") + strlen(xdg_session_id) + 1); + sprintf(path, "%s/foot-%s.sock", xdg_runtime, xdg_session_id); return path; } |
