openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/stream.c
static rsRetVal resolveFileSizeLimit(strm_t* pThis, uchar* pszCurrFName)
{
    uchar* pParams;
    uchar* pCmd;
    uchar* p;
    off_t actualFileSize;
    rsRetVal localRet;
    DEFiRet;
    ISOBJ_TYPE_assert(pThis, strm);
    assert(pszCurrFName != NULL);

    if (pThis->pszSizeLimitCmd == NULL)
    {
        ABORT_FINALIZE(
            RS_RET_NON_SIZELIMITCMD); /* nothing we can do in this case... */
    }

    /* we first check if we have command line parameters. We assume this,
     * when we have a space in the program name. If we find it, everything after
     * the space is treated as a single argument.
     */
    CHKmalloc(pCmd = ustrdup(pThis->pszSizeLimitCmd));

    for (p = pCmd; *p && *p != ' '; ++p)
    {
        /* JUST SKIP */
    }

    if (*p == ' ')
    {
        *p = '\0'; /* pretend string-end */
        pParams = p + 1;
    }
    else
        pParams = NULL;

    /* the execProg() below is probably not great, but at least is is
     * fairly secure now. Once we change the way file size limits are
     * handled, we should also revisit how this command is run (and
     * with which parameters).   rgerhards, 2007-07-20
     */
    execProg(pCmd, 1, pParams);

    free(pCmd);

    localRet = getFileSize(pszCurrFName, &actualFileSize);

    if (localRet == RS_RET_OK && actualFileSize >= pThis->iSizeLimit)
    {
        ABORT_FINALIZE(
            RS_RET_SIZELIMITCMD_DIDNT_RESOLVE); /* OK, it didn't work out... */
    }
    else if (localRet != RS_RET_FILE_NOT_FOUND)
    {
        /* file not found is OK, the command may have moved away the file */
        ABORT_FINALIZE(localRet);
    }

finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (iRet == RS_RET_SIZELIMITCMD_DIDNT_RESOLVE)
        {
            LogError(0, RS_RET_ERR,
                     "file size limit cmd for file '%s' "
                     "did no resolve situation\n",
                     pszCurrFName);
        }
        else
        {
            LogError(0, RS_RET_ERR,
                     "file size limit cmd for file '%s' "
                     "failed with code %d.\n",
                     pszCurrFName, iRet);
        }
        pThis->bDisabled = 1;
    }

    RETiRet;
}
/* Try to resolve a size limit situation. This is used to support custom-file
 * size handlers for omfile. It first runs the command, and then checks if we
 * are still above the size treshold. Note that this works only with single file
 * names, NOT with circular names. Note that pszCurrFName can NOT be taken from
 * pThis, because the stream is closed when we are called (and that destroys
 * pszCurrFName, as there is NO CURRENT file name!). So we need to receive the
 * name as a parameter. initially wirtten 2005-06-21, moved to this class &
 * updates 2009-06-01, both rgerhards
 */
