Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / lib / libsys / panic.c
blob6b6bbf3e97483a3cf28160981e04df23d46578aa
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 void panic_hook(void);
11 __weak_alias(panic_hook, __panic_hook);
13 void __panic_hook(void)
18 /*===========================================================================*
19 * panic *
20 *===========================================================================*/
21 void panic(const char *fmt, ...)
23 /* Something awful has happened. Panics are caused when an internal
24 * inconsistency is detected, e.g., a programming error or illegal
25 * value of a defined constant.
27 endpoint_t me = NONE;
28 char name[20];
29 int priv_flags;
30 int init_flags;
31 void (*suicide)(void);
32 va_list args;
34 if(sys_whoami(&me, name, sizeof(name), &priv_flags, &init_flags) == OK && me != NONE)
35 printf("%s(%d): panic: ", name, me);
36 else
37 printf("(sys_whoami failed): panic: ");
39 if(fmt) {
40 va_start(args, fmt);
41 vprintf(fmt, args);
42 va_end(args);
43 } else {
44 printf("no message\n");
46 printf("\n");
48 printf("syslib:panic.c: stacktrace: ");
49 util_stacktrace();
51 panic_hook();
53 /* Try exit */
54 _exit(1);
56 /* Try to signal ourself */
57 abort();
59 /* If exiting nicely through PM fails for some reason, try to
60 * commit suicide. E.g., message to PM might fail due to deadlock.
62 suicide = (void (*)(void)) -1;
63 suicide();
65 /* If committing suicide fails for some reason, hang. */
66 for(;;) { }