From c274cec87e957894c021bd7f27994a2f6ce5473c Mon Sep 17 00:00:00 2001 From: Diadlo Date: Tue, 21 Nov 2017 20:25:39 +0300 Subject: [PATCH] fix(ipc): Add check if IPC init failed Also add error code to debug message. Partially fix #4785 --- src/ipc.cpp | 8 +++++++- src/ipc.h | 1 + src/main.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ipc.cpp b/src/ipc.cpp index 219eb7acb9..166066a3bb 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -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*/) return result; } +bool IPC::isAttached() const +{ + return globalMemory.isAttached(); +} + void IPC::setProfileId(uint32_t profileId) { this->profileId = profileId; diff --git a/src/ipc.h b/src/ipc.h index 4f4913d520..94964fd3ae 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -73,6 +73,7 @@ class IPC : public QObject 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); diff --git a/src/main.cpp b/src/main.cpp index ec35810193..b4d1c3845f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; }