/*
* This is a sample use of the klogctl kernel function (there is another klogctl else there in glibc, which does something completely different)
* This program gets the size of the available kernel messages, put it in a buffer with the right size, empty the kernel messages, and show messages to stdout*/
#include <stdio.h>
#include <sys/klog.h>
int main(int argc, char **argv, char **envp) {
int ret;
//This call returns the size of the kernel messages
ret=klogctl(9, NULL,0);
char *buf=malloc(ret);
//That one send all messages in "buf" with "ret" as maximum size, and empty the messages
ret=klogctl(4, buf, ret);
//And display the buffer.
printf("%s\n", buf);
perror("klogctl");
return 1;
}