TTY: fix crash obtaining kernel messages
Also fix a case of potential message loss in TTY and LOG.
This commit is contained in:
parent
7f007284e6
commit
71d5865b10
2 changed files with 17 additions and 16 deletions
|
@ -21,8 +21,7 @@ void do_new_kmess(void)
|
||||||
/* Notification for a new kernel message. */
|
/* Notification for a new kernel message. */
|
||||||
static struct kmessages *kmess; /* entire kmess structure */
|
static struct kmessages *kmess; /* entire kmess structure */
|
||||||
static char print_buf[_KMESS_BUF_SIZE]; /* copy new message here */
|
static char print_buf[_KMESS_BUF_SIZE]; /* copy new message here */
|
||||||
int bytes;
|
int i, r, next, bytes;
|
||||||
int i, r;
|
|
||||||
static int prev_next = 0;
|
static int prev_next = 0;
|
||||||
|
|
||||||
assert(_minix_kerninfo);
|
assert(_minix_kerninfo);
|
||||||
|
@ -31,12 +30,13 @@ void do_new_kmess(void)
|
||||||
/* Print only the new part. Determine how many new bytes there are with
|
/* 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
|
* help of the current and previous 'next' index. Note that the kernel
|
||||||
* buffer is circular. This works fine if less than KMESS_BUF_SIZE bytes
|
* buffer is circular. This works fine if less than KMESS_BUF_SIZE bytes
|
||||||
* are new data; else we miss % KMESS_BUF_SIZE here.
|
* are new data; else we miss % KMESS_BUF_SIZE here. Obtain 'next' only
|
||||||
|
* once, since we are operating on shared memory here.
|
||||||
* Check for size being positive, the buffer might as well be emptied!
|
* Check for size being positive, the buffer might as well be emptied!
|
||||||
*/
|
*/
|
||||||
if (kmess->km_size > 0) {
|
next = kmess->km_next;
|
||||||
bytes = ((kmess->km_next + _KMESS_BUF_SIZE) - prev_next) %
|
bytes = ((next + _KMESS_BUF_SIZE) - prev_next) % _KMESS_BUF_SIZE;
|
||||||
_KMESS_BUF_SIZE;
|
if (bytes > 0) {
|
||||||
r= prev_next; /* start at previous old */
|
r= prev_next; /* start at previous old */
|
||||||
i=0;
|
i=0;
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
|
@ -53,5 +53,5 @@ void do_new_kmess(void)
|
||||||
/* Almost done, store 'next' so that we can determine what part of the
|
/* Almost done, store 'next' so that we can determine what part of the
|
||||||
* kernel messages buffer to print next time a notification arrives.
|
* kernel messages buffer to print next time a notification arrives.
|
||||||
*/
|
*/
|
||||||
prev_next = kmess->km_next;
|
prev_next = next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -456,9 +456,9 @@ do_new_kmess(void)
|
||||||
{
|
{
|
||||||
/* Kernel wants to print a new message */
|
/* Kernel wants to print a new message */
|
||||||
struct kmessages *kmess_ptr; /* kmessages structure */
|
struct kmessages *kmess_ptr; /* kmessages structure */
|
||||||
char kernel_buf_copy[2*_KMESS_BUF_SIZE];
|
char kernel_buf_copy[_KMESS_BUF_SIZE];
|
||||||
static int prev_next = 0;
|
static int prev_next = 0;
|
||||||
int bytes, copy, restore = 0;
|
int next, bytes, copy, restore = 0;
|
||||||
tty_t *tp, rtp;
|
tty_t *tp, rtp;
|
||||||
message print_kmsg;
|
message print_kmsg;
|
||||||
|
|
||||||
|
@ -468,14 +468,15 @@ do_new_kmess(void)
|
||||||
/* The kernel buffer is circular; print only the new part. Determine
|
/* The kernel buffer is circular; print only the new part. Determine
|
||||||
* how many new bytes there are with the help of current and
|
* how many new bytes there are with the help of current and
|
||||||
* previous 'next' index. This works fine if less than _KMESS_BUF_SIZE
|
* previous 'next' index. This works fine if less than _KMESS_BUF_SIZE
|
||||||
* bytes is new data; else we miss % _KMESS_BUF_SIZE here.
|
* bytes is new data; else we miss % _KMESS_BUF_SIZE here. Obtain
|
||||||
|
* 'next' only once, since we are operating on shared memory here.
|
||||||
* Check for size being positive; the buffer might as well be emptied!
|
* Check for size being positive; the buffer might as well be emptied!
|
||||||
*/
|
*/
|
||||||
if (kmess_ptr->km_size > 0) {
|
next = kmess_ptr->km_next;
|
||||||
bytes = ((kmess_ptr->km_next + _KMESS_BUF_SIZE) - prev_next) %
|
bytes = ((next + _KMESS_BUF_SIZE) - prev_next) % _KMESS_BUF_SIZE;
|
||||||
_KMESS_BUF_SIZE;
|
if (bytes > 0) {
|
||||||
/* Copy from current position to end of buffer */
|
/* Copy from current position toward end of buffer */
|
||||||
copy = (prev_next + bytes) % _KMESS_BUF_SIZE;
|
copy = MIN(_KMESS_BUF_SIZE - prev_next, bytes);
|
||||||
memcpy(kernel_buf_copy, &kmess_ptr->km_buf[prev_next], copy);
|
memcpy(kernel_buf_copy, &kmess_ptr->km_buf[prev_next], copy);
|
||||||
|
|
||||||
/* Copy remainder from start of buffer */
|
/* Copy remainder from start of buffer */
|
||||||
|
@ -510,7 +511,7 @@ do_new_kmess(void)
|
||||||
/* Store 'next' pointer so that we can determine what part of the
|
/* Store 'next' pointer so that we can determine what part of the
|
||||||
* kernel messages buffer to print next time a notification arrives.
|
* kernel messages buffer to print next time a notification arrives.
|
||||||
*/
|
*/
|
||||||
prev_next = kmess_ptr->km_next;
|
prev_next = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*===========================================================================*
|
/*===========================================================================*
|
||||||
|
|
Loading…
Reference in a new issue