2011-03-25 11:43:24 +01:00
|
|
|
/* This file handle diagnostic output that is sent to the LOG driver. Output
|
|
|
|
* can be either from the kernel, or from other system processes. Output from
|
|
|
|
* system processes is also routed through the kernel. The kernel notifies
|
|
|
|
* this driver with a SIGKMESS signal if any messages are available.
|
2005-07-21 20:29:52 +02:00
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* 21 July 2005: Created (Jorrit N. Herder)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
2012-07-18 18:53:20 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
extern struct minix_kerninfo *_minix_kerninfo;
|
|
|
|
|
2005-07-21 20:29:52 +02:00
|
|
|
/*==========================================================================*
|
|
|
|
* do_new_kmess *
|
|
|
|
*==========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void do_new_kmess(void)
|
2005-07-21 20:29:52 +02:00
|
|
|
{
|
|
|
|
/* Notification for a new kernel message. */
|
2012-07-18 18:53:20 +02:00
|
|
|
static struct kmessages *kmess; /* entire kmess structure */
|
2008-11-19 13:26:10 +01:00
|
|
|
static char print_buf[_KMESS_BUF_SIZE]; /* copy new message here */
|
2005-07-21 20:29:52 +02:00
|
|
|
int bytes;
|
|
|
|
int i, r;
|
2011-03-25 11:43:24 +01:00
|
|
|
static int prev_next = 0;
|
2006-07-10 14:42:31 +02:00
|
|
|
|
2012-07-18 18:53:20 +02:00
|
|
|
assert(_minix_kerninfo);
|
|
|
|
kmess = _minix_kerninfo->kmessages;
|
2005-07-21 20:29:52 +02:00
|
|
|
|
|
|
|
/* Print only the new part. Determine how many new bytes there are with
|
|
|
|
* help of the current and previous 'next' index. Note that the kernel
|
2011-03-25 11:43:24 +01:00
|
|
|
* buffer is circular. This works fine if less than KMESS_BUF_SIZE bytes
|
|
|
|
* are new data; else we miss % KMESS_BUF_SIZE here.
|
2005-07-21 20:29:52 +02:00
|
|
|
* Check for size being positive, the buffer might as well be emptied!
|
|
|
|
*/
|
2012-07-18 18:53:20 +02:00
|
|
|
if (kmess->km_size > 0) {
|
|
|
|
bytes = ((kmess->km_next + _KMESS_BUF_SIZE) - prev_next) %
|
2008-11-19 13:26:10 +01:00
|
|
|
_KMESS_BUF_SIZE;
|
2011-03-25 11:43:24 +01:00
|
|
|
r= prev_next; /* start at previous old */
|
2005-07-21 20:29:52 +02:00
|
|
|
i=0;
|
|
|
|
while (bytes > 0) {
|
2012-07-18 18:53:20 +02:00
|
|
|
print_buf[i] = kmess->km_buf[(r%_KMESS_BUF_SIZE)];
|
2005-07-21 20:29:52 +02:00
|
|
|
bytes --;
|
|
|
|
r ++;
|
|
|
|
i ++;
|
|
|
|
}
|
2005-10-20 11:29:18 +02:00
|
|
|
/* Now terminate the new message and save it in the log. */
|
2005-07-21 20:29:52 +02:00
|
|
|
print_buf[i] = 0;
|
2005-07-22 20:24:17 +02:00
|
|
|
log_append(print_buf, i);
|
2005-07-21 20:29:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Almost done, store 'next' so that we can determine what part of the
|
|
|
|
* kernel messages buffer to print next time a notification arrives.
|
|
|
|
*/
|
2012-07-18 18:53:20 +02:00
|
|
|
prev_next = kmess->km_next;
|
2005-07-21 20:29:52 +02:00
|
|
|
}
|