VirtualBox

Changeset 104750 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
May 22, 2024 9:46:13 AM (6 months ago)
Author:
vboxsync
Message:

Main/SystemProperties.cpp: i_setLoggingLevel needs to check that RTLogRelGetDefaultInstance() doesn't return NULL, otherwise calls will affect the default debug logger. Cleaned up the function, making it set error on failure. Ignore i_setLoggingLevel failure when loading settings, since we'll be falling back on default logging settings anyway.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/SystemPropertiesImpl.cpp

    r104748 r104750  
    14401440
    14411441    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1442
     1443    i_setLoggingLevel(data.strLoggingLevel); /* ignore errors here! */
     1444
    14421445    HRESULT hrc = i_setDefaultMachineFolder(data.strDefaultMachineFolder);
    1443     if (FAILED(hrc)) return hrc;
    1444 
    1445     hrc = i_setLoggingLevel(data.strLoggingLevel);
    14461446    if (FAILED(hrc)) return hrc;
    14471447
     
    16671667HRESULT SystemProperties::i_setLoggingLevel(const com::Utf8Str &aLoggingLevel)
    16681668{
    1669     Utf8Str useLoggingLevel(aLoggingLevel);
    1670     if (useLoggingLevel.isEmpty())
    1671         useLoggingLevel = VBOXSVC_LOG_DEFAULT;
    1672     int vrc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), useLoggingLevel.c_str());
    1673     //  If failed and not the default logging level - try to use the default logging level.
    1674     if (RT_FAILURE(vrc))
    1675     {
    1676         // If failed write message to the release log.
    1677         LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), vrc));
    1678         //  If attempted logging level not the default one then try the default one.
    1679         if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
     1669    static const char s_szDefaultLevel[] = VBOXSVC_LOG_DEFAULT;
     1670    const char       *pszUseLoggingLevel = aLoggingLevel.isEmpty() || aLoggingLevel.equalsIgnoreCase(s_szDefaultLevel)
     1671                                         ? s_szDefaultLevel : aLoggingLevel.c_str();
     1672    HRESULT           hrc                = S_OK;
     1673    PRTLOGGER const   pRelLog            = RTLogRelGetDefaultInstance();
     1674    if (pRelLog)
     1675    {
     1676        int vrc = RTLogGroupSettings(pRelLog, pszUseLoggingLevel);
     1677        if (RT_FAILURE(vrc))
    16801678        {
    1681             vrc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), VBOXSVC_LOG_DEFAULT);
    1682             // If failed report this to the release log.
    1683             if (RT_FAILURE(vrc))
    1684                 LogRel(("Cannot set default logging level Error=%Rrc \n", vrc));
     1679            LogRel(("Failed to set release logging level to '%s': %Rrc\n", pszUseLoggingLevel, vrc));
     1680            hrc = setErrorVrc(vrc, tr("RTLogGroupSettings failed: %Rrc (input: %s)"), vrc, pszUseLoggingLevel);
     1681
     1682            // If attempted logging level not the default one then use the default one.
     1683            if (pszUseLoggingLevel != s_szDefaultLevel)
     1684            {
     1685                pszUseLoggingLevel = s_szDefaultLevel;
     1686                vrc = RTLogGroupSettings(pRelLog, s_szDefaultLevel);
     1687                if (RT_FAILURE(vrc))
     1688                    LogRel(("Failed to set default release logging level: %Rrc\n", vrc));
     1689            }
    16851690        }
    1686         // On any failure - set default level as the one to be stored.
    1687         useLoggingLevel = VBOXSVC_LOG_DEFAULT;
    1688     }
    1689     //  Set to passed value or if default used/attempted (even if error condition) use empty string.
    1690     m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
    1691     return RT_SUCCESS(vrc) ? S_OK : E_FAIL;
     1691    }
     1692
     1693    // Set to passed value or if default used/attempted (even if error condition) use empty string.
     1694    if (pszUseLoggingLevel == s_szDefaultLevel)
     1695        m->strLoggingLevel.setNull();
     1696    else
     1697        m->strLoggingLevel = aLoggingLevel;
     1698
     1699    return hrc;
    16921700}
    16931701
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