VirtualBox

Changeset 83974 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Apr 24, 2020 4:05:50 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137541
Message:

VBoxService: Don't fail because no VBoxGuest till after parsing arguments, because how can one otherwise use --help, --register, --unregister and --version. Fixed usage (messed up in r61742).

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService-win.cpp

    r82968 r83974  
    356356                if (hService)
    357357                {
    358                     if (ChangeServiceConfig (hService,
    359                                              SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
    360                                              SERVICE_DEMAND_START,
    361                                              SERVICE_ERROR_NORMAL,
    362                                              imagePath,
    363                                              NULL,
    364                                              NULL,
    365                                              NULL,
    366                                              NULL,
    367                                              NULL,
    368                                              VBOXSERVICE_FRIENDLY_NAME))
     358                    if (ChangeServiceConfig(hService,
     359                                            SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
     360                                            SERVICE_DEMAND_START,
     361                                            SERVICE_ERROR_NORMAL,
     362                                            imagePath,
     363                                            NULL,
     364                                            NULL,
     365                                            NULL,
     366                                            NULL,
     367                                            NULL,
     368                                            VBOXSERVICE_FRIENDLY_NAME))
    369369                        VGSvcVerbose(1, "The service config has been successfully updated.\n");
    370370                    else
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r83409 r83974  
    378378static int vgsvcUsage(void)
    379379{
    380     RTPrintf("Usage:\n"
    381              " %-12s [-f|--foreground] [-v|--verbose] [-l|--logfile <file>]\n"
    382              "              [-p|--pidfile <file>] [-i|--interval <seconds>]\n"
    383              "              [--disable-<service>] [--enable-<service>]\n"
    384              "              [--only-<service>] [-h|-?|--help]\n", g_pszProgName);
    385 #ifdef RT_OS_WINDOWS
    386     RTPrintf("              [-r|--register] [-u|--unregister]\n");
     380    RTPrintf("Usage: %s [-f|--foreground] [-v|--verbose] [-l|--logfile <file>]\n"
     381             "           [-p|--pidfile <file>] [-i|--interval <seconds>]\n"
     382             "           [--disable-<service>] [--enable-<service>]\n"
     383             "           [--only-<service>] [-h|-?|--help]\n", g_pszProgName);
     384#ifdef RT_OS_WINDOWS
     385    RTPrintf("           [-r|--register] [-u|--unregister]\n");
    387386#endif
    388387    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
     
    878877
    879878
     879/**
     880 * Report VbglR3InitUser / VbglR3Init failure.
     881 *
     882 * @returns RTEXITCODE_FAILURE
     883 * @param   rcVbgl      The failing status code.
     884 */
     885static RTEXITCODE vbglInitFailure(int rcVbgl)
     886{
     887    if (rcVbgl == VERR_ACCESS_DENIED)
     888        return RTMsgErrorExit(RTEXITCODE_FAILURE,
     889                              "Insufficient privileges to start %s! Please start with Administrator/root privileges!\n",
     890                              g_pszProgName);
     891    return RTMsgErrorExit(RTEXITCODE_FAILURE, "VbglR3Init failed with rc=%Rrc\n", rcVbgl);
     892}
     893
     894
    880895int main(int argc, char **argv)
    881896{
     
    920935
    921936    /*
    922      * Connect to the kernel part before daemonizing so we can fail and
    923      * complain if there is some kind of problem.  We need to initialize the
    924      * guest lib *before* we do the pre-init just in case one of services needs
    925      * do to some initial stuff with it.
    926      */
    927     if (fUserSession)
    928         rc = VbglR3InitUser();
    929     else
    930         rc = VbglR3Init();
    931     if (RT_FAILURE(rc))
    932     {
    933         if (rc == VERR_ACCESS_DENIED)
    934             return RTMsgErrorExit(RTEXITCODE_FAILURE, "Insufficient privileges to start %s! Please start with Administrator/root privileges!\n",
    935                                   g_pszProgName);
    936         return RTMsgErrorExit(RTEXITCODE_FAILURE, "VbglR3Init failed with rc=%Rrc\n", rc);
    937     }
     937     * Connect to the kernel part before daemonizing and *before* we do the sub-service
     938     * pre-init just in case one of services needs do to some initial stuff with it.
     939     *
     940     * However, we do not fail till after we've parsed arguments, because that will
     941     * prevent useful stuff like --help, --register, --unregister and --version from
     942     * working when the driver hasn't been installed/loaded yet.
     943     */
     944    int const rcVbgl = fUserSession ? VbglR3InitUser() : VbglR3Init();
    938945
    939946#ifdef RT_OS_WINDOWS
     
    944951    if (   argc == 2
    945952        && !RTStrICmp(argv[1], "pagefusion"))
    946         return VGSvcPageSharingWorkerChild();
     953    {
     954        if (RT_SUCCESS(rcVbgl))
     955            return VGSvcPageSharingWorkerChild();
     956        return vbglInitFailure(rcVbgl);
     957    }
    947958#endif
    948959
     
    953964     */
    954965    if (fUserSession)
    955         return VGSvcGstCtrlSessionSpawnInit(argc, argv);
     966    {
     967        if (RT_SUCCESS(rcVbgl))
     968            return VGSvcGstCtrlSessionSpawnInit(argc, argv);
     969        return vbglInitFailure(rcVbgl);
     970    }
    956971#endif
    957972
     
    10521067            {
    10531068                case 'i':
    1054                     rc = VGSvcArgUInt32(argc, argv, psz + 1, &i,
    1055                                               &g_DefaultInterval, 1, (UINT32_MAX / 1000) - 1);
     1069                    rc = VGSvcArgUInt32(argc, argv, psz + 1, &i, &g_DefaultInterval, 1, (UINT32_MAX / 1000) - 1);
    10561070                    if (rc)
    10571071                        return rc;
     
    10851099                case 'l':
    10861100                {
    1087                     rc = vgsvcArgString(argc, argv, psz + 1, &i,
    1088                                         g_szLogFile, sizeof(g_szLogFile));
     1101                    rc = vgsvcArgString(argc, argv, psz + 1, &i, g_szLogFile, sizeof(g_szLogFile));
    10891102                    if (rc)
    10901103                        return rc;
     
    10951108                case 'p':
    10961109                {
    1097                     rc = vgsvcArgString(argc, argv, psz + 1, &i,
    1098                                         g_szPidFile, sizeof(g_szPidFile));
     1110                    rc = vgsvcArgString(argc, argv, psz + 1, &i, g_szPidFile, sizeof(g_szPidFile));
    10991111                    if (rc)
    11001112                        return rc;
     
    11261138        } while (psz && *++psz);
    11271139    }
     1140
     1141    /* Now we can report the VBGL failure. */
     1142    if (RT_FAILURE(rcVbgl))
     1143        return vbglInitFailure(rcVbgl);
    11281144
    11291145    /* Check that at least one service is enabled. */
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp

    r83405 r83974  
    564564    /* pszUsage. */
    565565#ifdef DEBUG
    566     "              [--control-dump-stderr] [--control-dump-stdout]\n"
     566    "           [--control-dump-stderr] [--control-dump-stdout]\n"
    567567#endif
    568     "              [--control-interval <ms>]"
     568    "           [--control-interval <ms>]"
    569569    ,
    570570    /* pszOptions. */
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp

    r82968 r83974  
    769769    "Time synchronization",
    770770    /* pszUsage. */
    771     "              [--timesync-interval <ms>] [--timesync-min-adjust <ms>]\n"
    772     "              [--timesync-latency-factor <x>] [--timesync-max-latency <ms>]\n"
    773     "              [--timesync-set-threshold <ms>]\n"
    774     "              [--timesync-set-start|--timesync-no-set-start]\n"
    775     "              [--timesync-set-on-restore|--timesync-no-set-on-restore]\n"
    776     "              [--timesync-verbosity <level>]"
     771    "           [--timesync-interval <ms>] [--timesync-min-adjust <ms>]\n"
     772    "           [--timesync-latency-factor <x>] [--timesync-max-latency <ms>]\n"
     773    "           [--timesync-set-threshold <ms>]\n"
     774    "           [--timesync-set-start|--timesync-no-set-start]\n"
     775    "           [--timesync-set-on-restore|--timesync-no-set-on-restore]\n"
     776    "           [--timesync-verbosity <level>]"
    777777    ,
    778778    /* pszOptions. */
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r83958 r83974  
    16731673    "Virtual Machine Information",
    16741674    /* pszUsage. */
    1675     "              [--vminfo-interval <ms>] [--vminfo-user-idle-threshold <ms>]"
     1675    "           [--vminfo-interval <ms>] [--vminfo-user-idle-threshold <ms>]"
    16761676    ,
    16771677    /* pszOptions. */
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