minix/kernel/utility.c
Ben Gras 35a108b911 panic() cleanup.
this change
   - makes panic() variadic, doing full printf() formatting -
     no more NO_NUM, and no more separate printf() statements
     needed to print extra info (or something in hex) before panicing
   - unifies panic() - same panic() name and usage for everyone -
     vm, kernel and rest have different names/syntax currently
     in order to implement their own luxuries, but no longer
   - throws out the 1st argument, to make source less noisy.
     the panic() in syslib retrieves the server name from the kernel
     so it should be clear enough who is panicing; e.g.
         panic("sigaction failed: %d", errno);
     looks like:
         at_wini(73130): panic: sigaction failed: 0
         syslib:panic.c: stacktrace: 0x74dc 0x2025 0x100a
   - throws out report() - printf() is more convenient and powerful
   - harmonizes/fixes the use of panic() - there were a few places
     that used printf-style formatting (didn't work) and newlines
     (messes up the formatting) in panic()
   - throws out a few per-server panic() functions
   - cleans up a tie-in of tty with panic()

merging printf() and panic() statements to be done incrementally.
2010-03-05 15:05:11 +00:00

73 lines
2 KiB
C

/* This file contains a collection of miscellaneous procedures:
* panic: abort MINIX due to a fatal error
* kputc: buffered putc used by kernel printf
*/
#include "kernel.h"
#include "proc.h"
#include <minix/syslib.h>
#include <unistd.h>
#include <stdarg.h>
#include <signal.h>
#include <minix/sys_config.h>
#define ARE_PANICING 0xDEADC0FF
/*===========================================================================*
* panic *
*===========================================================================*/
PUBLIC void panic(const char *fmt, ...)
{
va_list arg;
/* The system has run aground of a fatal kernel error. Terminate execution. */
if (minix_panicing == ARE_PANICING) {
arch_monitor();
}
minix_panicing = ARE_PANICING;
if (fmt != NULL) {
printf("kernel panic: ");
va_start(arg, fmt);
vprintf(fmt, arg);
printf("\n");
}
printf("kernel: ");
util_stacktrace();
/* Abort MINIX. */
minix_shutdown(NULL);
}
/*===========================================================================*
* kputc *
*===========================================================================*/
PUBLIC void kputc(c)
int c; /* character to append */
{
/* Accumulate a single character for a kernel message. Send a notification
* to the output driver if an END_OF_KMESS is encountered.
*/
if (c != END_OF_KMESS) {
if (do_serial_debug) {
if(c == '\n')
ser_putc('\r');
ser_putc(c);
}
kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
if (kmess.km_size < sizeof(kmess.km_buf))
kmess.km_size += 1;
kmess.km_next = (kmess.km_next + 1) % _KMESS_BUF_SIZE;
} else {
int p, outprocs[] = OUTPUT_PROCS_ARRAY;
if(!(minix_panicing || do_serial_debug)) {
for(p = 0; outprocs[p] != NONE; p++) {
if(isokprocn(outprocs[p]) && !isemptyn(outprocs[p])) {
send_sig(outprocs[p], SIGKMESS);
}
}
}
}
return;
}