openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/sys-utils/dmesg.c
static ssize_t read_syslog_buffer(struct dmesg_control* ctl, char** buf)
{
    size_t sz;
    int rc = -1;

    if (ctl->bufsize)
    {
        sz = ctl->bufsize + 8;
        *buf = xmalloc(sz * sizeof(char));
        rc = klogctl(ctl->action, *buf, sz);
    }
    else
    {
        sz = 16392;
        while (1)
        {
            *buf = xmalloc(sz * sizeof(char));
            rc = klogctl(SYSLOG_ACTION_READ_ALL, *buf, sz);
            if (rc < 0)
                break;
            if ((size_t)rc != sz || sz > (1 << 28))
                break;
            free(*buf);
            *buf = NULL;
            sz *= 4;
        }

        if (rc > 0 && ctl->action == SYSLOG_ACTION_READ_CLEAR)
            rc = klogctl(SYSLOG_ACTION_READ_CLEAR, *buf, sz);
    }

    return rc;
}
/*
 * Reads messages from kernel ring buffer by klogctl()
 */
Reads messages from kernel ring buffer by klogctl()
Reads messages from kernel ring buffer by klogctl ()
static ssize_t read_syslog_buffer(struct dmesg_control* ctl, char** buf)
{
    size_t sz;
    int rc = -1;
    if (ctl->bufsize)
    {
        sz = ctl->bufsize + 8;
        *buf = xmalloc(sz * sizeof(char));
        rc = klogctl(ctl->action, *buf, sz);
    }
    else
    {
        sz = 16392;
        while (1)
        {
            *buf = xmalloc(sz * sizeof(char));
            rc = klogctl(SYSLOG_ACTION_READ_ALL, *buf, sz);
            if (rc < 0)
                break;
            if ((size_t)rc != sz || sz > (1 << 28))
                break;
            free(*buf);
            *buf = NULL;
            sz *= 4;
        }
        if (rc > 0 && ctl->action == SYSLOG_ACTION_READ_CLEAR)
            rc = klogctl(SYSLOG_ACTION_READ_CLEAR, *buf, sz);
    }
    return rc;
}
static ssize_t read_syslog_buffer ( struct dmesg_control * ctl , char * * buf ) { size_t sz ; int rc = -1 ; if ( ctl -> bufsize ) { sz = ctl -> bufsize + 8 ; * buf = xmalloc ( sz * sizeof ( char ) ) ; rc = klogctl ( ctl -> action , * buf , sz ) ; } else { sz = 16392 ; while ( 1 ) { * buf = xmalloc ( sz * sizeof ( char ) ) ; rc = klogctl ( SYSLOG_ACTION_READ_ALL , * buf , sz ) ; if ( rc < 0 ) break ; if ( ( size_t ) rc != sz || sz > ( 1 << 28 ) ) break ; free ( * buf ) ; * buf = NULL ; sz *= 4 ; } if ( rc > 0 && ctl -> action == SYSLOG_ACTION_READ_CLEAR ) rc = klogctl ( SYSLOG_ACTION_READ_CLEAR , * buf , sz ) ; } return rc ; }
Reads messages from kernel ring buffer by klogctl()
Reads messages from kernel ring buffer by klogctl ()