VirtualBox

Changeset 69749 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Nov 19, 2017 12:49:36 PM (7 years ago)
Author:
vboxsync
Message:

Changed RTLogCreateEx[V] to take a RTERRINFO pointer rather than plain char * and size_t. Turned out a several callers didn't actually make use of the error message even.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r69746 r69749  
    228228#endif
    229229#ifdef IN_RING3
    230 static int  rtR3LogOpenFileDestination(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg);
     230static int  rtR3LogOpenFileDestination(PRTLOGGER pLogger, PRTERRINFO pErrInfo);
    231231#endif
    232232#ifndef IN_RC
     
    781781                           uint32_t fDestFlags, PFNRTLOGPHASE pfnPhase, uint32_t cHistory,
    782782                           uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot,
    783                            char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, va_list args)
     783                           PRTERRINFO pErrInfo, const char *pszFilenameFmt, va_list args)
    784784{
    785785    int         rc;
     
    791791     * Validate input.
    792792     */
    793     if (    (cGroups && !papszGroups)
    794         ||  !VALID_PTR(ppLogger) )
     793    if (   (cGroups && !papszGroups)
     794        || !VALID_PTR(ppLogger) )
    795795    {
    796796        AssertMsgFailed(("Invalid parameters!\n"));
     
    798798    }
    799799    *ppLogger = NULL;
    800 
    801     if (pszErrorMsg)
    802         RTStrPrintf(pszErrorMsg, cchErrorMsg, N_("unknown error"));
    803800
    804801    AssertMsgReturn(cHistory < _1M, ("%#x", cHistory), VERR_OUT_OF_RANGE);
     
    882879        else
    883880        {
     881            rc = VERR_NO_MEMORY;
    884882#  ifdef RT_OS_LINUX
    885             if (pszErrorMsg) /* Most probably SELinux causing trouble since the larger RTMemAlloc succeeded. */
    886                 RTStrPrintf(pszErrorMsg, cchErrorMsg, N_("mmap(PROT_WRITE | PROT_EXEC) failed -- SELinux?"));
     883                /* Most probably SELinux causing trouble since the larger RTMemAlloc succeeded. */
     884            RTErrInfoSet(rc, N_("mmap(PROT_WRITE | PROT_EXEC) failed -- SELinux?"));
    887885#  endif
    888             rc = VERR_NO_MEMORY;
    889886        }
    890887        if (RT_SUCCESS(rc))
     
    948945# ifdef IN_RING3
    949946            if ((pLogger->fDestFlags & (RTLOGDEST_FILE | RTLOGDEST_F_DELAY_FILE)) == RTLOGDEST_FILE)
    950                 rc = rtR3LogOpenFileDestination(pLogger, pszErrorMsg, cchErrorMsg);
     947                rc = rtR3LogOpenFileDestination(pLogger, pErrInfo);
    951948# endif
    952949
     
    984981                }
    985982
    986                 if (pszErrorMsg)
    987                     RTStrPrintf(pszErrorMsg, cchErrorMsg, N_("failed to create semaphore"));
     983                RTErrInfoSet(pErrInfo, rc, N_("failed to create semaphore"));
    988984            }
    989985# ifdef IN_RING3
     
    10161012    rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups,
    10171013                        fDestFlags, NULL /*pfnPhase*/, 0 /*cHistory*/, 0 /*cbHistoryFileMax*/, 0 /*cSecsHistoryTimeSlot*/,
    1018                         NULL /*pszErrorMsg*/, 0 /*cchErrorMsg*/, pszFilenameFmt, args);
     1014                        NULL /*pErrInfo*/, pszFilenameFmt, args);
    10191015    va_end(args);
    10201016    return rc;
     
    10271023                          uint32_t fDestFlags, PFNRTLOGPHASE pfnPhase, uint32_t cHistory,
    10281024                          uint64_t cbHistoryFileMax, uint32_t cSecsHistoryTimeSlot,
    1029                           char *pszErrorMsg, size_t cchErrorMsg, const char *pszFilenameFmt, ...)
     1025                          PRTERRINFO pErrInfo, const char *pszFilenameFmt, ...)
    10301026{
    10311027    va_list args;
     
    10351031    rc = RTLogCreateExV(ppLogger, fFlags, pszGroupSettings, pszEnvVarBase, cGroups, papszGroups,
    10361032                        fDestFlags, pfnPhase, cHistory, cbHistoryFileMax, cSecsHistoryTimeSlot,
    1037                         pszErrorMsg, cchErrorMsg, pszFilenameFmt, args);
     1033                        pErrInfo, pszFilenameFmt, args);
    10381034    va_end(args);
    10391035    return rc;
     
    24582454                && pLogger->pInt->hFile == NIL_RTFILE)
    24592455            {
    2460                 rc = rtR3LogOpenFileDestination(pLogger, NULL, 0);
     2456                rc = rtR3LogOpenFileDestination(pLogger, pErrInfo);
    24612457                if (RT_SUCCESS(rc))
    24622458                    rtlogFlush(pLogger, false /*fNeedSpace*/);
     
    31743170 *
    31753171 * @param   pLogger         The logger instance to update. NULL is not allowed!
    3176  * @param   pszErrorMsg     A buffer which is filled with an error message if
    3177  *                          something fails.  May be NULL.
    3178  * @param   cchErrorMsg     The size of the error message buffer.
    3179  */
    3180 static int rtlogFileOpen(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg)
     3172 * @param   pErrInfo        Where to return extended error information.
     3173 *                          Optional.
     3174 */
     3175static int rtlogFileOpen(PRTLOGGER pLogger, PRTERRINFO pErrInfo)
    31813176{
    31823177    uint32_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_NONE;
     
    32113206    {
    32123207        pLogger->pInt->hFile = NIL_RTFILE;
    3213         if (pszErrorMsg)
    3214             RTStrPrintf(pszErrorMsg, cchErrorMsg, N_("could not open file '%s' (fOpen=%#x)"), pLogger->pInt->szFilename, fOpen);
     3208        RTErrInfoSetF(pErrInfo, rc, N_("could not open file '%s' (fOpen=%#x)"), pLogger->pInt->szFilename, fOpen);
    32153209    }
    32163210    return rc;
     
    32283222 *                      called from RTLogCreateExV.  Prevents pfnPhase from
    32293223 *                      being called.
    3230  */
    3231 static void rtlogRotate(PRTLOGGER pLogger, uint32_t uTimeSlot, bool fFirst)
     3224 * @param   pErrInfo    Where to return extended error information. Optional.
     3225 */
     3226static void rtlogRotate(PRTLOGGER pLogger, uint32_t uTimeSlot, bool fFirst, PRTERRINFO pErrInfo)
    32323227{
    32333228    /* Suppress rotating empty log files simply because the time elapsed. */
     
    33213316    pLogger->pInt->cbHistoryFileWritten = 0;
    33223317    pLogger->pInt->uHistoryTimeSlotStart = uTimeSlot;
    3323     rtlogFileOpen(pLogger, NULL, 0);
     3318    rtlogFileOpen(pLogger, pErrInfo);
    33243319
    33253320    /*
     
    33493344 * @returns IPRT status code.
    33503345 * @param   pLogger             The logger.
    3351  * @param   pszErrorMsg         Where to return error info. Optional.
    3352  * @param   cchErrorMsg         Size of @a pszErrorMsg buffer.
    3353  */
    3354 static int rtR3LogOpenFileDestination(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg)
     3346 * @param   pErrInfo            Where to return extended error information.
     3347 *                              Optional.
     3348 */
     3349static int rtR3LogOpenFileDestination(PRTLOGGER pLogger, PRTERRINFO pErrInfo)
    33553350{
    33563351    int rc;
    33573352    if (pLogger->fFlags & RTLOGFLAGS_APPEND)
    33583353    {
    3359         rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg);
     3354        rc = rtlogFileOpen(pLogger, pErrInfo);
    33603355
    33613356        /* Rotate in case of appending to a too big log file,
    33623357           otherwise this simply doesn't do anything. */
    3363         rtlogRotate(pLogger, 0, true /* fFirst */);
     3358        rtlogRotate(pLogger, 0, true /* fFirst */, pErrInfo);
    33643359    }
    33653360    else
     
    33673362        /* Force rotation if it is configured. */
    33683363        pLogger->pInt->cbHistoryFileWritten = UINT64_MAX;
    3369         rtlogRotate(pLogger, 0, true /* fFirst */);
     3364        rtlogRotate(pLogger, 0, true /* fFirst */, pErrInfo);
    33703365
    33713366        /* If the file is not open then rotation is not set up. */
     
    33733368        {
    33743369            pLogger->pInt->cbHistoryFileWritten = 0;
    3375             rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg);
     3370            rc = rtlogFileOpen(pLogger, pErrInfo);
    33763371        }
    33773372        else
     
    34813476        if (   (pLogger->fDestFlags & RTLOGDEST_FILE)
    34823477            && pLogger->pInt->cHistory)
    3483             rtlogRotate(pLogger, RTTimeProgramSecTS() / pLogger->pInt->cSecsHistoryTimeSlot, false /* fFirst */);
     3478            rtlogRotate(pLogger, RTTimeProgramSecTS() / pLogger->pInt->cSecsHistoryTimeSlot, false /*fFirst*/, NULL /*pErrInfo*/);
    34843479#endif
    34853480    }
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