diff --git a/src/backend.c b/src/backend.c index 391c8a314779450c26e86c4f0770599aecbc9d77..2498fd811ad6293d537dbce2e1d5a1eaca18f230 100644 --- a/src/backend.c +++ b/src/backend.c @@ -184,11 +184,12 @@ void backend() if(SETJMP(back)) { - exit_on_error="Error in handle_error in master object!\nPrevious error:"; + ONERROR tmp; + SET_ONERROR(tmp,exit_on_error,"Error in handle_error in master object!"); assign_svalue_no_free(sp++, & throw_value); APPLY_MASTER("handle_error", 1); pop_stack(); - automatic_fatal=0; + UNSET_ONERROR(tmp); } while(first_object) diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 65a0fd635255d42966e5bc3fed4a743e26b21907..16bffa63f07385b9c87cc3df4c819f7a45fb55a8 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -617,6 +617,7 @@ struct callback *add_exit_callback(callback_func call, void f_exit(INT32 args) { + ONERROR tmp; int i; if(args < 1) error("Too few arguments to exit.\n"); @@ -624,7 +625,7 @@ void f_exit(INT32 args) if(sp[-args].type != T_INT) error("Bad argument 1 to exit.\n"); - exit_on_error="Pike is exiting: "; + SET_ONERROR(tmp,exit_on_error,"Error in handle_error in master object!"); call_callback(&exit_callbacks, (void *)0); free_callback(&exit_callbacks); @@ -634,6 +635,7 @@ void f_exit(INT32 args) exit_modules(); #endif + UNSET_ONERROR(tmp); exit(i); } diff --git a/src/error.c b/src/error.c index b4bd3c5cef7193b1eacbaec6ee56f320d4e9b85b..72493f2b30d838c402f09555132d3c698d7c5104 100644 --- a/src/error.c +++ b/src/error.c @@ -15,7 +15,6 @@ #undef ATTRIBUTE #define ATTRIBUTE(X) -char *automatic_fatal, *exit_on_error; JMP_BUF *recoveries=0; JMP_BUF *init_recovery(JMP_BUF *r) @@ -80,22 +79,13 @@ void va_error(char *fmt, va_list args) ATTRIBUTE((noreturn)) VSPRINTF(buf, fmt, args); - if(automatic_fatal) - { - fprintf(stderr,"%s %s",automatic_fatal,buf); - abort(); - } - - if(exit_on_error || !recoveries) + if(!recoveries) { - if(!exit_on_error) - exit_on_error="No error recovery context: "; - #ifdef DEBUG dump_backlog(); #endif - fprintf(stderr,"%s %s",exit_on_error,buf); + fprintf(stderr,"No error recovery context!\n%s",buf); exit(99); } @@ -113,6 +103,24 @@ void va_error(char *fmt, va_list args) ATTRIBUTE((noreturn)) throw(); /* Hope someone is catching, or we will be out of balls. */ } +void exit_on_error(void *msg) +{ +#ifdef DEBUG + dump_backlog(); +#endif + fprintf(stderr,"%s\n",(char *)msg); + exit(1); +} + +void fatal_on_error(void *msg) +{ +#ifdef DEBUG + dump_backlog(); +#endif + fprintf(stderr,"%s\n",(char *)msg); + abort(); +} + void error(char *fmt,...) ATTRIBUTE((noreturn,format (printf, 1, 2))) { va_list args; diff --git a/src/error.h b/src/error.h index 900a783513cf9c4db429703c9982d5050d42df93..4f137b6e91e257d56164ed91075566b10e50a742 100644 --- a/src/error.h +++ b/src/error.h @@ -41,7 +41,6 @@ typedef struct JMP_BUF extern JMP_BUF *recoveries; extern struct svalue throw_value; -extern char *automatic_fatal, *exit_on_error; #define SETJMP(X) setjmp((init_recovery(&X)->recovery)) #define UNSETJMP(X) recoveries=X.previous; @@ -60,6 +59,8 @@ extern char *automatic_fatal, *exit_on_error; JMP_BUF *init_recovery(JMP_BUF *r); void throw() ATTRIBUTE((noreturn)); void va_error(char *fmt, va_list args) ATTRIBUTE((noreturn)); +void exit_on_error(void *msg); +void fatal_on_error(void *msg); void error(char *fmt,...) ATTRIBUTE((noreturn,format (printf, 1, 2))); void fatal(char *fmt, ...) ATTRIBUTE((noreturn,format (printf, 1, 2))); /* Prototypes end here */ diff --git a/src/main.c b/src/main.c index 16e86ff9fe7d7e2097bc210d4c3e58ea2e4cd9aa..c9db3ad6ace9293e044cb21a7f9dfe741693bd5d 100644 --- a/src/main.c +++ b/src/main.c @@ -225,11 +225,13 @@ void main(int argc, char **argv, char **env) if(SETJMP(back)) { - exit_on_error="Error in handle_error, previous error (in _main): "; + ONERROR tmp; + SET_ONERROR(tmp,exit_on_error,"Error in handle_error in master object!"); assign_svalue_no_free(sp, & throw_value); sp++; APPLY_MASTER("handle_error", 1); pop_stack(); + UNSET_ONERROR(tmp); exit(10); }