VirtualBox

Changeset 69745 in vbox


Ignore:
Timestamp:
Nov 18, 2017 8:52:38 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119145
Message:

IPRT: Added tweak (RTLOGDEST_F_DELAY_FILE) for delaying log file opening untill the RTLogClearFileDelayFlag function is called.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/log.h

    r69105 r69745  
    457457    /** Open files with no deny (share read, write, delete) on Windows. */
    458458    RTLOGDEST_F_NO_DENY     = 0x00010000,
     459    /** Delay opening the log file, logging to the buffer untill
     460     * RTLogClearFileDelayFlag is called. */
     461    RTLOGDEST_F_DELAY_FILE  = 0x00020000,
    459462    /** Just a dummy flag to be used when no other flag applies. */
    460463    RTLOGDEST_DUMMY         = 0x20000000,
     
    22692272
    22702273/**
     2274 * Clear the file delay flag if set, opening the destination and flushing.
     2275 *
     2276 * @returns IPRT status code.
     2277 * @param   pLogger             Logger instance (NULL for default logger).
     2278 * @param   pszValue            The value to parse.
     2279 * @param   pErrInfo            Where to return extended error info.  Optional.
     2280 */
     2281RTDECL(int) RTLogClearFileDelayFlag(PRTLOGGER pLogger, PRTERRINFO pErrInfo);
     2282
     2283/**
    22712284 * Get the current log destinations as a string.
    22722285 *
  • trunk/include/iprt/mangling.h

    r69742 r69745  
    12341234# define RTLogBackdoorPrintfV                           RT_MANGLER(RTLogBackdoorPrintfV) /* r0drv-guest */
    12351235# define RTLogCalcSizeForR0                             RT_MANGLER(RTLogCalcSizeForR0)
     1236# define RTLogClearFileDelayFlag                        RT_MANGLER(RTLogClearFileDelayFlag)
    12361237# define RTLogCloneRC                                   RT_MANGLER(RTLogCloneRC)
    12371238# define RTLogComPrintf                                 RT_MANGLER(RTLogComPrintf)
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r69111 r69745  
    228228#endif
    229229#ifdef IN_RING3
    230 static int rtlogFileOpen(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg);
    231 static void rtlogRotate(PRTLOGGER pLogger, uint32_t uTimeSlot, bool fFirst);
     230static int  rtR3LogOpenFileDestination(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg);
    232231#endif
    233232#ifndef IN_RC
    234233static void rtLogRingBufFlush(PRTLOGGER pLogger);
    235234#endif
    236 static void rtlogFlush(PRTLOGGER pLogger);
     235static void rtlogFlush(PRTLOGGER pLogger, bool fNeedSpace);
    237236static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars);
    238237static DECLCALLBACK(size_t) rtLogOutputPrefixed(void *pv, const char *pachChars, size_t cbChars);
     
    776775# endif
    777776}
    778 
    779 
    780777
    781778
     
    947944             */
    948945            rc = VINF_SUCCESS;
     946            if ((pLogger->fDestFlags & (RTLOGDEST_F_DELAY_FILE | RTLOGDEST_FILE)) == RTLOGDEST_F_DELAY_FILE)
     947                pLogger->fDestFlags &= ~RTLOGDEST_F_DELAY_FILE;
    949948# ifdef IN_RING3
    950             if (pLogger->fDestFlags & RTLOGDEST_FILE)
    951             {
    952                 if (pLogger->fFlags & RTLOGFLAGS_APPEND)
    953                 {
    954                     rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg);
    955 
    956                     /* Rotate in case of appending to a too big log file,
    957                        otherwise this simply doesn't do anything. */
    958                     rtlogRotate(pLogger, 0, true /* fFirst */);
    959                 }
    960                 else
    961                 {
    962                     /* Force rotation if it is configured. */
    963                     pLogger->pInt->cbHistoryFileWritten = UINT64_MAX;
    964                     rtlogRotate(pLogger, 0, true /* fFirst */);
    965 
    966                     /* If the file is not open then rotation is not set up. */
    967                     if (pLogger->pInt->hFile == NIL_RTFILE)
    968                     {
    969                         pLogger->pInt->cbHistoryFileWritten = 0;
    970                         rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg);
    971                     }
    972                 }
    973             }
    974 # endif  /* IN_RING3 */
     949            if ((pLogger->fDestFlags & (RTLOGDEST_FILE | RTLOGDEST_F_DELAY_FILE)) == RTLOGDEST_FILE)
     950                rc = rtR3LogOpenFileDestination(pLogger, pszErrorMsg, cchErrorMsg);
     951# endif
    975952
    976953            if ((pLogger->fDestFlags & RTLOGDEST_RINGBUF) && RT_SUCCESS(rc))
     
    11021079     * Flush it.
    11031080     */
    1104     rtlogFlush(pLogger);
     1081    rtlogFlush(pLogger, false /*fNeedSpace*/);
    11051082
    11061083# ifdef IN_RING3
     
    24492426
    24502427/**
     2428 * Clear the file delay flag if set, opening the destination and flushing.
     2429 *
     2430 * @returns IPRT status code.
     2431 * @param   pLogger             Logger instance (NULL for default logger).
     2432 * @param   pszValue            The value to parse.
     2433 * @param   pErrInfo            Where to return extended error info.  Optional.
     2434 */
     2435RTDECL(int) RTLogClearFileDelayFlag(PRTLOGGER pLogger, PRTERRINFO pErrInfo)
     2436{
     2437    /*
     2438     * Resolve defaults.
     2439     */
     2440    if (!pLogger)
     2441    {
     2442        pLogger = RTLogDefaultInstance();
     2443        if (!pLogger)
     2444            return VINF_SUCCESS;
     2445    }
     2446
     2447    /*
     2448     * Do the work.
     2449     */
     2450    int rc = rtlogLock(pLogger);
     2451    if (RT_SUCCESS(rc))
     2452    {
     2453        if (pLogger->fDestFlags & RTLOGDEST_F_DELAY_FILE)
     2454        {
     2455            pLogger->fDestFlags &= ~RTLOGDEST_F_DELAY_FILE;
     2456# ifdef IN_RING3
     2457            if (   pLogger->fDestFlags & RTLOGDEST_FILE
     2458                && pLogger->pInt->hFile == NIL_RTFILE)
     2459            {
     2460                int rc = rtR3LogOpenFileDestination(pLogger, NULL, 0);
     2461                if (RT_SUCCESS(rc))
     2462                    rtlogFlush(pLogger, false /*fNeedSpace*/);
     2463            }
     2464# endif
     2465            RT_NOREF(pErrInfo); /** @todo fix create API to use RTErrInfo */
     2466        }
     2467        rtlogUnlock(pLogger);
     2468    }
     2469    return VINF_SUCCESS;
     2470}
     2471RT_EXPORT_SYMBOL(RTLogClearFileDelayFlag);
     2472
     2473
     2474/**
    24512475 * Get the current log destinations as a string.
    24522476 *
     
    26052629         * Call worker.
    26062630         */
    2607         rtlogFlush(pLogger);
     2631        rtlogFlush(pLogger, false /*fNeedSpace*/);
    26082632
    26092633#ifndef IN_RC
     
    33173341}
    33183342
     3343
     3344/**
     3345 * Worker for RTLogCreateExV and RTLogClearFileDelayFlag.
     3346 *
     3347 * This will later be used to reopen the file by RTLogDestinations.
     3348 *
     3349 * @returns IPRT status code.
     3350 * @param   pLogger             The logger.
     3351 * @param   pszErrorMsg         Where to return error info. Optional.
     3352 * @param   cchErrorMsg         Size of @a pszErrorMsg buffer.
     3353 */
     3354static int rtR3LogOpenFileDestination(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg)
     3355{
     3356    int rc;
     3357    if (pLogger->fFlags & RTLOGFLAGS_APPEND)
     3358    {
     3359        rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg);
     3360
     3361        /* Rotate in case of appending to a too big log file,
     3362           otherwise this simply doesn't do anything. */
     3363        rtlogRotate(pLogger, 0, true /* fFirst */);
     3364    }
     3365    else
     3366    {
     3367        /* Force rotation if it is configured. */
     3368        pLogger->pInt->cbHistoryFileWritten = UINT64_MAX;
     3369        rtlogRotate(pLogger, 0, true /* fFirst */);
     3370
     3371        /* If the file is not open then rotation is not set up. */
     3372        if (pLogger->pInt->hFile == NIL_RTFILE)
     3373        {
     3374            pLogger->pInt->cbHistoryFileWritten = 0;
     3375            rc = rtlogFileOpen(pLogger, pszErrorMsg, cchErrorMsg);
     3376        }
     3377        else
     3378            rc = VINF_SUCCESS;
     3379    }
     3380    return rc;
     3381}
     3382
    33193383#endif /* IN_RING3 */
    33203384
     
    33233387 * Writes the buffer to the given log device without checking for buffered
    33243388 * data or anything.
     3389 *
    33253390 * Used by the RTLogFlush() function.
    33263391 *
    33273392 * @param   pLogger     The logger instance to write to. NULL is not allowed!
    3328  */
    3329 static void rtlogFlush(PRTLOGGER pLogger)
     3393 * @param   fNeedSpace  Set if the caller assumes space will be made available.
     3394 */
     3395static void rtlogFlush(PRTLOGGER pLogger, bool fNeedSpace)
    33303396{
    33313397    uint32_t const cchScratch = pLogger->offScratch;
    33323398    if (cchScratch == 0)
    33333399        return; /* nothing to flush. */
     3400    NOREF(fNeedSpace);
    33343401
    33353402#ifndef IN_RC
     
    33453412        pLogger->offScratch = 0; /* empty the buffer. */
    33463413    }
     3414    /*
     3415     * In file delay mode, we ignore flush requests except when we're full
     3416     * and the caller really needs some scratch space to get work done.
     3417     */
    33473418    else
     3419# ifdef IN_RING3
     3420        if (!(pLogger->fDestFlags & RTLOGDEST_F_DELAY_FILE))
     3421# endif
    33483422#endif
    33493423    {
     
    34103484#endif
    34113485    }
     3486#ifdef IN_RING3
     3487    else
     3488    {
     3489        /*
     3490         * Delay file open but the caller really need some space.  So, give him half a
     3491         * buffer and insert a message indicating that we've dropped output.
     3492         */
     3493        uint32_t offHalf = sizeof(pLogger->achScratch) / 2;
     3494        if (cchScratch > offHalf)
     3495        {
     3496            if (pLogger->fFlags & RTLOGFLAGS_USECRLF)
     3497                pLogger->achScratch[offHalf++] = '\r';
     3498            static const char s_szDropMsg[] = "\n[DROP DROP DROP]";
     3499            memcpy(&pLogger->achScratch[offHalf], RT_STR_TUPLE(s_szDropMsg));
     3500            offHalf += sizeof(s_szDropMsg) - 1;
     3501            if (pLogger->fFlags & RTLOGFLAGS_USECRLF)
     3502                pLogger->achScratch[offHalf++] = '\r';
     3503            pLogger->achScratch[offHalf++] = '\n';
     3504
     3505            pLogger->offScratch = offHalf;
     3506        }
     3507    }
     3508#endif
    34123509}
    34133510
     
    34553552
    34563553            /* flush */
    3457             rtlogFlush(pLogger);
     3554            rtlogFlush(pLogger, true /*fNeedSpace*/);
    34583555        }
    34593556
     
    35523649                if (cb < 256 + 16)
    35533650                {
    3554                     rtlogFlush(pLogger);
     3651                    rtlogFlush(pLogger, true /*fNeedSpace*/);
    35553652                    offScratch = pLogger->offScratch;
    35563653                    cb = sizeof(pLogger->achScratch) - offScratch - 1;
     
    38503947            else if (cb <= 0)
    38513948            {
    3852                 rtlogFlush(pLogger);
     3949                rtlogFlush(pLogger, true /*fNeedSpace*/);
    38533950                offScratch = pLogger->offScratch;
    38543951                cb = sizeof(pLogger->achScratch) - offScratch - 1;
     
    39534050    if (    !(pLogger->fFlags & RTLOGFLAGS_BUFFERED)
    39544051        &&  pLogger->offScratch)
    3955         rtlogFlush(pLogger);
     4052        rtlogFlush(pLogger, false /*fNeedSpace*/);
    39564053}
    39574054
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