From cd0bf66434abe3f659035453197b093c67194cf2 Mon Sep 17 00:00:00 2001 From: Gauvain 'GovanifY' Roussel-Tarbouriech Date: Sun, 30 Aug 2020 14:41:10 +0200 Subject: [PATCH] IPC: conform to the XDG base specification on linux --- pcsx2/IPC.cpp | 16 +++++++++++++--- pcsx2/IPC.h | 21 ++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pcsx2/IPC.cpp b/pcsx2/IPC.cpp index 6fc4c6d4a5..1ce6b8bf05 100644 --- a/pcsx2/IPC.cpp +++ b/pcsx2/IPC.cpp @@ -73,6 +73,16 @@ SocketIPC::SocketIPC(SysCoreThread* vm) } #else + // XXX: go back whenever we want to have multiple IPC instances with + // multiple emulators running and make this a folder + char* runtime_dir = std::getenv("XDG_RUNTIME_DIR"); + // fallback in case macOS or other OSes don't implement the XDG base + // spec + if (runtime_dir == NULL) + m_socket_name = (char*)"/tmp/pcsx2.sock"; + else + m_socket_name = strcat(runtime_dir, "/pcsx2.sock"); + struct sockaddr_un server; m_sock = socket(AF_UNIX, SOCK_STREAM, 0); @@ -82,11 +92,11 @@ SocketIPC::SocketIPC(SysCoreThread* vm) return; } server.sun_family = AF_UNIX; - strcpy(server.sun_path, SOCKET_NAME); + strcpy(server.sun_path, m_socket_name); // we unlink the socket so that when releasing this thread the socket gets // freed even if we didn't close correctly the loop - unlink(SOCKET_NAME); + unlink(m_socket_name); if (bind(m_sock, (struct sockaddr*)&server, sizeof(struct sockaddr_un))) { Console.WriteLn(Color_Red, "IPC: Error while binding to socket! Shutting down..."); @@ -213,7 +223,7 @@ SocketIPC::~SocketIPC() #ifdef _WIN32 WSACleanup(); #else - unlink(SOCKET_NAME); + unlink(m_socket_name); #endif close_portable(m_sock); close_portable(m_msgsock); diff --git a/pcsx2/IPC.h b/pcsx2/IPC.h index 6fb9f4bcb2..9e0bc793bd 100644 --- a/pcsx2/IPC.h +++ b/pcsx2/IPC.h @@ -38,9 +38,8 @@ protected: // the message socket used in thread's accept(). SOCKET m_msgsock = INVALID_SOCKET; #else - // absolute path of the socket. Stored in the temporary directory in linux since - // /run requires superuser permission - const char* SOCKET_NAME = "/tmp/pcsx2.sock"; + // absolute path of the socket. Stored in XDG_RUNTIME_DIR, if unset /tmp + char* m_socket_name; int m_sock = 0; // the message socket used in thread's accept(). int m_msgsock = 0; @@ -80,14 +79,14 @@ protected: */ enum IPCCommand : unsigned char { - MsgRead8 = 0, /**< Read 8 bit value to memory. */ - MsgRead16 = 1, /**< Read 16 bit value to memory. */ - MsgRead32 = 2, /**< Read 32 bit value to memory. */ - MsgRead64 = 3, /**< Read 64 bit value to memory. */ - MsgWrite8 = 4, /**< Write 8 bit value to memory. */ - MsgWrite16 = 5, /**< Write 16 bit value to memory. */ - MsgWrite32 = 6, /**< Write 32 bit value to memory. */ - MsgWrite64 = 7, /**< Write 64 bit value to memory. */ + MsgRead8 = 0, /**< Read 8 bit value to memory. */ + MsgRead16 = 1, /**< Read 16 bit value to memory. */ + MsgRead32 = 2, /**< Read 32 bit value to memory. */ + MsgRead64 = 3, /**< Read 64 bit value to memory. */ + MsgWrite8 = 4, /**< Write 8 bit value to memory. */ + MsgWrite16 = 5, /**< Write 16 bit value to memory. */ + MsgWrite32 = 6, /**< Write 32 bit value to memory. */ + MsgWrite64 = 7, /**< Write 64 bit value to memory. */ MsgUnimplemented = 0xFF /**< Unimplemented IPC message. */ };