VirtualBox

Changeset 68562 in vbox


Ignore:
Timestamp:
Aug 31, 2017 12:10:16 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
117779
Message:

merging vbglioc r117719: VBoxClient: avoid use RTEXITCODE where possible, use RTMsg* where possible, added options for forground execution (like VBoxService -f), added comprehensible error on syntax errors (wasting my time), wasted time figuring out that the logging to stdout fun done in the -d case is useless now (probably due to moving VbglR3InitUser from top of main() to service code).

Location:
trunk/src/VBox/Additions/x11/VBoxClient
Files:
2 edited

Legend:

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

    r67755 r68562  
    3636
    3737/** Call clean-up for the current service and exit. */
    38 extern void VBClCleanUp();
     38extern void VBClCleanUp(bool fExit = true);
    3939
    4040/** A simple interface describing a service.  VBoxClient will run exactly one
  • trunk/src/VBox/Additions/x11/VBoxClient/main.cpp

    r67755 r68562  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VirtualBox Guest Service:
    5  * Linux guest.
     3 * VirtualBox Guest Additions - X11 Client.
    64 */
    75
     
    6664unsigned cRespawn = 0;
    6765
    68 /** Exit with a fatal error. */
     66/**
     67 * Exit with a fatal error.
     68 *
     69 * This is used by the VBClFatalError macro and thus needs to be external.
     70 */
    6971void vbclFatalError(char *pszMessage)
    7072{
     
    9294        }
    9395    }
    94     _exit(1);
    95 }
    96 
    97 /** Clean up if we get a signal or something.  This is extern so that we
    98  * can call it from other compilation units. */
    99 void VBClCleanUp()
     96    _exit(RTEXITCODE_FAILURE);
     97}
     98
     99/**
     100 * Clean up if we get a signal or something.
     101 *
     102 * This is extern so that we can call it from other compilation units.
     103 */
     104void VBClCleanUp(bool fExit /*=true*/)
    100105{
    101106    /* We never release this, as we end up with a call to exit(3) which is not
     
    109114    if (g_szPidFile[0] && g_hPidFile)
    110115        VbglR3ClosePidFile(g_szPidFile, g_hPidFile);
    111     exit(0);
     116    if (fExit)
     117        exit(RTEXITCODE_SUCCESS);
    112118}
    113119
     
    173179 * Print out a usage message and exit with success.
    174180 */
    175 void vboxClientUsage(const char *pcszFileName)
     181static void vboxClientUsage(const char *pcszFileName)
    176182{
    177183    RTPrintf("Usage: %s --clipboard|"
     
    198204    RTPrintf("  --seamless         starts the seamless windows service\n");
    199205    RTPrintf("  --vmsvga           starts VMSVGA dynamic resizing for DRM or for X11\n");
     206    RTPrintf("  -f, --foreground   run in the foreground (no daemonizing)\n");
    200207    RTPrintf("  -d, --nodaemon     continues running as a system service\n");
    201208    RTPrintf("  -h, --help         shows this help text\n");
    202209    RTPrintf("  -V, --version      shows version information\n");
    203210    RTPrintf("\n");
    204     exit(0);
     211}
     212
     213/**
     214 * Complains about seeing more than one service specification.
     215 *
     216 * @returns RTEXITCODE_SYNTAX.
     217 */
     218static int vbclSyntaxOnlyOneService(void)
     219{
     220    RTMsgError("More than one service specified! Only one, please.");
     221    return RTEXITCODE_SYNTAX;
    205222}
    206223
     
    211228int main(int argc, char *argv[])
    212229{
    213     bool fDaemonise = true, fRespawn = true;
    214     int rc;
    215     const char *pcszFileName;
    216 
    217230    /* Initialise our runtime before all else. */
    218     rc = RTR3InitExe(argc, &argv, 0);
     231    int rc = RTR3InitExe(argc, &argv, 0);
    219232    if (RT_FAILURE(rc))
    220233        return RTMsgInitFailure(rc);
     234
    221235    /* This should never be called twice in one process - in fact one Display
    222236     * object should probably never be used from multiple threads anyway. */
    223237    if (!XInitThreads())
    224238        VBClFatalError(("Failed to initialize X11 threads\n"));
    225     /* Get our file name for error output. */
    226     pcszFileName = RTPathFilename(argv[0]);
     239
     240    /* Get our file name for usage info and hints. */
     241    const char *pcszFileName = RTPathFilename(argv[0]);
    227242    if (!pcszFileName)
    228243        pcszFileName = "VBoxClient";
     
    230245    /* Parse our option(s) */
    231246    /** @todo Use RTGetOpt() if the arguments become more complex. */
     247    bool fDaemonise = true;
     248    bool fRespawn = true;
    232249    for (int i = 1; i < argc; ++i)
    233250    {
    234         rc = VERR_INVALID_PARAMETER;
    235         if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--nodaemon"))
     251        if (   !strcmp(argv[i], "-f")
     252            || !strcmp(argv[i], "--foreground")
     253            || !strcmp(argv[i], "-d")
     254            || !strcmp(argv[i], "--nodaemon"))
    236255        {
    237256            /* If the user is running in "no daemon" mode anyway, send critical
    238257             * logging to stdout as well. */
     258            /** @todo r=bird: Since the release logger isn't created until the service
     259             *        calls VbglR3InitUser or VbglR3Init or RTLogCreate, this whole
     260             *        exercise is pointless.  Added --init-vbgl-user and --init-vbgl-full
     261             *        for getting some work done. */
    239262            PRTLOGGER pReleaseLog = RTLogRelGetDefaultInstance();
    240263            if (pReleaseLog)
    241264                rc = RTLogDestinations(pReleaseLog, "stdout");
    242265            if (pReleaseLog && RT_FAILURE(rc))
    243                 RTPrintf("%s: failed to redivert error output, rc=%Rrc\n",
    244                          pcszFileName, rc);
     266                return RTMsgErrorExitFailure("failed to redivert error output, rc=%Rrc", rc);
     267
    245268            fDaemonise = false;
     269            if (   !strcmp(argv[i], "-f")
     270                || !strcmp(argv[i], "--foreground"))
     271                fRespawn = false;
    246272        }
    247273        else if (!strcmp(argv[i], "--no-respawn"))
     
    252278        {
    253279            if (g_pService)
    254                 break;
     280                return vbclSyntaxOnlyOneService();
    255281            g_pService = VBClGetClipboardService();
    256282        }
     
    258284        {
    259285            if (g_pService)
    260                 break;
     286                return vbclSyntaxOnlyOneService();
    261287            g_pService = VBClGetDisplayService();
    262288        }
     
    264290        {
    265291            if (g_pService)
    266                 break;
     292                return vbclSyntaxOnlyOneService();
    267293            g_pService = VBClGetSeamlessService();
    268294        }
     
    270296        {
    271297            if (g_pService)
    272                 break;
     298                return vbclSyntaxOnlyOneService();
    273299            g_pService = VBClGetHostVersionService();
    274300        }
     
    277303        {
    278304            if (g_pService)
    279                 break;
     305                return vbclSyntaxOnlyOneService();
    280306            g_pService = VBClGetDragAndDropService();
    281307        }
     
    284310        {
    285311            if (g_pService)
    286                 break;
     312                return vbclSyntaxOnlyOneService();
    287313            g_pService = VBClCheck3DService();
    288314        }
     
    290316        {
    291317            if (g_pService)
    292                 break;
     318                return vbclSyntaxOnlyOneService();
    293319            g_pService = VBClDisplaySVGAService();
     320        }
     321        /* bird: this is just a quick hack to get something out of the LogRel statements in the code. */
     322        else if (!strcmp(argv[i], "--init-vbgl-user"))
     323        {
     324            rc = VbglR3InitUser();
     325            if (RT_FAILURE(rc))
     326                return RTMsgErrorExitFailure("VbglR3InitUser failed: %Rrc", rc);
     327        }
     328        else if (!strcmp(argv[i], "--init-vbgl-full"))
     329        {
     330            rc = VbglR3Init();
     331            if (RT_FAILURE(rc))
     332                return RTMsgErrorExitFailure("VbglR3Init failed: %Rrc", rc);
    294333        }
    295334        else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
     
    305344        else
    306345        {
    307             RTPrintf("%s: unrecognized option `%s'\n", pcszFileName, argv[i]);
    308             RTPrintf("Try `%s --help' for more information\n", pcszFileName);
     346            RTMsgError("unrecognized option `%s'", argv[i]);
     347            RTMsgInfo("Try `%s --help' for more information", pcszFileName);
    309348            return RTEXITCODE_SYNTAX;
    310349        }
    311         rc = VINF_SUCCESS;
    312     }
    313     if (RT_FAILURE(rc) || !g_pService)
    314     {
    315         vboxClientUsage(pcszFileName);
     350    }
     351    if (!g_pService)
     352    {
     353        RTMsgError("No service specified. Quitting because nothing to do!");
    316354        return RTEXITCODE_SYNTAX;
    317355    }
     
    363401        LogRel2(("Initializing service failed: %Rrc\n", rc));
    364402    }
    365     VBClCleanUp();
     403    VBClCleanUp(false /*fExit*/);
    366404    return RTEXITCODE_SUCCESS;
    367405}
Note: See TracChangeset for help on using the changeset viewer.

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