Browse Source

fix(ipc): Add check if IPC init failed

Also add error code to debug message.

Partially fix #4785
reviewable/pr4817/r1
Diadlo 8 years ago
parent
commit
c274cec87e
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 8
      src/ipc.cpp
  2. 1
      src/ipc.h
  3. 9
      src/main.cpp

8
src/ipc.cpp

@ -72,7 +72,8 @@ IPC::IPC(uint32_t profileId) @@ -72,7 +72,8 @@ IPC::IPC(uint32_t profileId)
} else if (globalMemory.attach()) {
qDebug() << "Attaching to the global shared memory";
} else {
qDebug() << "Failed to attach to the global shared memory, giving up";
qDebug() << "Failed to attach to the global shared memory, giving up. Error:"
<< globalMemory.error();
return; // We won't be able to do any IPC without being attached, let's get outta here
}
@ -189,6 +190,11 @@ bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout /*=-1*/) @@ -189,6 +190,11 @@ bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout /*=-1*/)
return result;
}
bool IPC::isAttached() const
{
return globalMemory.isAttached();
}
void IPC::setProfileId(uint32_t profileId)
{
this->profileId = profileId;

1
src/ipc.h

@ -73,6 +73,7 @@ public: @@ -73,6 +73,7 @@ public:
void registerEventHandler(const QString& name, IPCEventHandler handler);
bool isEventAccepted(time_t time);
bool waitUntilAccepted(time_t time, int32_t timeout = -1);
bool isAttached() const;
public slots:
void setProfileId(uint32_t profileId);

9
src/main.cpp

@ -199,11 +199,16 @@ int main(int argc, char* argv[]) @@ -199,11 +199,16 @@ int main(int argc, char* argv[])
uint32_t profileId = Settings::getInstance().getCurrentProfileId();
IPC ipc(profileId);
if (!ipc.isAttached()) {
qCritical() << "Can't init IPC";
return EXIT_FAILURE;
}
QObject::connect(&Settings::getInstance(), &Settings::currentProfileIdChanged, &ipc,
&IPC::setProfileId);
if (sodium_init() < 0) // For the auto-updater
{
// For the auto-updater
if (sodium_init() < 0) {
qCritical() << "Can't init libsodium";
return EXIT_FAILURE;
}

Loading…
Cancel
Save