panic() cleanup.
[minix.git] / lib / libsys / panic.c
blob0abab10db2f6c21c1f1be1df4f82fe68c76780f1
1 #include <stdlib.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <stdarg.h>
5 #include <minix/sysutil.h>
7 #include "syslib.h"
9 /*===========================================================================*
10 * panic *
11 *===========================================================================*/
12 PUBLIC void panic(const char *fmt, ...)
14 /* Something awful has happened. Panics are caused when an internal
15 * inconsistency is detected, e.g., a programming error or illegal
16 * value of a defined constant.
18 message m;
19 endpoint_t me = NONE;
20 char name[20];
21 void (*suicide)(void);
22 static int panicing= 0;
23 va_list args;
25 if(panicing) return;
26 panicing= 1;
28 if(sys_whoami(&me, name, sizeof(name)) == OK && me != NONE)
29 printf("%s(%d): panic: ", name, me);
30 else
31 printf("(sys_whoami failed): panic: ");
33 if(fmt) {
34 va_start(args, fmt);
35 vprintf(fmt, args);
36 va_end(fmt);
37 } else {
38 printf("no message\n");
40 printf("\n");
42 printf("syslib:panic.c: stacktrace: ");
43 util_stacktrace();
45 /* Try exit */
46 _exit(1);
48 /* Try to signal ourself */
49 abort();
51 /* If exiting nicely through PM fails for some reason, try to
52 * commit suicide. E.g., message to PM might fail due to deadlock.
54 suicide = (void (*)(void)) -1;
55 suicide();
57 /* If committing suicide fails for some reason, hang. */
58 for(;;) { }