mirror of https://github.com/PCSX2/pcsx2.git
IPC: conform to the XDG base specification on linux
This commit is contained in:
parent
136b6d8098
commit
cd0bf66434
|
@ -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);
|
||||
|
|
21
pcsx2/IPC.h
21
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. */
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue