testsh2.sh: change output to new cksum util
[minix.git] / drivers / log / diag.c
blobac7841ba4e9ebec89c3e3bdeb7879ef035678043
1 /* This file handle diagnostic output that is sent to the LOG driver. Output
2 * can be either from the kernel, or from other system processes. Output from
3 * system processes is also routed through the kernel. The kernel notifies
4 * this driver with a SIGKMESS signal if any messages are available.
6 * Changes:
7 * 21 July 2005: Created (Jorrit N. Herder)
8 */
10 #include "log.h"
12 #include <assert.h>
14 extern struct minix_kerninfo *_minix_kerninfo;
16 /*==========================================================================*
17 * do_new_kmess *
18 *==========================================================================*/
19 void do_new_kmess(void)
21 /* Notification for a new kernel message. */
22 static struct kmessages *kmess; /* entire kmess structure */
23 static char print_buf[_KMESS_BUF_SIZE]; /* copy new message here */
24 int bytes;
25 int i, r;
26 static int prev_next = 0;
28 assert(_minix_kerninfo);
29 kmess = _minix_kerninfo->kmessages;
31 /* Print only the new part. Determine how many new bytes there are with
32 * help of the current and previous 'next' index. Note that the kernel
33 * buffer is circular. This works fine if less than KMESS_BUF_SIZE bytes
34 * are new data; else we miss % KMESS_BUF_SIZE here.
35 * Check for size being positive, the buffer might as well be emptied!
37 if (kmess->km_size > 0) {
38 bytes = ((kmess->km_next + _KMESS_BUF_SIZE) - prev_next) %
39 _KMESS_BUF_SIZE;
40 r= prev_next; /* start at previous old */
41 i=0;
42 while (bytes > 0) {
43 print_buf[i] = kmess->km_buf[(r%_KMESS_BUF_SIZE)];
44 bytes --;
45 r ++;
46 i ++;
48 /* Now terminate the new message and save it in the log. */
49 print_buf[i] = 0;
50 log_append(print_buf, i);
53 /* Almost done, store 'next' so that we can determine what part of the
54 * kernel messages buffer to print next time a notification arrives.
56 prev_next = kmess->km_next;