Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(ipc): Add check if IPC init failed
Browse files Browse the repository at this point in the history
Also add error code to debug message.

Partially fix #4785
  • Loading branch information
Diadlo committed Nov 22, 2017
1 parent fb92ef9 commit c274cec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c274cec

Please sign in to comment.