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