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. 5 * 6 * Changes: 7 * 21 July 2005: Created (Jorrit N. Herder) 8 */ 9 10 #include "log.h" 11 12 #include <assert.h> 13 14 /*==========================================================================* 15 * do_new_kmess * 16 *==========================================================================*/ 17 void do_new_kmess(void) 18 { 19 /* Notification for a new kernel message. */ 20 static struct kmessages *kmess; /* entire kmess structure */ 21 static char print_buf[_KMESS_BUF_SIZE]; /* copy new message here */ 22 int i, r, next, bytes; 23 static int prev_next = 0; 24 25 kmess = get_minix_kerninfo()->kmessages; 26 27 /* Print only the new part. Determine how many new bytes there are with 28 * help of the current and previous 'next' index. Note that the kernel 29 * buffer is circular. This works fine if less than KMESS_BUF_SIZE bytes 30 * are new data; else we miss % KMESS_BUF_SIZE here. Obtain 'next' only 31 * once, since we are operating on shared memory here. 32 * Check for size being positive, the buffer might as well be emptied! 33 */ 34 next = kmess->km_next; 35 bytes = ((next + _KMESS_BUF_SIZE) - prev_next) % _KMESS_BUF_SIZE; 36 if (bytes > 0) { 37 r= prev_next; /* start at previous old */ 38 i=0; 39 while (bytes > 0) { 40 print_buf[i] = kmess->km_buf[(r%_KMESS_BUF_SIZE)]; 41 bytes --; 42 r ++; 43 i ++; 44 } 45 /* Now terminate the new message and save it in the log. */ 46 print_buf[i] = 0; 47 log_append(print_buf, i); 48 } 49 50 /* Almost done, store 'next' so that we can determine what part of the 51 * kernel messages buffer to print next time a notification arrives. 52 */ 53 prev_next = next; 54 } 55