VirtualBox

Changeset 52577 in vbox


Ignore:
Timestamp:
Sep 3, 2014 9:59:36 AM (10 years ago)
Author:
vboxsync
Message:

Additions/x11/VBoxClient: more clean-up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/main.cpp

    r52562 r52577  
    7272            system(pszCommand);
    7373    }
    74     exit(1);
     74    _exit(1);
    7575}
    7676
     
    8484    int rc = RTCritSectEnter(&g_critSect);
    8585    if (RT_FAILURE(rc))
    86     {
    87         LogRel(("VBoxClient: Failure while acquiring the global critical section, rc=%Rrc\n", rc));
    88         abort();
    89     }
     86        VBClFatalError(("VBoxClient: Failure while acquiring the global critical section, rc=%Rrc\n", rc));
    9087    if (g_pService)
    9188        (*g_pService)->cleanup(g_pService);
     
    9996 * A standard signal handler which cleans up and exits.
    10097 */
    101 void vboxClientSignalHandler(int cSignal)
     98static void vboxClientSignalHandler(int cSignal)
    10299{
    103100    LogRel(("VBoxClient: terminated with signal %d\n", cSignal));
     
    110107 * Xlib error handler for certain errors that we can't avoid.
    111108 */
    112 int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
     109static int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
    113110{
    114111    char errorText[1024];
     
    134131 * cleans up and exits.
    135132 */
    136 void vboxClientSetSignalHandlers(void)
     133static void vboxClientSetSignalHandlers(void)
    137134{
    138135    struct sigaction sigAction;
     
    361358     * object should probably never be used from multiple threads anyway. */
    362359    if (!XInitThreads())
    363         return 1;
     360        VBClFatalError(("Failed to initialize X11 threads\n"));
    364361    /* Get our file name for error output. */
    365362    pcszFileName = RTPathFilename(argv[0]);
     
    369366    rc = VbglR3InitUser();
    370367    if (RT_FAILURE(rc))
    371     {
    372         RTPrintf("%s: failed to connect to the VirtualBox kernel service, rc=%Rrc\n",
    373                  pcszFileName, rc);
    374         return 1;
    375     }
     368        VBClFatalError(("%s: failed to connect to the VirtualBox kernel service, rc=%Rrc\n",
     369                 pcszFileName, rc));
    376370
    377371    /* Parse our option(s) */
     
    444438    }
    445439
    446     do {
    447         pcszStage = "Initialising critical section";
    448         rc = RTCritSectInit(&g_critSect);
    449         if (RT_FAILURE(rc))
    450             break;
    451         pcszStage = "Getting home directory for pid-file";
    452         rc = RTPathUserHome(g_szPidFile, sizeof(g_szPidFile));
    453         if (RT_FAILURE(rc))
    454             break;
    455         pcszStage = "Creating pid-file path";
    456         rc = RTPathAppend(g_szPidFile, sizeof(g_szPidFile),
    457                           (*g_pService)->getPidFilePath());
    458         if (RT_FAILURE(rc))
    459             break;
    460         pcszStage = "Daemonising";
    461         if (fDaemonise)
    462             rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */);
    463         if (RT_FAILURE(rc))
    464             break;
    465         pcszStage = "Creating pid-file";
    466         if (g_szPidFile[0])
    467             rc = VbglR3PidFile(g_szPidFile, &g_hPidFile);
    468         if (RT_FAILURE(rc))
    469             break;
    470         /* Set signal handlers to clean up on exit. */
    471         vboxClientSetSignalHandlers();
    472         /* Set an X11 error handler, so that we don't die when we get unavoidable
    473          * errors. */
    474         XSetErrorHandler(vboxClientXLibErrorHandler);
    475         /* Set an X11 I/O error handler, so that we can shutdown properly on
    476          * fatal errors. */
    477         XSetIOErrorHandler(vboxClientXLibIOErrorHandler);
    478         pcszStage = "Initialising service";
    479         rc = (*g_pService)->init(g_pService);
    480     } while (0);
    481     if (RT_FAILURE(rc))
    482     {
    483         LogRelFunc(("VBoxClient: failed at stage: \"%s\" rc: %Rrc\n",
    484                     pcszStage, rc));
    485         VbglR3Term();
    486         return 1;
    487     }
    488 
     440    rc = RTCritSectInit(&g_critSect);
     441    if (RT_FAILURE(rc))
     442        VBClFatalError(("Initialising critical section: %Rrc\n", rc));
     443    if (RT_FAILURE(rc))
     444        VBClFatalError(("Initialising critical section: %Rrc\n", rc));
     445    rc = RTPathUserHome(g_szPidFile, sizeof(g_szPidFile));
     446    if (RT_FAILURE(rc))
     447        VBClFatalError(("Getting home directory for pid-file: %Rrc\n", rc));
     448    rc = RTPathAppend(g_szPidFile, sizeof(g_szPidFile),
     449                      (*g_pService)->getPidFilePath());
     450    if (RT_FAILURE(rc))
     451        VBClFatalError(("Creating pid-file path: %Rrc\n", rc));
     452    if (fDaemonise)
     453        rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */);
     454    if (RT_FAILURE(rc))
     455        VBClFatalError(("Daemonizing: %Rrc\n", rc));
     456    if (g_szPidFile[0])
     457        rc = VbglR3PidFile(g_szPidFile, &g_hPidFile);
     458    if (RT_FAILURE(rc))
     459        VBClFatalError(("Creating pid-file: %Rrc\n", rc));
     460    /* Set signal handlers to clean up on exit. */
     461    vboxClientSetSignalHandlers();
     462    /* Set an X11 error handler, so that we don't die when we get unavoidable
     463     * errors. */
     464    XSetErrorHandler(vboxClientXLibErrorHandler);
     465    /* Set an X11 I/O error handler, so that we can shutdown properly on
     466     * fatal errors. */
     467    XSetIOErrorHandler(vboxClientXLibIOErrorHandler);
     468    rc = (*g_pService)->init(g_pService);
     469    if (RT_FAILURE(rc))
     470        VBClFatalError(("Initialising service: %Rrc\n", rc));
    489471    rc = startMonitorThread();
    490472    if (RT_FAILURE(rc))
    491         LogRel(("Failed to start the monitor thread (%Rrc).  Exiting.\n",
    492                  rc));
    493     else
    494         (*g_pService)->run(g_pService, fDaemonise);  /* Should never return. */
     473        VBClFatalError(("Starting monitor thread: %Rrc\n", rc));
     474    (*g_pService)->run(g_pService, fDaemonise);  /* Should never return. */
    495475    VBClCleanUp();
    496476    return 1;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette