VirtualBox

Changeset 6464 in vbox


Ignore:
Timestamp:
Jan 23, 2008 3:59:06 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27457
Message:

Simplified consoleInitReleaseLog a bit and fixed a little bug in the error handling.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r6446 r6464  
    11571157// IConsole methods
    11581158/////////////////////////////////////////////////////////////////////////////
    1159 
    1160 /*
    1161  * Initialize the release logging facility. In case something
    1162  * goes wrong, there will be no release logging. Maybe in the future
    1163  * we can add some logic to use different file names in this case.
    1164  * Note that the logic must be in sync with Machine::DeleteSettings().
    1165  */
    1166 static HRESULT consoleInitReleaseLog(const ComPtr <IMachine> machine,
    1167                                      char szError[RTPATH_MAX + 128], int *pRc)
    1168 {
    1169     HRESULT hrc = S_OK;
    1170     int vrc = VINF_SUCCESS;
    1171 
    1172     Bstr logFolder;
    1173     hrc = machine->COMGETTER(LogFolder) (logFolder.asOutParam());
    1174     CheckComRCReturnRC (hrc);
    1175 
    1176     Utf8Str logDir = logFolder;
    1177 
    1178     /* make sure the Logs folder exists */
    1179     Assert (!logDir.isEmpty());
    1180     if (!RTDirExists (logDir))
    1181         RTDirCreateFullPath (logDir, 0777);
    1182 
    1183     Utf8Str logFile = Utf8StrFmt ("%s%cVBox.log",
    1184                                   logDir.raw(), RTPATH_DELIMITER);
    1185     Utf8Str pngFile = Utf8StrFmt ("%s%cVBox.png",
    1186                                   logDir.raw(), RTPATH_DELIMITER);
    1187 
    1188     /*
    1189      * Age the old log files
    1190      * Rename .(n-1) to .(n), .(n-2) to .(n-1), ..., and the last log file to .1
    1191      * Overwrite target files in case they exist.
    1192      */
    1193     ComPtr<IVirtualBox> virtualBox;
    1194     machine->COMGETTER(Parent)(virtualBox.asOutParam());
    1195     ComPtr <ISystemProperties> systemProperties;
    1196     virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
    1197     ULONG uLogHistoryCount = 3;
    1198     systemProperties->COMGETTER(LogHistoryCount)(&uLogHistoryCount);
    1199     if (uLogHistoryCount)
    1200     {
    1201         for (int i = uLogHistoryCount-1; i >= 0; i--)
    1202         {
    1203             Utf8Str *files[] = { &logFile, &pngFile };
    1204             Utf8Str oldName, newName;
    1205 
    1206             for (unsigned int j = 0; j < ELEMENTS (files); ++ j)
    1207             {
    1208                 if (i > 0)
    1209                     oldName = Utf8StrFmt ("%s.%d", files [j]->raw(), i);
    1210                 else
    1211                     oldName = *files [j];
    1212                 newName = Utf8StrFmt ("%s.%d", files [j]->raw(), i + 1);
    1213                 /* If the old file doesn't exist, delete the new file (if it
    1214                  * exists) to provide correct rotation even if the sequence is
    1215                  * broken */
    1216                 if (RTFileRename (oldName, newName, RTFILEMOVE_FLAGS_REPLACE) ==
    1217                         VERR_FILE_NOT_FOUND)
    1218                     RTFileDelete (newName);
    1219             }
    1220         }
    1221     }
    1222 
    1223     PRTLOGGER loggerRelease;
    1224     static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
    1225     RTUINT fFlags = RTLOGFLAGS_PREFIX_TIME_PROG;
    1226 #if defined (RT_OS_WINDOWS) || defined (RT_OS_OS2)
    1227     fFlags |= RTLOGFLAGS_USECRLF;
    1228 #endif
    1229     vrc = RTLogCreateEx(&loggerRelease, fFlags, "all",
    1230                         "VBOX_RELEASE_LOG", ELEMENTS(s_apszGroups), s_apszGroups,
    1231                         RTLOGDEST_FILE, szError, sizeof(szError), logFile.raw());
    1232     if (VBOX_SUCCESS(vrc))
    1233     {
    1234         /* some introductory information */
    1235         RTTIMESPEC timeSpec;
    1236         char nowUct[64];
    1237         RTTimeSpecToString(RTTimeNow(&timeSpec), nowUct, sizeof(nowUct));
    1238         RTLogRelLogger(loggerRelease, 0, ~0U,
    1239                        "VirtualBox %s r%d %s (%s %s) release log\n"
    1240                        "Log opened %s\n",
    1241                        VBOX_VERSION_STRING, VBoxSVNRev (), VBOX_BUILD_TARGET,
    1242                        __DATE__, __TIME__, nowUct);
    1243 
    1244         /* register this logger as the release logger */
    1245         RTLogRelSetDefaultInstance(loggerRelease);
    1246     }
    1247     *pRc = vrc;
    1248     return RT_SUCCESS(vrc) ? hrc : E_FAIL;
    1249 }
    12501159
    12511160STDMETHODIMP Console::PowerUp (IProgress **aProgress)
     
    14591368        task->mSavedStateFile = savedStateFile;
    14601369
    1461     int vrc;
    1462     char szError[RTPATH_MAX + 128] = "";
    1463     HRESULT hrc = consoleInitReleaseLog(mMachine, szError, &vrc);
    1464     ComAssertMsgRCRet (SUCCEEDED (hrc),
    1465                        ("Failed to open release log (%s, %Vrc)", szError, vrc),
    1466                        hrc);
    1467     vrc = RTThreadCreate (NULL, Console::powerUpThread, (void *) task.get(),
    1468                           0, RTTHREADTYPE_MAIN_WORKER, 0, "VMPowerUp");
     1370    HRESULT hrc = consoleInitReleaseLog (mMachine);
     1371    if (FAILED (hrc))
     1372        return hrc;
     1373
     1374    int vrc = RTThreadCreate (NULL, Console::powerUpThread, (void *) task.get(),
     1375                              0, RTTHREADTYPE_MAIN_WORKER, 0, "VMPowerUp");
    14691376
    14701377    ComAssertMsgRCRet (vrc, ("Could not create VMPowerUp thread (%Vrc)\n", vrc),
     
    38373744}
    38383745
    3839 // private mehtods
     3746// private methods
    38403747////////////////////////////////////////////////////////////////////////////////
    38413748
     
    39163823    }
    39173824}
     3825
     3826/**
     3827 * Initialize the release logging facility. In case something
     3828 * goes wrong, there will be no release logging. Maybe in the future
     3829 * we can add some logic to use different file names in this case.
     3830 * Note that the logic must be in sync with Machine::DeleteSettings().
     3831 */
     3832HRESULT Console::consoleInitReleaseLog (const ComPtr <IMachine> aMachine)
     3833{
     3834    HRESULT hrc = S_OK;
     3835
     3836    Bstr logFolder;
     3837    hrc = aMachine->COMGETTER(LogFolder) (logFolder.asOutParam());
     3838    CheckComRCReturnRC (hrc);
     3839
     3840    Utf8Str logDir = logFolder;
     3841
     3842    /* make sure the Logs folder exists */
     3843    Assert (!logDir.isEmpty());
     3844    if (!RTDirExists (logDir))
     3845        RTDirCreateFullPath (logDir, 0777);
     3846
     3847    Utf8Str logFile = Utf8StrFmt ("%s%cVBox.log",
     3848                                  logDir.raw(), RTPATH_DELIMITER);
     3849    Utf8Str pngFile = Utf8StrFmt ("%s%cVBox.png",
     3850                                  logDir.raw(), RTPATH_DELIMITER);
     3851
     3852    /*
     3853     * Age the old log files
     3854     * Rename .(n-1) to .(n), .(n-2) to .(n-1), ..., and the last log file to .1
     3855     * Overwrite target files in case they exist.
     3856     */
     3857    ComPtr<IVirtualBox> virtualBox;
     3858    aMachine->COMGETTER(Parent)(virtualBox.asOutParam());
     3859    ComPtr <ISystemProperties> systemProperties;
     3860    virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
     3861    ULONG uLogHistoryCount = 3;
     3862    systemProperties->COMGETTER(LogHistoryCount)(&uLogHistoryCount);
     3863    if (uLogHistoryCount)
     3864    {
     3865        for (int i = uLogHistoryCount-1; i >= 0; i--)
     3866        {
     3867            Utf8Str *files[] = { &logFile, &pngFile };
     3868            Utf8Str oldName, newName;
     3869
     3870            for (unsigned int j = 0; j < ELEMENTS (files); ++ j)
     3871            {
     3872                if (i > 0)
     3873                    oldName = Utf8StrFmt ("%s.%d", files [j]->raw(), i);
     3874                else
     3875                    oldName = *files [j];
     3876                newName = Utf8StrFmt ("%s.%d", files [j]->raw(), i + 1);
     3877                /* If the old file doesn't exist, delete the new file (if it
     3878                 * exists) to provide correct rotation even if the sequence is
     3879                 * broken */
     3880                if (   RTFileRename (oldName, newName, RTFILEMOVE_FLAGS_REPLACE)
     3881                    == VERR_FILE_NOT_FOUND)
     3882                    RTFileDelete (newName);
     3883            }
     3884        }
     3885    }
     3886
     3887    PRTLOGGER loggerRelease;
     3888    static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
     3889    RTUINT fFlags = RTLOGFLAGS_PREFIX_TIME_PROG;
     3890#if defined (RT_OS_WINDOWS) || defined (RT_OS_OS2)
     3891    fFlags |= RTLOGFLAGS_USECRLF;
     3892#endif
     3893    char szError[RTPATH_MAX + 128] = "";
     3894    int vrc = RTLogCreateEx(&loggerRelease, fFlags, "all",
     3895                            "VBOX_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups,
     3896                            RTLOGDEST_FILE, szError, sizeof(szError), logFile.raw());
     3897    if (RT_SUCCESS(vrc))
     3898    {
     3899        /* some introductory information */
     3900        RTTIMESPEC timeSpec;
     3901        char nowUct[64];
     3902        RTTimeSpecToString(RTTimeNow(&timeSpec), nowUct, sizeof(nowUct));
     3903        RTLogRelLogger(loggerRelease, 0, ~0U,
     3904                       "VirtualBox %s r%d %s (%s %s) release log\n"
     3905                       "Log opened %s\n",
     3906                       VBOX_VERSION_STRING, VBoxSVNRev (), VBOX_BUILD_TARGET,
     3907                       __DATE__, __TIME__, nowUct);
     3908
     3909        /* register this logger as the release logger */
     3910        RTLogRelSetDefaultInstance(loggerRelease);
     3911        hrc = S_OK;
     3912    }
     3913    else
     3914        hrc = setError (E_FAIL,
     3915                        tr ("Failed to open release log (%s, %Rrc)"), szError, vrc);
     3916
     3917    return hrc;
     3918}
     3919
    39183920
    39193921/**
     
    54455447 * @param   rc          VBox status code.
    54465448 * @param   pszFormat   Printf-like error message.
    5447  * @param   args        Various number of argumens for the error message. 
    5448  * 
    5449  * @thread EMT, VMPowerUp... 
    5450  * 
    5451  * @note The VMProgressTask structure modified by this callback is not thread 
     5449 * @param   args        Various number of argumens for the error message.
     5450 *
     5451 * @thread EMT, VMPowerUp...
     5452 *
     5453 * @note The VMProgressTask structure modified by this callback is not thread
    54525454 *       safe.
    54535455 */
     
    59935995    {
    59945996        /* We are still in the Starting/Restoring state. This means one of:
    5995          * 
     5997         *
    59965998         * 1) we failed before VMR3Create() was called;
    59975999         * 2) VMR3Create() failed.
    5998          * 
     6000         *
    59996001         * In both cases, there is no need to call powerDown(), but we still
    60006002         * need to go back to the PoweredOff/Saved state. Reuse
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r6388 r6464  
    377377    void releaseVMCaller();
    378378
     379    HRESULT consoleInitReleaseLog (const ComPtr <IMachine> aMachine);
     380
    379381    HRESULT powerDown();
    380382
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