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/plugins/imuxsock/imuxsock.c
static rsRetVal findRatelimiter(lstn_t* pLstn, struct ucred* cred,
                                ratelimit_t** prl)
{
    ratelimit_t* rl = NULL;
    int r;
    pid_t* keybuf;
    char pinfobuf[512];
    DEFiRet;

    if (cred == NULL)
        FINALIZE;
#if 0 // TODO: check deactivated?
	if(pLstn->ratelimitInterval == 0) {
		*prl = NULL;
		FINALIZE;
	}
#endif
    if (pLstn->ht == NULL)
    {
        *prl = NULL;
        FINALIZE;
    }

    rl = hashtable_search(pLstn->ht, &cred->pid);
    if (rl == NULL)
    {
        /* we need to add a new ratelimiter, process not seen before! */
        DBGPRINTF("imuxsock: no ratelimiter for pid %lu, creating one\n",
                  (unsigned long)cred->pid);
        STATSCOUNTER_INC(ctrNumRatelimiters, mutCtrNumRatelimiters);
        /* read process name from system  */
        char procName[256]; /* enough for any sane process name  */
        snprintf(procName, sizeof(procName), "/proc/%lu/cmdline",
                 (unsigned long)cred->pid);
        FILE* f = fopen(procName, "r");
        if (f)
        {
            size_t len;
            len = fread(procName, sizeof(char), 256, f);
            if (len > 0)
            {
                snprintf(pinfobuf, sizeof(pinfobuf), "pid: %lu, name: %s",
                         (unsigned long)cred->pid, procName);
            }
            fclose(f);
        }
        else
        {
            snprintf(pinfobuf, sizeof(pinfobuf), "pid: %lu",
                     (unsigned long)cred->pid);
        }
        pinfobuf[sizeof(pinfobuf) - 1] = '\0'; /* to be on safe side */
        CHKiRet(ratelimitNew(&rl, "imuxsock", pinfobuf));
        ratelimitSetLinuxLike(rl, pLstn->ratelimitInterval,
                              pLstn->ratelimitBurst);
        ratelimitSetSeverity(rl, pLstn->ratelimitSev);
        CHKmalloc(keybuf = malloc(sizeof(pid_t)));
        *keybuf = cred->pid;
        r = hashtable_insert(pLstn->ht, keybuf, rl);
        if (r == 0)
            ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
    }

    *prl = rl;
    rl = NULL;

finalize_it:
    if (rl != NULL)
        ratelimitDestruct(rl);
    if (*prl == NULL)
        *prl = pLstn->dflt_ratelimiter;
    RETiRet;
}
/* find ratelimiter to use for this message. Currently, we use the
 * pid, but may change to cgroup later (probably via a config switch).
 * Returns NULL if not found or rate-limiting not activated for this
 * listener (the latter being a performance enhancement).
 */
