diff --git a/src/discord.cpp b/src/discord.cpp index 6c201f8b..aa89921d 100644 --- a/src/discord.cpp +++ b/src/discord.cpp @@ -86,21 +86,20 @@ static void run() { DEFER({close(fd);}); // Get socket path - const char* env = getenv("XDG_RUNTIME_DIR"); - if (!env) - env = getenv("TMPDIR"); - if (!env) - env = getenv("TMP"); - if (!env) - env = getenv("TEMP"); - if (!env) - env = "/tmp"; - std::string path = std::string() + env + "/discord-ipc-0"; + const char* dir = getenv("XDG_RUNTIME_DIR"); + if (!dir) + dir = getenv("TMPDIR"); + if (!dir) + dir = getenv("TMP"); + if (!dir) + dir = getenv("TEMP"); + if (!dir) + dir = "/tmp"; // Connect to socket struct sockaddr_un addr; addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path.c_str()); + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/discord-ipc-0", dir); if (connect(fd, (struct sockaddr*) &addr, sizeof(addr))) { // Fail silently since this just means Discord isn't open. // WARN("Could not bind Discord socket");