1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat(ipc): make IPC user specific

This allows multiple users on a system each running qTox to use IPC at once.

Fix #6076
This commit is contained in:
Anthony Bilinski 2020-04-13 00:29:47 -07:00
parent d028f9e394
commit 2fe1918083
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -21,9 +21,37 @@
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
#include <ctime>
#include <random>
#include <unistd.h>
#include <stdlib.h>
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>("IPCEventHandler");