find ratelimiter to use for this message. Currently, we use the
pid, but may change to cgroup later (probably via a config switch).
Returns NULL if not found or rate-limiting not activated for this
listener (the latter being a performance enhancement).
find ratelimiter to use for this message . Currently we use the pid but may change to cgroup later ( probably via a config switch ) . Returns NULL if not found or rate - limiting not activated for this listener ( the latter being a performance enhancement ) .
static rsRetVal findRatelimiter(lstn_t* pLstn, struct ucred* cred,
                                ratelimit_t** prl)
{
    ratelimit_t* rl = NULL;
    int r;
    pid_t* keybuf;
    char pinfobuf[512];
    DEFiRet;
    if (cred == NULL)
        FINALIZE;
#if 0 
	if(pLstn->ratelimitInterval == 0) {
		*prl = NULL;
		FINALIZE;
	}
#endif
    if (pLstn->ht == NULL)
    {
        *prl = NULL;
        FINALIZE;
    }
    rl = hashtable_search(pLstn->ht, &cred->pid);
    if (rl == NULL)
    {
        DBGPRINTF("imuxsock: no ratelimiter for pid %lu, creating one\n",
                  (unsigned long)cred->pid);
        STATSCOUNTER_INC(ctrNumRatelimiters, mutCtrNumRatelimiters);
        char procName[256]; 
        snprintf(procName, sizeof(procName), "/proc/%lu/cmdline",
                 (unsigned long)cred->pid);
        FILE* f = fopen(procName, "r");
        if (f)
        {
            size_t len;
            len = fread(procName, sizeof(char), 256, f);
            if (len > 0)
            {
                snprintf(pinfobuf, sizeof(pinfobuf), "pid: %lu, name: %s",
                         (unsigned long)cred->pid, procName);
            }
            fclose(f);
        }
        else
        {
            snprintf(pinfobuf, sizeof(pinfobuf), "pid: %lu",
                     (unsigned long)cred->pid);
        }
        pinfobuf[sizeof(pinfobuf) - 1] = '\0'; 
        CHKiRet(ratelimitNew(&rl, "imuxsock", pinfobuf));
        ratelimitSetLinuxLike(rl, pLstn->ratelimitInterval,
                              pLstn->ratelimitBurst);
        ratelimitSetSeverity(rl, pLstn->ratelimitSev);
        CHKmalloc(keybuf = malloc(sizeof(pid_t)));
        *keybuf = cred->pid;
        r = hashtable_insert(pLstn->ht, keybuf, rl);
        if (r == 0)
            ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
    }
    *prl = rl;
    rl = NULL;
finalize_it:
    if (rl != NULL)
        ratelimitDestruct(rl);
    if (*prl == NULL)
        *prl = pLstn->dflt_ratelimiter;
    RETiRet;
}
static rsRetVal findRatelimiter ( lstn_t * pLstn , struct ucred * cred , ratelimit_t * * prl ) { ratelimit_t * rl = NULL ; int r ; pid_t * keybuf ; char pinfobuf [ 512 ] ; DEFiRet ; if ( cred == NULL ) FINALIZE ; #if 0 if ( pLstn -> ratelimitInterval == 0 ) { * prl = NULL ; FINALIZE ; } #endif if ( pLstn -> ht == NULL ) { * prl = NULL ; FINALIZE ; } rl = hashtable_search ( pLstn -> ht , & cred -> pid ) ; if ( rl == NULL ) { DBGPRINTF ( " \n " , ( unsigned long ) cred -> pid ) ; STATSCOUNTER_INC ( ctrNumRatelimiters , mutCtrNumRatelimiters ) ; char procName [ 256 ] ; snprintf ( procName , sizeof ( procName ) , " " , ( unsigned long ) cred -> pid ) ; FILE * f = fopen ( procName , " " ) ; if ( f ) { size_t len ; len = fread ( procName , sizeof ( char ) , 256 , f ) ; if ( len > 0 ) { snprintf ( pinfobuf , sizeof ( pinfobuf ) , " " , ( unsigned long ) cred -> pid , procName ) ; } fclose ( f ) ; } else { snprintf ( pinfobuf , sizeof ( pinfobuf ) , " " , ( unsigned long ) cred -> pid ) ; } pinfobuf [ sizeof ( pinfobuf ) - 1 ] = ' \0 ' ; CHKiRet ( ratelimitNew ( & rl , " " , pinfobuf ) ) ; ratelimitSetLinuxLike ( rl , pLstn -> ratelimitInterval , pLstn -> ratelimitBurst ) ; ratelimitSetSeverity ( rl , pLstn -> ratelimitSev ) ; CHKmalloc ( keybuf = malloc ( sizeof ( pid_t ) ) ) ; * keybuf = cred -> pid ; r = hashtable_insert ( pLstn -> ht , keybuf , rl ) ; if ( r == 0 ) ABORT_FINALIZE ( RS_RET_OUT_OF_MEMORY ) ; } * prl = rl ; rl = NULL ; finalize_it : if ( rl != NULL ) ratelimitDestruct ( rl ) ; if ( * prl == NULL ) * prl = pLstn -> dflt_ratelimiter ; RETiRet ; }
find ratelimiter to use for this message.
find ratelimiter to use for this message .
// TODO: check deactivated? /* we need to add a new ratelimiter, process not seen before! */ /* read process name from system  */ /* enough for any sane process name  */ /* to be on safe side */