From 86bb84d57695fbe94455259014edeb5aacec13f4 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 26 Jan 2018 17:13:00 +0000 Subject: [PATCH] Split panic routine Split panic routine so that the 'Hit Any Key to continue' behavior can be overriden. Sponsored by: Netflix --- stand/i386/gptboot/gptboot.c | 2 +- stand/libsa/panic.c | 19 +++++++++++++------ stand/libsa/stand.h | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/stand/i386/gptboot/gptboot.c b/stand/i386/gptboot/gptboot.c index 49c2d5f82c54..40fa00e59279 100644 --- a/stand/i386/gptboot/gptboot.c +++ b/stand/i386/gptboot/gptboot.c @@ -102,7 +102,6 @@ static struct bios_smap smap; static char *heap_next; static char *heap_end; -void exit(int); static void load(void); static int parse_cmds(char *, int *); static int dskread(void *, daddr_t, unsigned); @@ -365,6 +364,7 @@ main(void) void exit(int x) { + while (1); } static void diff --git a/stand/libsa/panic.c b/stand/libsa/panic.c index 6e4c76d0e031..bc6e7e2aca5a 100644 --- a/stand/libsa/panic.c +++ b/stand/libsa/panic.c @@ -39,7 +39,18 @@ __FBSDID("$FreeBSD$"); #include #include -extern void exit(int) __dead2; +/* + * Boot loaders and other standalone programs that wish to have a + * different panic policy can provide their own panic_action rotuine. + */ +__weak_symbol void +panic_action(void) +{ + printf("--> Press a key on the console to reboot <--\n"); + getchar(); + printf("Rebooting...\n"); + exit(1); +} void panic(const char *fmt,...) @@ -51,9 +62,5 @@ panic(const char *fmt,...) vprintf(fmt, ap); va_end(ap); printf("\n"); - - printf("--> Press a key on the console to reboot <--\n"); - getchar(); - printf("Rebooting...\n"); - exit(1); + panic_action(); } diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h index c867f7a05635..7c93f83af56b 100644 --- a/stand/libsa/stand.h +++ b/stand/libsa/stand.h @@ -368,7 +368,6 @@ static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); } static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); } static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); } - /* null functions for device/filesystem switches (undocumented) */ extern int nodev(void); extern int noioctl(struct open_file *, u_long, void *); @@ -387,13 +386,14 @@ extern int null_readdir(struct open_file *f, struct dirent *d); * Machine dependent functions and data, must be provided or stubbed by * the consumer */ -extern void exit(int); +extern void exit(int) __dead2; extern int getchar(void); extern int ischar(void); extern void putchar(int); extern int devopen(struct open_file *, const char *, const char **); extern int devclose(struct open_file *f); extern void panic(const char *, ...) __dead2 __printflike(1, 2); +extern void panic_action(void) __weak_symbol __dead2; extern time_t getsecs(void); extern struct fs_ops *file_system[]; extern struct fs_ops *exclusive_file_system;