mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-22 15:51:29 -04:00
Prevent multiple instances from running on Unix systems.
Every call to RsInit::LoadCertificates() now creates a file: ~/.retroshare/xxxxxxxxxxxxxxxxxxxx/lock which is then bound to a system lock (fcntl F_SETLK). If the lock request fails, it means another instance is already running with the same profile. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3241 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
840f077826
commit
fe46d7618a
7 changed files with 221 additions and 47 deletions
|
@ -320,19 +320,27 @@ void GenCertDialog::checkChanged(int i)
|
|||
|
||||
void GenCertDialog::loadCertificates()
|
||||
{
|
||||
bool autoSave = false;
|
||||
/* Final stage of loading */
|
||||
if (RsInit::LoadCertificates(autoSave))
|
||||
int retVal = RsInit::LockAndLoadCertificates(false);
|
||||
switch(retVal)
|
||||
{
|
||||
close();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* some error msg */
|
||||
QMessageBox::warning ( NULL,
|
||||
"Generate ID Failure",
|
||||
"Failed to Load your new Certificate!",
|
||||
QMessageBox::Ok);
|
||||
case 0: close();
|
||||
break;
|
||||
case 1: QMessageBox::warning( this,
|
||||
tr("Multiple instances"),
|
||||
tr("Another RetroShare using the same profile is "
|
||||
"already running on your system. Please close "
|
||||
"that instance first") );
|
||||
break;
|
||||
case 2: QMessageBox::warning( this,
|
||||
tr("Multiple instances"),
|
||||
tr("An unexpected error occurred when Retroshare"
|
||||
"tried to acquire the single instance lock") );
|
||||
break;
|
||||
case 3: QMessageBox::warning( this,
|
||||
tr("Generate ID Failure"),
|
||||
tr("Failed to Load your new Certificate!") );
|
||||
break;
|
||||
default: std::cerr << "StartDialog::loadCertificates() unexpected switch value " << retVal << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,18 +152,27 @@ void StartDialog::loadPerson()
|
|||
void StartDialog::loadCertificates()
|
||||
{
|
||||
/* Final stage of loading */
|
||||
|
||||
if (RsInit::LoadCertificates(ui.autologin_checkbox->isChecked()))
|
||||
int retVal = RsInit::LockAndLoadCertificates(ui.autologin_checkbox->isChecked());
|
||||
switch(retVal)
|
||||
{
|
||||
close();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* some error msg */
|
||||
QMessageBox::warning ( this,
|
||||
tr("Login Failure"),
|
||||
tr("Maybe password is wrong"),
|
||||
QMessageBox::Ok);
|
||||
case 0: close();
|
||||
break;
|
||||
case 1: QMessageBox::warning( this,
|
||||
tr("Multiple instances"),
|
||||
tr("Another RetroShare using the same profile is "
|
||||
"already running on your system. Please close "
|
||||
"that instance first, or choose another profile") );
|
||||
break;
|
||||
case 2: QMessageBox::warning( this,
|
||||
tr("Multiple instances"),
|
||||
tr("An unexpected error occurred when Retroshare"
|
||||
"tried to acquire the single instance lock") );
|
||||
break;
|
||||
case 3: QMessageBox::warning( this,
|
||||
tr("Login Failure"),
|
||||
tr("Maybe password is wrong") );
|
||||
break;
|
||||
default: std::cerr << "StartDialog::loadCertificates() unexpected switch value " << retVal << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,27 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
// true: note auto-login is active
|
||||
RsInit::LoadCertificates(true);
|
||||
int retVal = RsInit::LockAndLoadCertificates(true);
|
||||
switch(retVal)
|
||||
{
|
||||
case 0: break;
|
||||
case 1: QMessageBox::warning( 0,
|
||||
QObject::tr("Multiple instances"),
|
||||
QObject::tr("Another RetroShare using the same profile is "
|
||||
"already running on your system. Please close "
|
||||
"that instance first") );
|
||||
return 1;
|
||||
case 2: QMessageBox::critical( 0,
|
||||
QObject::tr("Multiple instances"),
|
||||
QObject::tr("An unexpected error occurred when Retroshare"
|
||||
"tried to acquire the single instance lock") );
|
||||
return 1;
|
||||
case 3: QMessageBox::critical( 0,
|
||||
QObject::tr("Login Failure"),
|
||||
QObject::tr("Maybe password is wrong") );
|
||||
return 1;
|
||||
default: std::cerr << "StartDialog::loadCertificates() unexpected switch value " << retVal << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
rsicontrol->StartupRetroShare();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue