"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Unix/Main.cpp" (10 Oct 2018, 3097 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Main.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #include "System.h"
   14 #include <sys/mman.h>
   15 
   16 #include "Platform/Platform.h"
   17 #include "Platform/SystemLog.h"
   18 #include "Volume/EncryptionThreadPool.h"
   19 #include "Core/Unix/CoreService.h"
   20 #include "Main/Application.h"
   21 #include "Main/Main.h"
   22 #include "Main/UserInterface.h"
   23 
   24 #if defined (TC_MACOSX) && !defined (TC_NO_GUI)
   25 #include <ApplicationServices/ApplicationServices.h>
   26 #endif
   27 
   28 using namespace VeraCrypt;
   29 
   30 int main (int argc, char **argv)
   31 {
   32     try
   33     {
   34         // Make sure all required commands can be executed via default search path
   35         string sysPathStr = "/usr/sbin:/sbin:/usr/bin:/bin";
   36 
   37         char *sysPath = getenv ("PATH");
   38         if (sysPath)
   39         {
   40             sysPathStr += ":";
   41             sysPathStr += sysPath;
   42         }
   43 
   44         setenv ("PATH", sysPathStr.c_str(), 1);
   45 
   46         if (argc > 1 && strcmp (argv[1], TC_CORE_SERVICE_CMDLINE_OPTION) == 0)
   47         {
   48             // Process elevated requests
   49             try
   50             {
   51                 CoreService::ProcessElevatedRequests();
   52                 return 0;
   53             }
   54             catch (exception &e)
   55             {
   56 #ifdef DEBUG
   57                 SystemLog::WriteException (e);
   58 #endif
   59             }
   60             catch (...) { }
   61             return 1;
   62         }
   63 
   64         // Start core service
   65         CoreService::Start();
   66         finally_do ({ CoreService::Stop(); });
   67 
   68         // Start encryption thread pool
   69         EncryptionThreadPool::Start();
   70         finally_do ({ EncryptionThreadPool::Stop(); });
   71 
   72 #ifdef TC_NO_GUI
   73         bool forceTextUI = true;
   74 #else
   75         bool forceTextUI = false;
   76 #endif
   77 
   78 #ifdef __WXGTK__
   79         if (!getenv ("DISPLAY"))
   80             forceTextUI = true;
   81 #endif
   82 
   83         // Initialize application
   84         if (forceTextUI || (argc > 1 && (strcmp (argv[1], "-t") == 0 || strcmp (argv[1], "--text") == 0)))
   85         {
   86             Application::Initialize (UserInterfaceType::Text);
   87         }
   88         else
   89         {
   90 #if defined (TC_MACOSX) && !defined (TC_NO_GUI)
   91             if (argc > 1 && !(argc == 2 && strstr (argv[1], "-psn_") == argv[1]))
   92             {
   93                 ProcessSerialNumber p;
   94                 if (GetCurrentProcess (&p) == noErr)
   95                 {
   96                     TransformProcessType (&p, kProcessTransformToForegroundApplication);
   97                     SetFrontProcess (&p);
   98                 }
   99             }
  100 #endif
  101             Application::Initialize (UserInterfaceType::Graphic);
  102         }
  103 
  104         Application::SetExitCode (1);
  105 
  106         // Start application
  107         if (::wxEntry (argc, argv) == 0)
  108             Application::SetExitCode (0);
  109     }
  110     catch (ErrorMessage &e)
  111     {
  112         wcerr << wstring (e) << endl;
  113     }
  114     catch (SystemException &e)
  115     {
  116         wstringstream s;
  117         if (e.GetSubject().empty())
  118             s << e.what() << endl << e.SystemText();
  119         else
  120             s << e.what() << endl << e.SystemText() << endl << e.GetSubject();
  121         wcerr << s.str() << endl;
  122     }
  123     catch (exception &e)
  124     {
  125         stringstream s;
  126         s << StringConverter::GetTypeName (typeid (e)) << endl << e.what();
  127         cerr << s.str() << endl;
  128     }
  129 
  130     return Application::GetExitCode();
  131 }