From c12db68363131d189d8410bf2994d70919229021 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Thu, 9 Mar 2023 14:13:57 +0100 Subject: footclient: fallback logic when socket paths don't exist Even if WAYLAND_DISPLAY / XDG_RUNTIME_DIR are defined, if we can't find the corresponding socket, we fallback to the path used when they are not defined. --- client.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index 99c7c1e8..41be68a9 100644 --- a/client.c +++ b/client.c @@ -374,16 +374,19 @@ main(int argc, char *const *argv) const char *xdg_runtime = getenv("XDG_RUNTIME_DIR"); if (xdg_runtime != NULL) { const char *wayland_display = getenv("WAYLAND_DISPLAY"); - if (wayland_display != NULL) + if (wayland_display != NULL) { snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot-%s.sock", xdg_runtime, wayland_display); - else + connected = (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0); + } + if (!connected) { + LOG_WARN("%s: failed to connect, will now try %s/foot.sock", + addr.sun_path, xdg_runtime); snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/foot.sock", xdg_runtime); - - if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0) - connected = true; - else + connected = (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == 0); + } + if (!connected) LOG_WARN("%s: failed to connect, will now try /tmp/foot.sock", addr.sun_path); } -- cgit v1.3