Skip to content

Commit

Permalink
Check the primary connection and assume primary if no response is found.
Browse files Browse the repository at this point in the history
This guards against the case of stale shared memory that can happen when
the primary application crashes or is forcefully killed.

Issue itay-grudev#190

Signed-off-by: Adam Treat <[email protected]>
  • Loading branch information
manyoso committed Aug 29, 2024
1 parent 494772e commit 21bdef0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions singleapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
}
}

// Check to ensure the primary process really does exist by sending a message and if it does not
// then assume primary status
if ( inst->primary != false && !d->connectToPrimary( timeout, SingleApplicationPrivate::SecondaryInstance )) {
qDebug() << "SingleApplication: Cannot communicate with primary so assuming primary status.";
inst->primary = false;
}

if( inst->primary == false ){
d->startPrimary();
if( ! d->memory->unlock() ){
Expand Down

0 comments on commit 21bdef0

Please sign in to comment.