From d1a3316e4486433cb4d3f74016479998ac3ea62a Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 8 Feb 2015 17:54:08 +0100 Subject: Linux: solve rare issue where VeraCrypt wrongly reports that another instance is already running. That happens when VeraCrypt doesn't close cleanly upon shutdown/reboot and on the next startup another process is running with the same PID as VeraCrypt before shutdow/reboot. --- src/Main/GraphicUserInterface.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/Main/GraphicUserInterface.cpp') diff --git a/src/Main/GraphicUserInterface.cpp b/src/Main/GraphicUserInterface.cpp index 67d8d870..c29eef22 100644 --- a/src/Main/GraphicUserInterface.cpp +++ b/src/Main/GraphicUserInterface.cpp @@ -842,8 +842,9 @@ namespace VeraCrypt wxLogLevel logLevel = wxLog::GetLogLevel(); wxLog::SetLogLevel (wxLOG_Error); - - SingleInstanceChecker.reset (new wxSingleInstanceChecker (wxString (L".") + Application::GetName() + L"-lock-" + wxGetUserId())); + + const wxString instanceCheckerName = wxString (L".") + Application::GetName() + L"-lock-" + wxGetUserId(); + SingleInstanceChecker.reset (new wxSingleInstanceChecker (instanceCheckerName)); wxLog::SetLogLevel (logLevel); @@ -878,6 +879,7 @@ namespace VeraCrypt if (write (showFifo, buf, 1) == 1) { close (showFifo); + Gui->ShowInfo (_("VeraCrypt is already running.")); Application::SetExitCode (0); return false; } @@ -890,12 +892,28 @@ namespace VeraCrypt throw; #endif } -#endif + + // This is a false positive as VeraCrypt is not running (pipe not available) + // we continue running after cleaning the lock file + // and creating a new instance of the checker + wxString lockFileName = wxGetHomeDir(); + if ( lockFileName.Last() != wxT('/') ) + { + lockFileName += wxT('/'); + } + lockFileName << instanceCheckerName; + + if (wxRemoveFile (lockFileName)) + { + SingleInstanceChecker.reset (new wxSingleInstanceChecker (instanceCheckerName)); + } +#else wxLog::FlushActive(); Application::SetExitCode (1); Gui->ShowInfo (_("VeraCrypt is already running.")); return false; +#endif } #ifdef TC_WINDOWS -- cgit v1.2.3