mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-01-15 00:42:05 +08:00
chore: Failed to create instance
Sometimes Ubuntu20.04-24.04 execution of `d->memory->attach()` crashes here and prints the necessary information to determine that the creation has failed
This commit is contained in:
parent
494772e98c
commit
3d459bf28d
@ -72,8 +72,9 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
|
|||||||
#else
|
#else
|
||||||
d->memory = new QSharedMemory( d->blockServerName );
|
d->memory = new QSharedMemory( d->blockServerName );
|
||||||
#endif
|
#endif
|
||||||
d->memory->attach();
|
bool ok = d->memory->attach();
|
||||||
delete d->memory;
|
qCritical() << "d->memory->attach():" << ok;
|
||||||
|
if (ok) delete d->memory;
|
||||||
#endif
|
#endif
|
||||||
// Guarantee thread safe behaviour with a shared memory block.
|
// Guarantee thread safe behaviour with a shared memory block.
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
|
||||||
@ -91,16 +92,24 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
|
|||||||
}
|
}
|
||||||
d->initializeMemoryBlock();
|
d->initializeMemoryBlock();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
qCritical() << "Shared memory creation failed:" << d->memory->errorString();
|
||||||
|
|
||||||
if( d->memory->error() == QSharedMemory::AlreadyExists ){
|
if( d->memory->error() == QSharedMemory::AlreadyExists ){
|
||||||
// Attempt to attach to the memory segment
|
// Attempt to attach to the memory segment
|
||||||
if( ! d->memory->attach() ){
|
if( ! d->memory->attach() ){
|
||||||
qCritical() << "SingleApplication: Unable to attach to shared memory block.";
|
qCritical() << "SingleApplication: Unable to attach to shared memory block.";
|
||||||
abortSafely();
|
abortSafely();
|
||||||
|
} else {
|
||||||
|
qCritical() << "Successfully attached to existing shared memory block";
|
||||||
}
|
}
|
||||||
if( ! d->memory->lock() ){
|
if( ! d->memory->lock() ){
|
||||||
qCritical() << "SingleApplication: Unable to lock memory block after attach.";
|
qCritical() << "SingleApplication: Unable to lock memory block after attach.";
|
||||||
abortSafely();
|
abortSafely();
|
||||||
|
} else {
|
||||||
|
qCritical() << "Memory block successfully locked";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "SingleApplication: Unable to create block.";
|
qCritical() << "SingleApplication: Unable to create block.";
|
||||||
abortSafely();
|
abortSafely();
|
||||||
@ -108,6 +117,21 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto *inst = static_cast<InstancesInfo*>( d->memory->data() );
|
auto *inst = static_cast<InstancesInfo*>( d->memory->data() );
|
||||||
|
|
||||||
|
if (!inst) {
|
||||||
|
qCritical() << "Shared memory data is NULL!";
|
||||||
|
abortSafely();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
qCritical() << "Shared memory data doesn't NULL!";
|
||||||
|
qCritical() << "Primary: " << inst->primary << QString::asprintf("0x%X", inst->primary);
|
||||||
|
qCritical() << "Secondary: " << inst->secondary << QString::asprintf("0x%X", inst->secondary);
|
||||||
|
qCritical() << "Primary PID: " << inst->primaryPid << QString::asprintf("0x%llX", inst->primaryPid);
|
||||||
|
qCritical() << "Checksum: " << inst->checksum << QString::asprintf("0x%X", inst->checksum);
|
||||||
|
qCritical() << "Primary User: " << inst->primaryUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QElapsedTimer time;
|
QElapsedTimer time;
|
||||||
time.start();
|
time.start();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user