From 2fe1918083f99cde499eb8bc73c08851553bbd32 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Mon, 13 Apr 2020 00:29:47 -0700 Subject: [PATCH] feat(ipc): make IPC user specific This allows multiple users on a system each running qTox to use IPC at once. Fix #6076 --- src/ipc.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ipc.cpp b/src/ipc.cpp index d98c08a7c..36d4fb29b 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -21,9 +21,37 @@ #include #include #include + #include #include #include +#include + +namespace +{ +#ifdef Q_OS_WIN + const char* getCurUsername() + { + return getenv("USERNAME"); + } +#else + const char* getCurUsername() + { + return getenv("USER"); + } +#endif + + QString getIpcKey() + { + auto* user = getCurUsername(); + if (!user) + { + qWarning() << "Failed to get current username. Will use a global IPC."; + user = ""; + } + return QString("qtox-" IPC_PROTOCOL_VERSION "-") + user; + } +} // namespace /** * @var time_t IPC::lastEvent @@ -40,7 +68,7 @@ IPC::IPC(uint32_t profileId) : profileId{profileId} - , globalMemory{"qtox-" IPC_PROTOCOL_VERSION} + , globalMemory{getIpcKey()} { qRegisterMetaType("IPCEventHandler");