1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Allow to start multiple instances with -p

Starting a new instance with the -p option will force it to start a new instance with the given profile instead of bringing an eventual existing instance to the foreground

Two instances can not run with the same profiles, the profile locking code will ensure that. A user who likes to live dangerously could manually delete the lock to force two instances on the same profile, but such an hypothetical user would be asking for it.

If a qTox instance starts and becomes owner of the IPC shared memory on its first try, it considers itself the only running freshly-started instance, and deletes any possibly stale lock before starting up. This should be fine in the vast majority of cases, but if an existing qTox instance freezes for a long enough time to lose ownership of the IPC and a new instance is started without first killing the frozen one, the frozen instance's lock will be deleted as stale by the new one. If the frozen instance subsequentely unfreezes, it will be running on a profile for which it doesn't have a lock, which could cause trouble. This is an intentionaly allowed edge case, the alternative being a stale lock staying forever until removed manually. A potential solution not yet implemented would be to check that the lock is still actually present before attempting any write.
This commit is contained in:
tux3 2015-04-24 19:43:39 +02:00
parent 0baba7abe2
commit 05b6f1985d
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 15 additions and 3 deletions

View File

@ -893,7 +893,8 @@ QByteArray Core::loadToxSave(QString path)
tr("Your profile is already used by another qTox\n"
"Please select another profile"));
path = Settings::getInstance().askProfiles();
qWarning() << "New profile is "<<QFileInfo(path).baseName();
Settings::getInstance().switchProfile(QFileInfo(path).baseName());
HistoryKeeper::resetInstance();
}
QFile configurationFile(path);
@ -971,8 +972,19 @@ void Core::saveConfiguration()
saveConfiguration(path);
}
void Core::switchConfiguration(const QString& profile)
void Core::switchConfiguration(const QString& _profile)
{
QString profile = QFileInfo(_profile).baseName();
// If we can't get a lock, then another instance is already using that profile
while (!profile.isEmpty() && !ProfileLocker::lock(profile))
{
qWarning() << "Profile "<<profile<<" is already in use, pick another";
GUI::showWarning(tr("Profile already in use"),
tr("Your profile is already used by another qTox instance\n"
"Please select another profile"));
profile = QFileInfo(Settings::getInstance().askProfiles()).baseName();
}
if (profile.isEmpty())
qDebug() << "Core: creating new Id";
else

View File

@ -262,7 +262,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
}
else if (!ipc.isCurrentOwner())
else if (!ipc.isCurrentOwner() && !parser.isSet("p"))
{
uint32_t dest = 0;
if (parser.isSet("p"))