openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/nss-pam-ldapd/0.9.8-r0/nss-pam-ldapd-0.9.8/nslcd/log.c
void log_log(int pri, const char* format, ...)
{
    int res;
    struct log_cfg* lst;
    char buffer[200];
    va_list ap;
#ifndef TLS
    char *sessionid, *requestid;
    pthread_once(&tls_init_once, tls_init_keys);
    sessionid = pthread_getspecific(sessionid_key);
    requestid = pthread_getspecific(requestid_key);
#endif /* no TLS */
    /* make the message */
    va_start(ap, format);
    res = vsnprintf(buffer, sizeof(buffer), format, ap);
    if ((res < 0) || (res >= (int)sizeof(buffer)))
    {
        /* truncate with "..." */
        buffer[sizeof(buffer) - 2] = '.';
        buffer[sizeof(buffer) - 3] = '.';
        buffer[sizeof(buffer) - 4] = '.';
    }
    buffer[sizeof(buffer) - 1] = '\0';
    va_end(ap);
    /* do the logging */
    if (prelogging_loglevel >= 0)
    {
        /* if logging is not yet defined, log to stderr */
        if (pri <= prelogging_loglevel)
        {
            if ((requestid != NULL) && (requestid[0] != '\0'))
                fprintf(stderr, "%s: [%s] <%s> %s%s\n", PACKAGE, sessionid,
                        requestid, pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
            else if ((sessionid != NULL) && (sessionid[0] != '\0'))
                fprintf(stderr, "%s: [%s] %s%s\n", PACKAGE, sessionid,
                        pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
            else
                fprintf(stderr, "%s: %s%s\n", PACKAGE,
                        pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
        }
    }
    else
    {
        for (lst = loglist; lst != NULL; lst = lst->next)
        {
            if (pri <= lst->loglevel)
            {
                if (lst->fp == NULL)
                {
                    if ((requestid != NULL) && (requestid[0] != '\0'))
                        syslog(pri, "[%s] <%s> %s%s", sessionid, requestid,
                               pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else if ((sessionid != NULL) && (sessionid[0] != '\0'))
                        syslog(pri, "[%s] %s%s", sessionid,
                               pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else
                        syslog(pri, "%s%s", pri == LOG_DEBUG ? "DEBUG: " : "",
                               buffer);
                }
                else
                {
                    if ((requestid != NULL) && (requestid[0] != '\0'))
                        fprintf(lst->fp, "%s: [%s] <%s> %s%s\n", PACKAGE,
                                sessionid, requestid,
                                pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else if ((sessionid != NULL) && (sessionid[0] != '\0'))
                        fprintf(lst->fp, "%s: [%s] %s%s\n", PACKAGE, sessionid,
                                pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else
                        fprintf(lst->fp, "%s: %s%s\n", PACKAGE,
                                pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    fflush(lst->fp);
                }
            }
        }
    }
}
/* log the given message using the configured logging method */
log the given message using the configured logging method
log the given message using the configured logging method
void log_log(int pri, const char* format, ...)
{
    int res;
    struct log_cfg* lst;
    char buffer[200];
    va_list ap;
#ifndef TLS
    char *sessionid, *requestid;
    pthread_once(&tls_init_once, tls_init_keys);
    sessionid = pthread_getspecific(sessionid_key);
    requestid = pthread_getspecific(requestid_key);
#endif 
    va_start(ap, format);
    res = vsnprintf(buffer, sizeof(buffer), format, ap);
    if ((res < 0) || (res >= (int)sizeof(buffer)))
    {
        buffer[sizeof(buffer) - 2] = '.';
        buffer[sizeof(buffer) - 3] = '.';
        buffer[sizeof(buffer) - 4] = '.';
    }
    buffer[sizeof(buffer) - 1] = '\0';
    va_end(ap);
    if (prelogging_loglevel >= 0)
    {
        if (pri <= prelogging_loglevel)
        {
            if ((requestid != NULL) && (requestid[0] != '\0'))
                fprintf(stderr, "%s: [%s] <%s> %s%s\n", PACKAGE, sessionid,
                        requestid, pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
            else if ((sessionid != NULL) && (sessionid[0] != '\0'))
                fprintf(stderr, "%s: [%s] %s%s\n", PACKAGE, sessionid,
                        pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
            else
                fprintf(stderr, "%s: %s%s\n", PACKAGE,
                        pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
        }
    }
    else
    {
        for (lst = loglist; lst != NULL; lst = lst->next)
        {
            if (pri <= lst->loglevel)
            {
                if (lst->fp == NULL)
                {
                    if ((requestid != NULL) && (requestid[0] != '\0'))
                        syslog(pri, "[%s] <%s> %s%s", sessionid, requestid,
                               pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else if ((sessionid != NULL) && (sessionid[0] != '\0'))
                        syslog(pri, "[%s] %s%s", sessionid,
                               pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else
                        syslog(pri, "%s%s", pri == LOG_DEBUG ? "DEBUG: " : "",
                               buffer);
                }
                else
                {
                    if ((requestid != NULL) && (requestid[0] != '\0'))
                        fprintf(lst->fp, "%s: [%s] <%s> %s%s\n", PACKAGE,
                                sessionid, requestid,
                                pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else if ((sessionid != NULL) && (sessionid[0] != '\0'))
                        fprintf(lst->fp, "%s: [%s] %s%s\n", PACKAGE, sessionid,
                                pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    else
                        fprintf(lst->fp, "%s: %s%s\n", PACKAGE,
                                pri == LOG_DEBUG ? "DEBUG: " : "", buffer);
                    fflush(lst->fp);
                }
            }
        }
    }
}
void log_log ( int pri , const char * format , ... ) { int res ; struct log_cfg * lst ; char buffer [ 200 ] ; va_list ap ; #ifndef TLS char * sessionid , * requestid ; pthread_once ( & tls_init_once , tls_init_keys ) ; sessionid = pthread_getspecific ( sessionid_key ) ; requestid = pthread_getspecific ( requestid_key ) ; #endif va_start ( ap , format ) ; res = vsnprintf ( buffer , sizeof ( buffer ) , format , ap ) ; if ( ( res < 0 ) || ( res >= ( int ) sizeof ( buffer ) ) ) { buffer [ sizeof ( buffer ) - 2 ] = ' ' ; buffer [ sizeof ( buffer ) - 3 ] = ' ' ; buffer [ sizeof ( buffer ) - 4 ] = ' ' ; } buffer [ sizeof ( buffer ) - 1 ] = ' \0 ' ; va_end ( ap ) ; if ( prelogging_loglevel >= 0 ) { if ( pri <= prelogging_loglevel ) { if ( ( requestid != NULL ) && ( requestid [ 0 ] != ' \0 ' ) ) fprintf ( stderr , " \n " , PACKAGE , sessionid , requestid , pri == LOG_DEBUG ? " " : " " , buffer ) ; else if ( ( sessionid != NULL ) && ( sessionid [ 0 ] != ' \0 ' ) ) fprintf ( stderr , " \n " , PACKAGE , sessionid , pri == LOG_DEBUG ? " " : " " , buffer ) ; else fprintf ( stderr , " \n " , PACKAGE , pri == LOG_DEBUG ? " " : " " , buffer ) ; } } else { for ( lst = loglist ; lst != NULL ; lst = lst -> next ) { if ( pri <= lst -> loglevel ) { if ( lst -> fp == NULL ) { if ( ( requestid != NULL ) && ( requestid [ 0 ] != ' \0 ' ) ) syslog ( pri , " " , sessionid , requestid , pri == LOG_DEBUG ? " " : " " , buffer ) ; else if ( ( sessionid != NULL ) && ( sessionid [ 0 ] != ' \0 ' ) ) syslog ( pri , " " , sessionid , pri == LOG_DEBUG ? " " : " " , buffer ) ; else syslog ( pri , " " , pri == LOG_DEBUG ? " " : " " , buffer ) ; } else { if ( ( requestid != NULL ) && ( requestid [ 0 ] != ' \0 ' ) ) fprintf ( lst -> fp , " \n " , PACKAGE , sessionid , requestid , pri == LOG_DEBUG ? " " : " " , buffer ) ; else if ( ( sessionid != NULL ) && ( sessionid [ 0 ] != ' \0 ' ) ) fprintf ( lst -> fp , " \n " , PACKAGE , sessionid , pri == LOG_DEBUG ? " " : " " , buffer ) ; else fprintf ( lst -> fp , " \n " , PACKAGE , pri == LOG_DEBUG ? " " : " " , buffer ) ; fflush ( lst -> fp ) ; } } } } }
log the given message using the configured logging method
log the given message using the configured logging method
/* no TLS */ /* make the message */ /* truncate with "..." */ /* do the logging */ /* if logging is not yet defined, log to stderr */