Browse Source

feat(ipc): make IPC user specific

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

Fix #6076
reviewable/pr6085/r2
Anthony Bilinski 5 years ago
parent
commit
2fe1918083
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 30
      src/ipc.cpp

30
src/ipc.cpp

@ -21,9 +21,37 @@ @@ -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 @@ @@ -40,7 +68,7 @@
IPC::IPC(uint32_t profileId)
: profileId{profileId}
, globalMemory{"qtox-" IPC_PROTOCOL_VERSION}
, globalMemory{getIpcKey()}
{
qRegisterMetaType<IPCEventHandler>("IPCEventHandler");

Loading…
Cancel
Save