VirtualBox

Changeset 95139 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 30, 2022 5:19:09 PM (3 years ago)
Author:
vboxsync
Message:

FE/VBoxAutostart: Lots of bigger and smaller cleanups, especially regarding mixed up return types, better and more (optionally verbose) logging for the Windows event log, added missing syntax help.

Location:
trunk/src/VBox/Frontends/VBoxAutostart
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart-posix.cpp

    r95105 r95139  
    248248}
    249249
    250 static void displayHeader()
    251 {
    252     RTStrmPrintf(g_pStdErr, VBOX_PRODUCT " Autostart " VBOX_VERSION_STRING "\n"
    253                  "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
    254                  "All rights reserved.\n\n");
    255 }
    256 
    257250/**
    258  * Displays the help.
     251 * Shows the help.
    259252 *
    260253 * @param   pszImage                Name of program name (image).
    261254 */
    262 static void displayHelp(const char *pszImage)
     255static void showHelp(const char *pszImage)
    263256{
    264257    AssertPtrReturnVoid(pszImage);
    265258
    266     displayHeader();
     259    autostartSvcShowHeader();
    267260
    268261    RTStrmPrintf(g_pStdErr,
    269262                 "Usage: %s [-v|--verbose] [-h|-?|--help]\n"
     263                 "           [-V|--version]\n"
    270264                 "           [-F|--logfile=<file>] [-R|--logrotate=<num>]\n"
    271265                 "           [-S|--logsize=<bytes>] [-I|--loginterval=<seconds>]\n"
     
    282276        {
    283277            case 'h':
    284                 pcszDescr = "Print this help message and exit.";
     278                pcszDescr = "Prints this help message and exit.";
    285279                break;
    286280
     
    310304                pcszDescr = "Name of the configuration file for the global overrides.";
    311305                break;
     306
     307            case 'V':
     308                pcszDescr = "Shows the service version.";
     309                break;
     310
    312311            default:
    313312                AssertFailedBreakStmt(pcszDescr = "");
     
    357356        {
    358357            case 'h':
    359                 displayHelp(argv[0]);
    360                 return 0;
     358                showHelp(argv[0]);
     359                return RTEXITCODE_SUCCESS;
    361360
    362361            case 'v':
     
    370369#endif
    371370            case 'V':
    372                 RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
    373                 return 0;
     371                autostartSvcShowVersion(false);
     372                return RTEXITCODE_SUCCESS;
    374373
    375374            case 'F':
     
    412411    if (!fStart && !fStop)
    413412    {
    414         displayHelp(argv[0]);
     413        showHelp(argv[0]);
    415414        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Either --start or --stop must be present");
    416415    }
    417416    else if (fStart && fStop)
    418417    {
    419         displayHelp(argv[0]);
     418        showHelp(argv[0]);
    420419        return RTMsgErrorExit(RTEXITCODE_FAILURE, "--start or --stop are mutually exclusive");
    421420    }
     
    423422    if (!pszConfigFile)
    424423    {
    425         displayHelp(argv[0]);
     424        showHelp(argv[0]);
    426425        return RTMsgErrorExit(RTEXITCODE_FAILURE, "--config <config file> is missing");
    427426    }
    428427
    429428    if (!fQuiet)
    430         displayHeader();
     429        autostartSvcShowHeader();
    431430
    432431    PCFGAST pCfgAst = NULL;
     
    544543        return RTEXITCODE_FAILURE;
    545544
    546     RTEXITCODE rcExit;
    547545    if (fStart)
    548         rcExit = autostartStartMain(pCfgAstUser);
     546        rc = autostartStartMain(pCfgAstUser);
    549547    else
    550548    {
    551549        Assert(fStop);
    552         rcExit = autostartStopMain(pCfgAstUser);
     550        rc = autostartStopMain(pCfgAstUser);
    553551    }
    554552
    555553    autostartConfigAstDestroy(pCfgAst);
    556554    NativeEventQueue::getMainEventQueue()->processEventQueue(0);
    557 
    558555    autostartShutdown();
    559     return rcExit;
     556
     557    return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
    560558}
    561559
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart-win.cpp

    r95103 r95139  
    2020*   Header Files                                                                                                                 *
    2121*********************************************************************************************************************************/
    22 #include <iprt/buildconfig.h>
    2322#include <iprt/dir.h>
    2423#include <iprt/env.h>
    25 #include <iprt/errcore.h>
     24#include <iprt/err.h>
    2625#include <iprt/getopt.h>
    2726#include <iprt/initterm.h>
     
    5150
    5251#include <VBox/log.h>
    53 #include <VBox/version.h>
    5452
    5553#include "VBoxAutostart.h"
     
    261259DECLHIDDEN(void) autostartSvcOsLogStr(const char *pszMsg, AUTOSTARTLOGTYPE enmLogType)
    262260{
    263     /* write it to the release log too */
     261    /* write it to the console + release log too (if configured). */
    264262    LogRel(("%s", pszMsg));
    265263
     264    /** @todo r=andy Only (un)register source once? */
    266265    HANDLE hEventLog = RegisterEventSourceA(NULL /* local computer */, "VBoxAutostartSvc");
    267266    AssertReturnVoid(hEventLog != NULL);
     
    274273    {
    275274        case AUTOSTARTLOGTYPE_INFO:
     275            RTStrmPrintf(g_pStdOut, "%s", pszMsg);
    276276            wType = 0;
    277277            break;
    278278        case AUTOSTARTLOGTYPE_ERROR:
     279            RTStrmPrintf(g_pStdErr, "Error: %s", pszMsg);
    279280            wType = EVENTLOG_ERROR_TYPE;
    280281            break;
    281282        case AUTOSTARTLOGTYPE_WARNING:
     283            RTStrmPrintf(g_pStdOut, "Warning: %s", pszMsg);
    282284            wType = EVENTLOG_WARNING_TYPE;
    283285            break;
    284286        case AUTOSTARTLOGTYPE_VERBOSE:
    285             if (!g_cVerbosity)
    286                 return;
     287            RTStrmPrintf(g_pStdOut, "%s", pszMsg);
    287288            wType = EVENTLOG_INFORMATION_TYPE;
    288289            break;
    289290        default:
    290             AssertMsgFailed(("Invalid log type %d\n", enmLogType));
    291     }
    292 
     291            AssertMsgFailed(("Invalid log type %#x\n", enmLogType));
     292            break;
     293    }
     294
     295    /** @todo r=andy Why ANSI and not Unicode (xxxW)? */
    293296    BOOL fRc = ReportEventA(hEventLog,               /* hEventLog */
    294297                            wType,                   /* wType */
     
    300303                            apsz,                    /* lpStrings */
    301304                            NULL);                   /* lpRawData */
    302     AssertMsg(fRc, ("%u\n", GetLastError())); NOREF(fRc);
     305    AssertMsg(fRc, ("ReportEventA failed with %ld\n", GetLastError())); RT_NOREF(fRc);
    303306    DeregisterEventSource(hEventLog);
    304307}
     
    342345 * @returns Valid service handle on success.
    343346 *          NULL on failure, will display an error message unless it's ignored.
     347 *          Use GetLastError() to find out what the last Windows error was.
    344348 *
    345349 * @param   pszAction           The action which is requesting access to the service.
     
    364368    else
    365369    {
    366         DWORD   err = GetLastError();
    367         bool    fIgnored = false;
     370        DWORD const dwErr    = GetLastError();
     371        bool        fIgnored = false;
    368372        va_list va;
    369373        va_start(va, cIgnoredErrors);
    370374        while (!fIgnored && cIgnoredErrors-- > 0)
    371             fIgnored = (DWORD)va_arg(va, int) == err;
     375            fIgnored = (DWORD)va_arg(va, int) == dwErr;
    372376        va_end(va);
    373377        if (!fIgnored)
    374378        {
    375             switch (err)
     379            switch (dwErr)
    376380            {
    377381                case ERROR_ACCESS_DENIED:
     
    383387                    break;
    384388                default:
    385                     autostartSvcDisplayError("%s - OpenService failure: %d\n", pszAction, err);
     389                    autostartSvcDisplayError("%s - OpenService failure, rc=%Rrc (%#x)\n", RTErrConvertFromWin32(dwErr), dwErr);
    386390                    break;
    387391            }
     
    389393
    390394        CloseServiceHandle(hSCM);
    391         SetLastError(err);
     395        SetLastError(dwErr);
    392396    }
    393397    return hSvc;
     
    472476 * @param   argv    The action argument vector.
    473477 */
    474 static int autostartSvcWinDelete(int argc, char **argv)
     478static RTEXITCODE autostartSvcWinDelete(int argc, char **argv)
    475479{
    476480    /*
     
    508512    int vrc = autostartGetServiceName(pszUser, sServiceName);
    509513    if (RT_FAILURE(vrc))
    510         return autostartSvcDisplayError("delete - DeleteService failed, service name for user %s can not be constructed.\n",
     514        return autostartSvcDisplayError("delete - DeleteService failed, service name for user %s cannot be constructed.\n",
    511515                                        pszUser);
    512516    /*
    513      * Create the service.
     517     * Delete the service.
    514518     */
    515     RTEXITCODE rc = RTEXITCODE_FAILURE;
    516     SC_HANDLE hSvc = autostartSvcWinOpenService(com::Bstr(sServiceName).raw(), "delete", SERVICE_CHANGE_CONFIG, DELETE,
    517                                                 1, ERROR_SERVICE_DOES_NOT_EXIST);
     519    RTEXITCODE rcExit = RTEXITCODE_FAILURE;
     520    SC_HANDLE hSvc = autostartSvcWinOpenService(com::Bstr(sServiceName).raw(), "delete", SERVICE_CHANGE_CONFIG, DELETE, 0);
    518521    if (hSvc)
    519522    {
    520523        if (DeleteService(hSvc))
    521524        {
    522             RTPrintf("Successfully deleted the %s service.\n", sServiceName.c_str());
    523             rc = RTEXITCODE_SUCCESS;
     525            if (g_cVerbosity)
     526                RTPrintf("Successfully deleted the %s service.\n", sServiceName.c_str());
     527            rcExit = RTEXITCODE_SUCCESS;
    524528        }
    525529        else
    526             autostartSvcDisplayError("delete - DeleteService failed, err=%d.\n", GetLastError());
     530        {
     531            DWORD const dwErr = GetLastError();
     532            autostartSvcDisplayError("delete - DeleteService failed, rc=%Rrc (%#x)\n", RTErrConvertFromWin32(dwErr), dwErr);
     533        }
    527534        CloseServiceHandle(hSvc);
    528535    }
    529     else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
    530     {
    531 
    532         if (g_cVerbosity)
    533             RTPrintf("The service %s was not installed, nothing to be done.", sServiceName.c_str());
    534         else
    535             RTPrintf("Successfully deleted the %s service.\n", sServiceName.c_str());
    536         rc = RTEXITCODE_SUCCESS;
    537     }
    538     return rc;
     536    return rcExit;
    539537}
    540538
     
    786784             */
    787785            int rc = RTSemEventMultiSignal(g_hSupSvcWinEvent);
    788             if (RT_FAILURE(rc))
    789                 autostartSvcLogError("SERVICE_CONTROL_STOP: RTSemEventMultiSignal failed, %Rrc\n", rc);
     786            if (RT_FAILURE(rc)) /** @todo r=andy Don't we want to report back an error here to SCM? */
     787                autostartSvcLogErrorRc(rc, "SERVICE_CONTROL_STOP: RTSemEventMultiSignal failed, %Rrc\n", rc);
    790788
    791789            return NO_ERROR;
     
    805803}
    806804
    807 static RTEXITCODE autostartStartVMs(void)
     805static int autostartStartVMs(void)
    808806{
    809807    int rc = autostartSetup();
    810808    if (RT_FAILURE(rc))
    811         return RTEXITCODE_FAILURE;
     809        return rc;
    812810
    813811    const char *pszConfigFile = RTEnvGet("VBOXAUTOSTART_CONFIG");
    814812    if (!pszConfigFile)
    815         return autostartSvcLogError("Starting VMs failed. VBOXAUTOSTART_CONFIG environment variable is not defined.\n");
     813        return autostartSvcLogErrorRc(VERR_ENV_VAR_NOT_FOUND,
     814                                      "Starting VMs failed. VBOXAUTOSTART_CONFIG environment variable is not defined.\n");
    816815    bool fAllow = false;
    817816
     
    819818    rc = autostartParseConfig(pszConfigFile, &pCfgAst);
    820819    if (RT_FAILURE(rc))
    821         return autostartSvcLogError("Starting VMs failed. Failed to parse the config file. Check the access permissions and file structure.\n");
    822 
     820        return autostartSvcLogErrorRc(rc, "Starting VMs failed. Failed to parse the config file. Check the access permissions and file structure.\n");
    823821    PCFGAST pCfgAstPolicy = autostartConfigAstGetByName(pCfgAst, "default_policy");
    824822    /* Check default policy. */
     
    835833        {
    836834            autostartConfigAstDestroy(pCfgAst);
    837             return autostartSvcLogError("'default_policy' must be either 'allow' or 'deny'.\n");
     835            return autostartSvcLogErrorRc(VERR_INVALID_PARAMETER, "'default_policy' must be either 'allow' or 'deny'.\n");
    838836        }
    839837    }
     
    844842    {
    845843        autostartConfigAstDestroy(pCfgAst);
    846         return autostartSvcLogError("Failed to query username of the process (%Rrc).\n", rc);
     844        return autostartSvcLogErrorRc(rc, "Failed to query username of the process (%Rrc).\n", rc);
    847845    }
    848846
     
    877875            {
    878876                autostartConfigAstDestroy(pCfgAst);
    879                 return autostartSvcLogError("'allow' must be either 'true' or 'false'.\n");
     877                return autostartSvcLogErrorRc(VERR_INVALID_PARAMETER, "'allow' must be either 'true' or 'false'.\n");
    880878            }
    881879        }
     
    884882    {
    885883        autostartConfigAstDestroy(pCfgAst);
    886         return autostartSvcLogError("Invalid config, user is not a compound node.\n");
     884        return autostartSvcLogErrorRc(VERR_INVALID_PARAMETER, "Invalid config, user is not a compound node.\n");
    887885    }
    888886
     
    890888    {
    891889        autostartConfigAstDestroy(pCfgAst);
    892         return autostartSvcLogError("User is not allowed to autostart VMs.\n");
    893     }
    894 
    895     RTEXITCODE rcExit = autostartStartMain(pCfgAstUser);
     890        return autostartSvcLogErrorRc(VERR_INVALID_PARAMETER, "User is not allowed to autostart VMs.\n");
     891    }
     892
     893    if (RT_SUCCESS(rc))
     894        rc = autostartStartMain(pCfgAstUser);
     895
    896896    autostartConfigAstDestroy(pCfgAst);
    897     if (rcExit != RTEXITCODE_SUCCESS)
    898         autostartSvcLogError("Starting VMs failed\n");
    899 
    900     return rcExit;
     897
     898    return rc;
    901899}
    902900
     
    953951                    {
    954952                        /* No one signaled us to stop */
    955                         RTEXITCODE ec = autostartStartVMs();
    956                         if (ec == RTEXITCODE_SUCCESS)
    957                         {
    958                             LogFlow(("autostartSvcWinServiceMain: done starting VMs\n"));
    959                             dwErr = NO_ERROR;
    960                         }
    961                         /* No reason to keep started. Shutdown the service*/
     953                        rc = autostartStartVMs();
    962954                    }
    963955                    autostartShutdown();
     
    982974        autostartSvcWinSetServiceStatus(SERVICE_STOPPED, 0, dwErr);
    983975    }
    984     else
    985     {
    986         dwErr = GetLastError();
    987         autostartSvcLogError("RegisterServiceCtrlHandlerEx failed, rc=%Rrc (%#x)\n", RTErrConvertFromWin32(dwErr), dwErr);
    988     }
    989 
    990     LogFlowFuncLeave();
     976    /* else error will be handled by the caller. */
    991977}
    992978
     
    1001987static RTEXITCODE autostartSvcWinRunIt(int argc, char **argv)
    1002988{
    1003     int rc;
     989    int vrc;
    1004990
    1005991    LogFlowFuncEnter();
     
    10311017    {
    10321018        char szLogFile[RTPATH_MAX];
    1033         rc = com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile),
     1019        vrc = com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile),
    10341020                                           /* :fCreateDir */ false);
    1035         if (RT_FAILURE(rc))
    1036         {
    1037             autostartSvcLogError("Failed to get VirtualBox user home directory: %Rrc\n", rc);
     1021        if (RT_FAILURE(vrc))
     1022        {
     1023            autostartSvcLogError("Failed to get VirtualBox user home directory: %Rrc\n", vrc);
    10381024            break;
    10391025        }
     
    10451031        }
    10461032
    1047         rc = RTPathAppend(szLogFile, sizeof(szLogFile), "VBoxAutostart.log");
    1048         if (RT_FAILURE(rc))
    1049         {
    1050             autostartSvcLogError("Failed to construct release log file name: %Rrc\n", rc);
    1051             break;
    1052         }
    1053 
    1054         rc = com::VBoxLogRelCreate(AUTOSTART_SERVICE_NAME,
     1033        vrc = RTPathAppend(szLogFile, sizeof(szLogFile), "VBoxAutostart.log");
     1034        if (RT_FAILURE(vrc))
     1035        {
     1036            autostartSvcLogError( "Failed to construct release log file name: %Rrc\n", vrc);
     1037            break;
     1038        }
     1039
     1040        vrc = com::VBoxLogRelCreate(AUTOSTART_SERVICE_NAME,
    10551041                                   szLogFile,
    10561042                                     RTLOGFLAGS_PREFIX_THREAD
     
    10641050                                   g_uHistoryFileSize,
    10651051                                   NULL);
    1066         if (RT_FAILURE(rc))
    1067             autostartSvcLogError("Failed to create release log file: %Rrc\n", rc);
     1052        if (RT_FAILURE(vrc))
     1053            autostartSvcLogError("Failed to create release log file: %Rrc\n", vrc);
    10681054    } while (0);
    10691055
     
    11121098    {
    11131099        autostartSvcLogError("runit failed, service name is missing");
    1114         return RTEXITCODE_FAILURE;
    1115     }
    1116 
     1100        return RTEXITCODE_SYNTAX;
     1101    }
    11171102
    11181103    autostartSvcLogInfo("Starting service %ls\n", g_bstrServiceName.raw());
     
    11271112        { NULL, NULL}
    11281113    };
     1114
    11291115    if (StartServiceCtrlDispatcherW(&s_aServiceStartTable[0]))
    11301116    {
     
    11371123    {
    11381124        case ERROR_FAILED_SERVICE_CONTROLLER_CONNECT:
    1139             autostartSvcWinServiceMain(0, NULL);//autostartSvcDisplayError("Cannot run a service from the command line. Use the 'start' action to start it the right way.\n");
     1125            autostartSvcLogWarning("Cannot run a service from the command line. Use the 'start' action to start it the right way.\n");
     1126            autostartSvcWinServiceMain(0 /* cArgs */, NULL /* papwszArgs */);
    11401127            break;
    11411128        default:
     
    11471134
    11481135    return RTEXITCODE_FAILURE;
    1149 }
    1150 
    1151 
    1152 static void autostartSvcShowHeader(void)
    1153 {
    1154     RTPrintf(VBOX_PRODUCT " VirtualBox Autostart Service Version " VBOX_VERSION_STRING " - r%s\n"
    1155              "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
    1156              "All rights reserved.\n\n", RTBldCfgRevisionStr());
    11571136}
    11581137
     
    11871166     * Do the printing.
    11881167     */
    1189     if (fBrief)
    1190         RTPrintf("%s\n", VBOX_VERSION_STRING);
    1191     else
    1192         autostartSvcShowHeader();
     1168    autostartSvcShowVersion(fBrief);
     1169
    11931170    return RTEXITCODE_SUCCESS;
    11941171}
     
    12111188             "\n"
    12121189             "Global options:\n"
    1213              "  <help|-?|-h|--help> [...]\n"
    1214              "    Displays this help screen.\n"
    1215              "  <version|-v|--version> [-brief]\n"
    1216              "    Displays the version.\n"
    1217              "\n"
     1190             "  -v\n"
     1191             "    Increases the verbosity. Can be specified multiple times."
     1192             "\n\n"
    12181193             "No command given:\n"
    12191194             "  Runs the service.\n"
     1195             "Options:\n"
    12201196             "  --service <name>\n"
    12211197             "    Specifies the service name to run.\n"
     1198             "\n"
     1199             "Command </help|help|-?|-h|--help> [...]\n"
     1200             "    Displays this help screen.\n"
     1201             "\n"
     1202             "Command </version|version|-V|--version> [-brief]\n"
     1203             "    Displays the version.\n"
    12221204             "\n"
    12231205             "Command </i|install|/RegServer> --user <username> --password-file <...>\n"
     
    12251207             "Options:\n"
    12261208             "  --user <username>\n"
    1227              "    Specifies the user name the service should use for installation.\n"
     1209             "    Specifies the user name the service should be installed for.\n"
    12281210             "  --password-file <path/to/file>\n"
    12291211             "    Specifies the file for user password to use for installation.\n"
    12301212             "\n"
    12311213             "Command </u|uninstall|delete|/UnregServer>\n"
    1232              "  Uninstalls the service.\n",
     1214             "  Uninstalls the service.\n"
     1215             "  --user <username>\n"
     1216             "    Specifies the user name the service should will be deleted for.\n",
    12331217             pszExe);
    12341218    return RTEXITCODE_SUCCESS;
     
    13241308            return autostartSvcWinShowHelp();
    13251309        else if (   !stricmp(argv[iArg], "version")
    1326                  || !stricmp(argv[iArg], "/v")
    1327                  || !stricmp(argv[iArg], "-v")
     1310                 || !stricmp(argv[iArg], "/ver")
     1311                 || !stricmp(argv[iArg], "-V") /* Note: "-v" is used for specifying the verbosity. */
    13281312                 || !stricmp(argv[iArg], "/version")
    13291313                 || !stricmp(argv[iArg], "-version")
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart.h

    r95103 r95139  
    126126
    127127/**
     128 * Prints the service header header (product name, version, ++) to stdout.
     129 */
     130DECLHIDDEN(void) autostartSvcShowHeader(void);
     131
     132/**
     133 * Prints the service version information header to stdout.
     134 *
     135 * @param   fBrief            Whether to show brief information or not.
     136 */
     137DECLHIDDEN(void) autostartSvcShowVersion(bool fBrief);
     138
     139/**
    128140 * Log messages to the system and release log.
    129141 *
     
    181193 * Main routine for the autostart daemon.
    182194 *
    183  * @returns exit status code.
     195 * @returns VBox status code.
    184196 * @param   pCfgAst        Config AST for the startup part of the autostart daemon.
    185197 */
    186 DECLHIDDEN(RTEXITCODE) autostartStartMain(PCFGAST pCfgAst);
     198DECLHIDDEN(int) autostartStartMain(PCFGAST pCfgAst);
    187199
    188200/**
     
    190202 * during system shutdown.
    191203 *
    192  * @returns exit status code.
     204 * @returns VBox status code.
    193205 * @param   pCfgAst        Config AST for the shutdown part of the autostart daemon.
    194206 */
    195 DECLHIDDEN(RTEXITCODE) autostartStopMain(PCFGAST pCfgAst);
    196 
    197 /**
    198  * Logs a verbose message to the appropriate system log.
     207DECLHIDDEN(int) autostartStopMain(PCFGAST pCfgAst);
     208
     209/**
     210 * Logs a verbose message to the appropriate system log and stdout + release log (if configured).
    199211 *
    200212 * @param   cVerbosity  Verbosity level when logging should happen.
     
    205217
    206218/**
    207  * Logs a verbose message to the appropriate system log.
     219 * Logs a verbose message to the appropriate system log and stdout + release log (if configured).
    208220 *
    209221 * @param   cVerbosity  Verbosity level when logging should happen.
     
    214226
    215227/**
    216  * Logs a warning message to the appropriate system log.
     228 * Logs a warning message to the appropriate system log and stdout + release log (if configured).
    217229 *
    218230 * @param   pszFormat   The log string. No trailing newline.
     
    222234
    223235/**
    224  * Logs a warning message to the appropriate system log.
     236 * Logs a warning message to the appropriate system log and stdout + release log (if configured).
    225237 *
    226238 * @param   pszFormat   The log string. No trailing newline.
     
    230242
    231243/**
    232  * Logs a info message to the appropriate system log.
     244 * Logs a info message to the appropriate system log and stdout + release log (if configured).
    233245 *
    234246 * @param   pszFormat   The log string. No trailing newline.
     
    238250
    239251/**
    240  * Logs a info message to the appropriate system log.
     252 * Logs a info message to the appropriate system log and stdout + release log (if configured).
    241253 *
    242254 * @param   pszFormat   The log string. No trailing newline.
     
    246258
    247259/**
     260 * Logs the message to the appropriate system log and stderr + release log (if configured).
     261 *
     262 * In debug builds this will also put it in the debug log.
     263 *
     264 * @returns VBox status code.
     265 * @param   pszFormat   The log string. No trailing newline.
     266 * @param   ...         Format arguments.
     267 */
     268DECLHIDDEN(int) autostartSvcLogErrorV(const char *pszFormat, va_list va);
     269
     270/**
     271 * Logs the message to the appropriate system log and stderr + release log (if configured).
     272 *
     273 * In debug builds this will also put it in the debug log.
     274 *
     275 * @returns VBox status code.
     276 * @param   pszFormat   The log string. No trailing newline.
     277 * @param   ...         Format arguments.
     278 */
     279DECLHIDDEN(int) autostartSvcLogError(const char *pszFormat, ...);
     280
     281/**
    248282 * Logs the message to the appropriate system log.
    249283 *
    250284 * In debug builds this will also put it in the debug log.
    251285 *
    252  * @param   pszFormat   The log string. No trailing newline.
    253  * @param   ...         Format arguments.
    254  *
    255  * @todo    This should later be replaced by the release logger and callback destination(s).
    256  */
    257 DECLHIDDEN(RTEXITCODE) autostartSvcLogErrorV(const char *pszFormat, va_list va);
     286 * @returns VBox status code specified by \a rc.
     287 * @param   pszFormat   The log string. No trailing newline.
     288 * @param   ...         Format arguments.
     289 *
     290 * @note    Convenience function to return directly with the specified \a rc.
     291 */
     292DECLHIDDEN(int) autostartSvcLogErrorRcV(int rc, const char *pszFormat, va_list va);
    258293
    259294/**
     
    262297 * In debug builds this will also put it in the debug log.
    263298 *
    264  * @param   pszFormat   The log string. No trailing newline.
    265  * @param   ...         Format arguments.
    266  *
    267  * @todo    This should later be replaced by the release logger and callback destination(s).
    268  */
    269 DECLHIDDEN(RTEXITCODE) autostartSvcLogError(const char *pszFormat, ...);
     299 * @returns VBox status code specified by \a rc.
     300 * @param   pszFormat   The log string. No trailing newline.
     301 * @param   ...         Format arguments.
     302 *
     303 * @note    Convenience function to return directly with the specified \a rc.
     304 */
     305DECLHIDDEN(int) autostartSvcLogErrorRc(int rc, const char *pszFormat, ...);
    270306
    271307/**
    272308 * Deals with RTGetOpt failure, bitching in the system log.
    273309 *
    274  * @returns 1
     310 * @returns VBox status code specified by \a rc.
    275311 * @param   pszAction       The action name.
    276312 * @param   rc              The RTGetOpt return value.
     
    280316 * @param   pValue          The value returned by RTGetOpt.
    281317 */
    282 DECLHIDDEN(RTEXITCODE) autostartSvcLogGetOptError(const char *pszAction, int rc, int argc, char **argv, int iArg, PCRTGETOPTUNION pValue);
     318DECLHIDDEN(int) autostartSvcLogGetOptError(const char *pszAction, int rc, int argc, char **argv, int iArg, PCRTGETOPTUNION pValue);
    283319
    284320/**
    285321 * Bitch about too many arguments (after RTGetOpt stops) in the system log.
    286322 *
    287  * @returns 1
     323 * @returns VERR_INVALID_PARAMETER
    288324 * @param   pszAction       The action name.
    289325 * @param   argc            The argument count.
     
    291327 * @param   iArg            The argument index.
    292328 */
    293 DECLHIDDEN(RTEXITCODE) autostartSvcLogTooManyArgsError(const char *pszAction, int argc, char **argv, int iArg);
     329DECLHIDDEN(int) autostartSvcLogTooManyArgsError(const char *pszAction, int argc, char **argv, int iArg);
    294330
    295331/**
    296332 * Prints an error message to the screen.
    297333 *
     334 * @returns RTEXITCODE
    298335 * @param   pszFormat   The message format string.
    299336 * @param   va          Format arguments.
     
    304341 * Prints an error message to the screen.
    305342 *
     343 * @returns RTEXITCODE
    306344 * @param   pszFormat   The message format string.
    307345 * @param   ...         Format arguments.
     
    319357DECLHIDDEN(RTEXITCODE) autostartSvcDisplayGetOptError(const char *pszAction, int rc, PCRTGETOPTUNION pValue);
    320358
    321 DECLHIDDEN(int) autostartSetup();
    322 
    323 DECLHIDDEN(void) autostartShutdown();
     359DECLHIDDEN(int) autostartSetup(void);
     360
     361DECLHIDDEN(void) autostartShutdown(void);
    324362
    325363#endif /* !VBOX_INCLUDED_SRC_VBoxAutostart_VBoxAutostart_h */
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartCfg.cpp

    r93115 r95139  
    456456 * Log unexpected token error.
    457457 *
    458  * @returns nothing.
     458 * @returns VBox status code (VERR_INVALID_PARAMETER).
    459459 * @param   pToken          The token which caused the error.
    460460 * @param   pszExpected     String of the token which was expected.
    461461 */
    462 static void autostartConfigTokenizerMsgUnexpectedToken(PCFGTOKEN pToken, const char *pszExpected)
    463 {
    464     autostartSvcLogError("Unexpected token '%s' at %d:%d.%d, expected '%s'",
    465                          autostartConfigTokenToString(pToken),
    466                          pToken->iLine, pToken->cchStart,
    467                          pToken->cchStart + autostartConfigTokenGetLength(pToken) - 1, pszExpected);
     462static int autostartConfigTokenizerMsgUnexpectedToken(PCFGTOKEN pToken, const char *pszExpected)
     463{
     464    return autostartSvcLogErrorRc(VERR_INVALID_PARAMETER, "Unexpected token '%s' at %d:%d.%d, expected '%s'",
     465                                autostartConfigTokenToString(pToken),
     466                                pToken->iLine, pToken->cchStart,
     467                                pToken->cchStart + autostartConfigTokenGetLength(pToken) - 1, pszExpected);
    468468}
    469469
     
    484484    {
    485485        if (pCfgToken->enmType != enmType)
    486         {
    487             autostartConfigTokenizerMsgUnexpectedToken(pCfgToken, autostartConfigTokenTypeToStr(enmType));
    488             rc = VERR_INVALID_PARAMETER;
    489         }
     486            return autostartConfigTokenizerMsgUnexpectedToken(pCfgToken, autostartConfigTokenTypeToStr(enmType));
    490487
    491488        autostartConfigTokenFree(pCfgTokenizer, pCfgToken);
     
    573570    }
    574571    else
    575     {
    576         autostartConfigTokenizerMsgUnexpectedToken(pToken, "non reserved token");
    577         rc = VERR_INVALID_PARAMETER;
    578     }
     572        rc = autostartConfigTokenizerMsgUnexpectedToken(pToken, "non reserved token");
    579573
    580574    return rc;
     
    641635        }
    642636        else if (RT_SUCCESS(rc))
    643         {
    644             autostartConfigTokenizerMsgUnexpectedToken(pToken, "non reserved token");
    645             rc = VERR_INVALID_PARAMETER;
    646         }
     637            rc = autostartConfigTokenizerMsgUnexpectedToken(pToken, "non reserved token");
    647638
    648639        /* Add to the current compound node. */
     
    724715        }
    725716        case CFGASTNODETYPE_LIST:
     717            RT_FALL_THROUGH();
    726718        default:
    727719            AssertMsgFailed(("Invalid AST node type %d\n", pCfgAst->enmType));
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartStart.cpp

    r95103 r95139  
    5454}
    5555
    56 DECLHIDDEN(RTEXITCODE) autostartStartMain(PCFGAST pCfgAst)
     56DECLHIDDEN(int) autostartStartMain(PCFGAST pCfgAst)
    5757{
    58     RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
    5958    int vrc = VINF_SUCCESS;
    6059    std::list<AUTOSTARTVM> listVM;
    6160    uint32_t uStartupDelay = 0;
     61
     62    autostartSvcLogVerbose(1, "Starting machines ...\n");
    6263
    6364    pCfgAst = autostartConfigAstGetByName(pCfgAst, "startup_delay");
     
    6869            vrc = RTStrToUInt32Full(pCfgAst->u.KeyValue.aszValue, 10, &uStartupDelay);
    6970            if (RT_FAILURE(vrc))
    70                 return RTMsgErrorExit(RTEXITCODE_FAILURE, "'startup_delay' must be an unsigned number");
     71                return autostartSvcLogErrorRc(vrc, "'startup_delay' must be an unsigned number");
    7172        }
    7273    }
     
    7980
    8081    if (vrc == VERR_INTERRUPTED)
    81         return RTEXITCODE_SUCCESS;
     82        return VINF_SUCCESS;
    8283
    8384    /*
     
    9697            if (machines[i])
    9798            {
     99                Bstr strName;
     100                CHECK_ERROR_BREAK(machines[i], COMGETTER(Name)(strName.asOutParam()));
     101
    98102                BOOL fAccessible;
    99103                CHECK_ERROR_BREAK(machines[i], COMGETTER(Accessible)(&fAccessible));
    100104                if (!fAccessible)
     105                {
     106                    autostartSvcLogVerbose(1, "Machine '%ls' is not accessible, skipping\n", strName.raw());
    101107                    continue;
     108                }
     109
     110                AUTOSTARTVM autostartVM;
    102111
    103112                BOOL fAutostart;
     
    105114                if (fAutostart)
    106115                {
    107                     AUTOSTARTVM autostartVM;
    108 
    109116                    CHECK_ERROR_BREAK(machines[i], COMGETTER(Id)(autostartVM.strId.asOutParam()));
    110117                    CHECK_ERROR_BREAK(machines[i], COMGETTER(AutostartDelay)(&autostartVM.uStartupDelay));
     
    112119                    listVM.push_back(autostartVM);
    113120                }
     121
     122                autostartSvcLogVerbose(1, "Machine '%ls': Autostart is %s (startup delay is %RU32 seconds)\n",
     123                                       strName.raw(), fAutostart ? "enabled" : "disabled",
     124                                       fAutostart ? autostartVM.uStartupDelay : 0);
    114125            }
    115126        }
     
    120131         * just to add this log, hence a bit of duplicate logic here.
    121132         */
    122         if (SUCCEEDED(rc) && listVM.empty())
    123             LogRel(("No VMs configured for autostart\n"));
     133        if (SUCCEEDED(rc))
     134        {
     135            if (machines.size() == 0)
     136                autostartSvcLogWarning("No virtual machines found.\n"
     137                                       "This either could be a configuration problem (access rights), "
     138                                       "or there are no VMs configured yet.");
     139            else if (listVM.empty())
     140                autostartSvcLogWarning("No virtual machines configured for autostart.\n"
     141                                       "Please consult the manual about how to enable auto starting VMs.\n");
     142        }
     143        else
     144            autostartSvcLogError("Enumerating virtual machines failed with %Rhrc\n", rc);
    124145
    125146        if (   SUCCEEDED(rc)
    126147            && !listVM.empty())
    127148        {
    128             ULONG uDelayCurr = 0;
     149            ULONG uDelayCur = 0;
    129150
    130151            /* Sort by startup delay and apply base override. */
     
    137158                ComPtr<IProgress> progress;
    138159
    139                 if ((*it).uStartupDelay > uDelayCurr)
    140                 {
    141                     autostartSvcLogVerbose(1, "Delaying start of the next VMs for %ul seconds ...\n",
    142                                            (*it).uStartupDelay - uDelayCurr);
    143                     RTThreadSleep(((*it).uStartupDelay - uDelayCurr) * 1000);
    144                     uDelayCurr = (*it).uStartupDelay;
    145                 }
    146 
    147                 CHECK_ERROR_BREAK(g_pVirtualBox, FindMachine((*it).strId.raw(),
    148                                                              machine.asOutParam()));
     160                CHECK_ERROR_BREAK(g_pVirtualBox, FindMachine((*it).strId.raw(), machine.asOutParam()));
     161
     162                Bstr strName;
     163                CHECK_ERROR_BREAK(machine, COMGETTER(Name)(strName.asOutParam()));
     164
     165                if ((*it).uStartupDelay > uDelayCur)
     166                {
     167                    autostartSvcLogVerbose(1, "Waiting for %ul seconds before starting machine '%s' ...\n",
     168                                           (*it).uStartupDelay - uDelayCur, strName.raw());
     169                    RTThreadSleep(((*it).uStartupDelay - uDelayCur) * 1000);
     170                    uDelayCur = (*it).uStartupDelay;
     171                }
    149172
    150173                CHECK_ERROR_BREAK(machine, LaunchVMProcess(g_pSession, Bstr("headless").raw(),
     
    152175                if (SUCCEEDED(rc) && !progress.isNull())
    153176                {
    154                     autostartSvcLogVerbose(1, "Waiting for VM '%ls' to power on...\n", (*it).strId.raw());
     177                    autostartSvcLogVerbose(1, "Waiting for machine '%ls' to power on ...\n", strName.raw());
    155178                    CHECK_ERROR(progress, WaitForCompletion(-1));
    156179                    if (SUCCEEDED(rc))
     
    172195                                }
    173196                                else
    174                                     autostartSvcLogVerbose(1, "VM '%ls' has been successfully started.\n", (*it).strId.raw());
     197                                    autostartSvcLogVerbose(1, "Machine '%ls' has been successfully started.\n", strName.raw());
    175198                            }
    176199                        }
     
    185208    }
    186209
    187     return rcExit;
     210    return vrc;
    188211}
    189212
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartStop.cpp

    r93115 r95139  
    1616 */
    1717
     18#include <iprt/assert.h>
     19#include <iprt/log.h>
     20#include <iprt/message.h>
     21#include <iprt/stream.h>
     22#include <iprt/thread.h>
     23#include <iprt/time.h>
     24
    1825#include <VBox/com/com.h>
    1926#include <VBox/com/string.h>
     
    2229#include <VBox/com/ErrorInfo.h>
    2330#include <VBox/com/errorprint.h>
    24 
    25 #include <iprt/thread.h>
    26 #include <iprt/stream.h>
    27 #include <iprt/log.h>
    28 #include <iprt/assert.h>
    29 #include <iprt/message.h>
    3031
    3132#include <list>
     
    103104}
    104105
    105 DECLHIDDEN(RTEXITCODE) autostartStopMain(PCFGAST pCfgAst)
     106DECLHIDDEN(int) autostartStopMain(PCFGAST pCfgAst)
    106107{
    107108    RT_NOREF(pCfgAst);
    108     RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
    109109    std::list<AUTOSTOPVM> listVM;
     110
     111    autostartSvcLogVerbose(1, "Stopping machines ...\n");
    110112
    111113    /*
     
    125127            if (machines[i])
    126128            {
     129                Bstr strName;
     130                CHECK_ERROR_BREAK(machines[i], COMGETTER(Name)(strName.asOutParam()));
     131
    127132                BOOL fAccessible;
    128133                CHECK_ERROR_BREAK(machines[i], COMGETTER(Accessible)(&fAccessible));
    129134                if (!fAccessible)
     135                {
     136                    autostartSvcLogVerbose(1, "Machine '%ls' is not accessible, skipping\n", strName.raw());
    130137                    continue;
     138                }
     139
     140                AUTOSTOPVM autostopVM;
    131141
    132142                AutostopType_T enmAutostopType;
     
    134144                if (enmAutostopType != AutostopType_Disabled)
    135145                {
    136                     AUTOSTOPVM autostopVM;
    137 
    138146                    CHECK_ERROR_BREAK(machines[i], COMGETTER(Id)(autostopVM.strId.asOutParam()));
    139147                    autostopVM.enmAutostopType = enmAutostopType;
     
    141149                    listVM.push_back(autostopVM);
    142150                }
     151
     152                autostartSvcLogVerbose(1, "Machine '%ls': Autostop type is %#x\n",
     153                                       strName.raw(), autostopVM.enmAutostopType);
    143154            }
    144155        }
     
    155166                CHECK_ERROR_BREAK(g_pVirtualBox, FindMachine((*it).strId.raw(),
    156167                                                             machine.asOutParam()));
     168
     169                Bstr strName;
     170                CHECK_ERROR_BREAK(machine, COMGETTER(Name)(strName.asOutParam()));
    157171
    158172                CHECK_ERROR_BREAK(machine, COMGETTER(State)(&enmMachineState));
     
    191205
    192206                            rc = showProgress(progress);
    193                             CHECK_PROGRESS_ERROR(progress, ("Failed to power off machine"));
     207                            CHECK_PROGRESS_ERROR(progress, ("Failed to powering off machine '%ls'", strName.raw()));
     208                            if (FAILED(rc))
     209                                autostartSvcLogError("Powering off machine '%ls' failed with %Rhrc\n", strName.raw(), rc);
    194210                            break;
    195211                        }
     
    198214                            BOOL fGuestEnteredACPI = false;
    199215                            CHECK_ERROR_BREAK(console, GetGuestEnteredACPIMode(&fGuestEnteredACPI));
    200                             if (fGuestEnteredACPI && enmMachineState == MachineState_Running)
     216                            if (   fGuestEnteredACPI
     217                                && enmMachineState == MachineState_Running)
    201218                            {
    202219                                CHECK_ERROR_BREAK(console, PowerButton());
    203220
    204                                 autostartSvcLogInfo("Waiting for VM \"%ls\" to power off...\n", (*it).strId.raw());
    205 
    206                                 do
     221                                autostartSvcLogVerbose(1, "Waiting for machine '%ls' to power off...\n", strName.raw());
     222
     223                                uint64_t     const tsStartMs = RTTimeMilliTS();
     224                                RTMSINTERVAL const msTimeout = RT_MS_5MIN; /* Should be enough time, shouldn't it? */
     225
     226                                while (RTTimeMilliTS() - tsStartMs <= msTimeout)
    207227                                {
    208                                     RTThreadSleep(1000);
    209228                                    CHECK_ERROR_BREAK(machine, COMGETTER(State)(&enmMachineState));
    210                                 } while (enmMachineState == MachineState_Running);
     229                                    if (enmMachineState != MachineState_Running)
     230                                        break;
     231                                    RTThreadSleep(RT_MS_1SEC);
     232                                }
     233
     234                                if (RTTimeMilliTS() - tsStartMs > msTimeout)
     235                                    autostartSvcLogWarning("Machine '%ls' did not power off via ACPI within time\n", strName.raw());
    211236                            }
    212237                            else
    213238                            {
    214239                                /* Use save state instead and log this to the console. */
    215                                 autostartSvcLogWarning("The guest of VM \"%ls\" does not support ACPI shutdown or is currently paused, saving state...\n",
    216                                                        (*it).strId.raw());
     240                                autostartSvcLogWarning("The guest of machine '%ls' does not support ACPI shutdown or is currently paused, saving state...\n",
     241                                                       strName.raw());
    217242                                rc = autostartSaveVMState(console);
    218243                            }
     
    220245                        }
    221246                        default:
    222                             autostartSvcLogWarning("Unknown autostop type for VM \"%ls\"\n", (*it).strId.raw());
     247                            autostartSvcLogWarning("Unknown autostop type for machine '%ls', skipping\n", strName.raw());
    223248                    }
    224249                    g_pSession->UnlockMachine();
     
    228253    }
    229254
    230     return rcExit;
     255    return VINF_SUCCESS; /** @todo r=andy Report back the overall status here. */
    231256}
    232257
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartUtils.cpp

    r95103 r95139  
    2525
    2626#include <VBox/err.h>
    27 
     27#include <VBox/version.h>
     28
     29#include <iprt/buildconfig.h>
    2830#include <iprt/message.h>
    2931#include <iprt/thread.h>
     
    9496}
    9597
    96 DECLHIDDEN(RTEXITCODE) autostartSvcLogErrorV(const char *pszFormat, va_list va)
    97 {
    98     if (*pszFormat)
    99     {
    100         char *pszMsg = NULL;
    101         if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
    102         {
    103             autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_ERROR);
    104             RTStrFree(pszMsg);
    105         }
    106         else
    107             autostartSvcOsLogStr(pszFormat, AUTOSTARTLOGTYPE_ERROR);
    108     }
    109     return RTEXITCODE_FAILURE;
    110 }
    111 
    112 DECLHIDDEN(RTEXITCODE) autostartSvcLogError(const char *pszFormat, ...)
    113 {
    114     va_list va;
    115     va_start(va, pszFormat);
    116     autostartSvcLogErrorV(pszFormat, va);
    117     va_end(va);
    118     return RTEXITCODE_FAILURE;
     98DECLHIDDEN(void) autostartSvcShowHeader(void)
     99{
     100    RTPrintf(VBOX_PRODUCT " VirtualBox Autostart Service Version " VBOX_VERSION_STRING " - r%s\n"
     101             "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
     102             "All rights reserved.\n\n", RTBldCfgRevisionStr());
     103}
     104
     105DECLHIDDEN(void) autostartSvcShowVersion(bool fBrief)
     106{
     107    if (fBrief)
     108        RTPrintf("%s\n", VBOX_VERSION_STRING);
     109    else
     110        autostartSvcShowHeader();
     111}
     112
     113DECLHIDDEN(int) autostartSvcLogErrorV(const char *pszFormat, va_list va)
     114{
     115    AssertPtrReturn(pszFormat, VERR_INVALID_POINTER);
     116
     117    char *pszMsg = NULL;
     118    if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
     119    {
     120        autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_ERROR);
     121        RTStrFree(pszMsg);
     122        return VINF_SUCCESS;
     123    }
     124
     125    return VERR_BUFFER_OVERFLOW;
     126}
     127
     128DECLHIDDEN(int) autostartSvcLogError(const char *pszFormat, ...)
     129{
     130    AssertPtrReturn(pszFormat, VERR_INVALID_POINTER);
     131
     132    va_list va;
     133    va_start(va, pszFormat);
     134    int rc = autostartSvcLogErrorV(pszFormat, va);
     135    va_end(va);
     136
     137    return rc;
     138}
     139
     140DECLHIDDEN(int) autostartSvcLogErrorRcV(int rc, const char *pszFormat, va_list va)
     141{
     142    AssertPtrReturn(pszFormat, VERR_INVALID_POINTER);
     143
     144    int rc2 = autostartSvcLogErrorV(pszFormat, va);
     145    if (RT_SUCCESS(rc2))
     146        return rc; /* Return handed-in rc. */
     147    return rc2;
     148}
     149
     150DECLHIDDEN(int) autostartSvcLogErrorRc(int rc, const char *pszFormat, ...)
     151{
     152    AssertPtrReturn(pszFormat, VERR_INVALID_POINTER);
     153
     154    va_list va;
     155    va_start(va, pszFormat);
     156    int rc2 = autostartSvcLogErrorRcV(rc, pszFormat, va);
     157    va_end(va);
     158    return rc2;
    119159}
    120160
     
    129169    if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
    130170    {
    131         RTPrintf("%s", pszMsg);
    132171        autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_VERBOSE);
    133172        RTStrFree(pszMsg);
     
    178217    if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
    179218    {
    180         RTPrintf("%s", pszMsg);
    181219        autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_INFO);
    182220        RTStrFree(pszMsg);
     
    184222}
    185223
    186 DECLHIDDEN(RTEXITCODE) autostartSvcLogGetOptError(const char *pszAction, int rc, int argc, char **argv, int iArg, PCRTGETOPTUNION pValue)
    187 {
    188     NOREF(pValue);
    189     autostartSvcLogError("%s - RTGetOpt failure, %Rrc (%d): %s",
    190                    pszAction, rc, rc, iArg < argc ? argv[iArg] : "<null>");
    191     return RTEXITCODE_FAILURE;
    192 }
    193 
    194 DECLHIDDEN(RTEXITCODE) autostartSvcLogTooManyArgsError(const char *pszAction, int argc, char **argv, int iArg)
    195 {
    196     Assert(iArg < argc);
     224DECLHIDDEN(int) autostartSvcLogGetOptError(const char *pszAction, int rc, int argc, char **argv, int iArg, PCRTGETOPTUNION pValue)
     225{
     226    RT_NOREF(pValue);
     227    autostartSvcLogError("%s - RTGetOpt failure, %Rrc (%d): %s", pszAction, rc, rc, iArg < argc ? argv[iArg] : "<null>");
     228    return RTEXITCODE_SYNTAX;
     229}
     230
     231DECLHIDDEN(int) autostartSvcLogTooManyArgsError(const char *pszAction, int argc, char **argv, int iArg)
     232{
     233    AssertReturn(iArg < argc, RTEXITCODE_FAILURE);
    197234    autostartSvcLogError("%s - Too many arguments: %s", pszAction, argv[iArg]);
    198235    for ( ; iArg < argc; iArg++)
    199236        LogRel(("arg#%i: %s\n", iArg, argv[iArg]));
    200     return RTEXITCODE_FAILURE;
     237    return VERR_INVALID_PARAMETER;
    201238}
    202239
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