Index: error.c =================================================================== RCS file: /anoncvs/libsmi/lib/error.c,v retrieving revision 1.72 diff -u -r1.72 error.c --- error.c 2001/06/25 13:26:58 1.72 +++ error.c 2001/07/16 17:38:50 @@ -44,6 +44,7 @@ static void smiErrorHandler(char *path, int line, int severity, char *msg, char *tag); static SmiErrorHandler *handler = smiErrorHandler; +static SmiErrorHandler *fatalhandler = NULL; @@ -476,6 +477,29 @@ /* *---------------------------------------------------------------------- * + * smiSetFatalErrorHandler -- + * + * Set the function that is called to handle fatal error messages, + * right before libsmi exits. + * + * Results: + * None. + * + * Side effects: + * Changes the error handler used for subsequent fatal error messages. + * + *---------------------------------------------------------------------- + */ + +void +smiSetFatalErrorHandler(SmiErrorHandler smiErrorHandler) +{ + fatalhandler = smiErrorHandler; +} + +/* + *---------------------------------------------------------------------- + * * smiSetErrorHandler -- * * Set the function that is called to handle error messages. @@ -621,8 +645,8 @@ * None. * * Side effects: - * Terminates the program if the error is severe and there - * is no way to continue. + * Calls the fatal error handler and terminates the program if the + * error is severe and there is no way to continue. * *---------------------------------------------------------------------- */ @@ -668,12 +692,18 @@ /* * A severe error, no way to continue :-( - * - * TODO: Give the application a chance to overwrite the exit() - * call so that it can at least do some cleanup. + * Give the application a chance to do some cleanup. */ if (errors[id].level <= 0) { + if (fatalhandler) { +#ifdef HAVE_VSNPRINTF + vsnprintf(buffer, sizeof(buffer), errors[id].fmt, ap); +#else + vsprintf(buffer, errors[id].fmt, ap); /* buffer overwrite */ +#endif + (fatalhandler) (parser ? parser->path : NULL, line, errors[id].level, buffer, errors[id].tag); + } exit(-1); } }