Try to resolve a size limit situation. This is used to support custom-file
size handlers for omfile. It first runs the command, and then checks if we
are still above the size treshold. Note that this works only with single file
names, NOT with circular names. Note that pszCurrFName can NOT be taken from
pThis, because the stream is closed when we are called (and that destroys
pszCurrFName, as there is NO CURRENT file name!). So we need to receive the
name as a parameter. initially wirtten 2005-06-21, moved to this class &
updates 2009-06-01, both rgerhards
Try to resolve a size limit situation . This is used to support custom - file size handlers for omfile . It first runs the command and then checks if we are still above the size treshold . Note that this works only with single file names NOT with circular names . Note that pszCurrFName can NOT be taken from pThis because the stream is closed when we are called ( and that destroys pszCurrFName as there is NO CURRENT file name! ) . So we need to receive the name as a parameter . initially wirtten 2005 - 06 - 21 moved to this class & updates 2009 - 06 - 01 both rgerhards
static rsRetVal resolveFileSizeLimit(strm_t* pThis, uchar* pszCurrFName)
{
    uchar* pParams;
    uchar* pCmd;
    uchar* p;
    off_t actualFileSize;
    rsRetVal localRet;
    DEFiRet;
    ISOBJ_TYPE_assert(pThis, strm);
    assert(pszCurrFName != NULL);
    if (pThis->pszSizeLimitCmd == NULL)
    {
        ABORT_FINALIZE(
            RS_RET_NON_SIZELIMITCMD); 
    }
    CHKmalloc(pCmd = ustrdup(pThis->pszSizeLimitCmd));
    for (p = pCmd; *p && *p != ' '; ++p)
    {
    }
    if (*p == ' ')
    {
        *p = '\0'; 
        pParams = p + 1;
    }
    else
        pParams = NULL;
    execProg(pCmd, 1, pParams);
    free(pCmd);
    localRet = getFileSize(pszCurrFName, &actualFileSize);
    if (localRet == RS_RET_OK && actualFileSize >= pThis->iSizeLimit)
    {
        ABORT_FINALIZE(
            RS_RET_SIZELIMITCMD_DIDNT_RESOLVE); 
    }
    else if (localRet != RS_RET_FILE_NOT_FOUND)
    {
        ABORT_FINALIZE(localRet);
    }
finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (iRet == RS_RET_SIZELIMITCMD_DIDNT_RESOLVE)
        {
            LogError(0, RS_RET_ERR,
                     "file size limit cmd for file '%s' "
                     "did no resolve situation\n",
                     pszCurrFName);
        }
        else
        {
            LogError(0, RS_RET_ERR,
                     "file size limit cmd for file '%s' "
                     "failed with code %d.\n",
                     pszCurrFName, iRet);
        }
        pThis->bDisabled = 1;
    }
    RETiRet;
}
static rsRetVal resolveFileSizeLimit ( strm_t * pThis , uchar * pszCurrFName ) { uchar * pParams ; uchar * pCmd ; uchar * p ; off_t actualFileSize ; rsRetVal localRet ; DEFiRet ; ISOBJ_TYPE_assert ( pThis , strm ) ; assert ( pszCurrFName != NULL ) ; if ( pThis -> pszSizeLimitCmd == NULL ) { ABORT_FINALIZE ( RS_RET_NON_SIZELIMITCMD ) ; } CHKmalloc ( pCmd = ustrdup ( pThis -> pszSizeLimitCmd ) ) ; for ( p = pCmd ; * p && * p != ' ' ; ++ p ) { } if ( * p == ' ' ) { * p = ' \0 ' ; pParams = p + 1 ; } else pParams = NULL ; execProg ( pCmd , 1 , pParams ) ; free ( pCmd ) ; localRet = getFileSize ( pszCurrFName , & actualFileSize ) ; if ( localRet == RS_RET_OK && actualFileSize >= pThis -> iSizeLimit ) { ABORT_FINALIZE ( RS_RET_SIZELIMITCMD_DIDNT_RESOLVE ) ; } else if ( localRet != RS_RET_FILE_NOT_FOUND ) { ABORT_FINALIZE ( localRet ) ; } finalize_it : if ( iRet != RS_RET_OK ) { if ( iRet == RS_RET_SIZELIMITCMD_DIDNT_RESOLVE ) { LogError ( 0 , RS_RET_ERR , " " " \n " , pszCurrFName ) ; } else { LogError ( 0 , RS_RET_ERR , " " " \n " , pszCurrFName , iRet ) ; } pThis -> bDisabled = 1 ; } RETiRet ; }
Try to resolve a size limit situation.
Try to resolve a size limit situation .
/* nothing we can do in this case... */ /* we first check if we have command line parameters. We assume this,
     * when we have a space in the program name. If we find it, everything after
     * the space is treated as a single argument.
     */ /* JUST SKIP */ /* pretend string-end */ /* the execProg() below is probably not great, but at least is is
     * fairly secure now. Once we change the way file size limits are
     * handled, we should also revisit how this command is run (and
     * with which parameters).   rgerhards, 2007-07-20
     */ /* OK, it didn't work out... */ /* file not found is OK, the command may have moved away the file */