Browse Source

Build Discord IPC path with snprintf instead of std::string.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
3c23abadc4
1 changed files with 10 additions and 11 deletions
  1. +10
    -11
      src/discord.cpp

+ 10
- 11
src/discord.cpp View File

@@ -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");


Loading…
Cancel
Save