Subject: Re: kernel panic messages
To: NetBSD Kernel Technical Discussion List <tech-kern@netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: tech-kern
Date: 05/04/2003 17:35:47
[ On Sunday, May 4, 2003 at 22:37:38 (+0200), Ian Piumarta wrote: ]
> Subject: Re: kernel panic messages
>
> On Sun, 4 May 2003, Greg A. Woods wrote:
> 
> > 	#define panic(varags)	{ _panic_setup(__FILE__, __LINE__); _panic varargs; }
> > 	panic(("help! %s", message));
> 
> I used to do error messages like that until I got fed up of typing all
> those parens.  These days I prefer something like this...

There's nothing wrong with a few (extra) parens!  You should just do
some (more) lisp programming and get used to it!  ;-)

> #include <stdio.h>
> #include <stdarg.h>
> 
> const char   *_panic_file= 0;
> unsigned int  _panic_line= 0;
> 
> void _panic(const char *fmt, ...)
> {
>   va_list ap;
>   va_start(ap, fmt);
>   printf("%s:%d: ", _panic_file, _panic_line);
>   vprintf(fmt, ap);
>   printf("\n");
>   va_end(ap);
> }
> 
> #define panic	(_panic_file= __FILE__, _panic_line= __LINE__, _panic)
> 
> int main()
> {
>   panic("help! %d", 42);
>   return 0;
> }
> 
> 
> ...which (ANSI prototypes notwithstanding) works with even the most
> ancient of C compilers.

Hmmm....  Cute trick.  I never thought of using a function value in a
sequential evaluation expression like that.  :-)

Also I prefer not to use globals like that, but it may be OK for the
kernel, assuming there's some way to prevent more than one CPU from
panicing at the same time, or at least handle it gracefully.

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>