cslog(7) CLIX cslog(7)
NAME
cslog - Console log character device
DESCRIPTION
The console log character device (/dev/cslog), major 0, minor 1, allows
user applications to access console messages. This includes messages
printed by the kernel, messages printed by applications, and echoed
keyboard input. The device is a single reader model, so only one process
may have the device open at a time. Console messages can be obtained by
opening and reading the device (with standard library routines). The read
will be blocking by default; however, it may be set to nonblocking during
the open by using the O_NDELAY flag. Blocking reads will sleep until the
highwater mark is reached.
The console messages are placed into a circular buffer. When the buffer
overflows, the least recent characters will be overwritten and a flag is
set to indicate overflow status. Overflow status may be obtained by the
CSLOG_OVERFLOW ioctl (defined in /usr/include/sys/cs.h). The overflow
flag will be cleared by a read.
The default buffer size for the console log is 4096. The highwater mark
for waking up blocking reads is 64 characters. Both of the sizes are
configurable with the UNIXCFG product (setting the cslog_bufs and
cslog_hiwat variables, respectively).
EXAMPLES
This example shows a typical use of the /dev/cslog device.
#include <sys/types.h>
#include <sys/param.h>
#include <sys/errno.h>
#include <sys/file.h>
#include <sys/fcntl.h>
#include <stdio.h>
#include <sys/tty.h> /* dependency in cs.h */
#include <sys/cs.h>
extern int errno;
main(argc, argv)
int argc;
char *argv[];
{
int in, out, bytes, flag;
char buf[4096];
if ((in = open("/dev/cslog", O_RDONLY)) == -1) {
perror("open");
2/94 - Intergraph Corporation 1
cslog(7) CLIX cslog(7)
exit(1);
}
if ((out = open("/tmp/cslog", O_WRONLY|O_CREAT|O_TRUNC)) == -1) {
perror("open");
exit(1);
}
for (;;) {
if (ioctl(in, CSLOG_OVERFLOW, &flag) == -1) {
perror("ioctl");
exit(1);
}
if (flag) {
write(out, "BUFFER OVERFLOW OCCURED\n", 25);
}
if ((bytes = read(in, buf, 4096)) == -1) {
perror("read");
exit(1);
}
if (write(out, buf, bytes) == -1) {
perror("write");
}
}
}
ERRORS
[EWOULDBLOCK]
No data is in the buffer on a non-blocking read.
[EBUSY] The device /dev/cslog is already opened by another process.
[EINTR] A signal was received during the read system call.
[EFAULT] A bad address was passed in to read or ioctl system call.
[EINVAL] A bad ioctl number was passed to the ioctl system call.
[EIO] A write system call was executed. This is not supported.
2 Intergraph Corporation - 2/94