2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: error.c,v 1.18 2003/04/27 01:17:19 martinea Exp $
30 * error handling common to Amanda programs
37 typedef void (*voidfunc) P((void));
38 static voidfunc onerr[MAXFUNCS] =
39 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
41 int erroutput_type = ERR_INTERACTIVE;
43 static char *pname = "unknown";
45 static void (*logerror) P((char *)) = NULL;
59 void (*f) P((char *));
65 static void output_error_message(msg)
68 /* print and/or log message */
70 if((erroutput_type & ERR_AMANDALOG) != 0 && logerror != NULL) {
74 if(erroutput_type & ERR_SYSLOG) {
76 openlog(get_pname(), LOG_PID, LOG_AUTH);
78 openlog(get_pname(), LOG_PID);
80 syslog(LOG_NOTICE, "%s", msg);
84 if(erroutput_type & ERR_INTERACTIVE) {
85 fprintf(stderr, "%s: %s\n", get_pname(), msg);
90 dbprintf(("%s: %s\n", debug_prefix_time(NULL), msg));
97 * Prints an error message, calls the functions installed via onerror(),
100 printf_arglist_function(void error, const char *, format)
104 char linebuf[STR_SIZE];
107 /* format and output the error message */
109 arglist_start(argp, format);
110 vsnprintf(linebuf, sizeof(linebuf), format, argp);
112 output_error_message(linebuf);
114 /* traverse function list, calling in reverse order */
116 for(i=MAXFUNCS-1; i >= 0; i--) {
117 if(onerr[i] != NULL) (*onerr[i])();
126 * Prints an error message, calls the functions installed via onerror(),
127 * then calls abort() to drop core.
129 printf_arglist_function(void errordump, const char *, format)
133 char linebuf[STR_SIZE];
135 /* format error message */
137 arglist_start(argp, format);
138 vsnprintf(linebuf, sizeof(linebuf), format, argp);
140 output_error_message(linebuf);
142 /* traverse function list, calling in reverse order */
144 for(i=MAXFUNCS-1; i >= 0; i--) {
145 if(onerr[i] != NULL) (*onerr[i])();
148 /* terminate and drop core */
154 void (*errf) P((void));
156 * Register function to be called when error is called. Up to MAXFUNCS
157 * functions can be registered. If there isn't room in the table, onerror
158 * returns -1, otherwise it returns 0.
160 * The resemblance to atexit() is on purpose. I wouldn't need onerror()
161 * if everyone had atexit(). Bummer.
166 for(i=0; i < MAXFUNCS; i++) /* find empty slot */
167 if(onerr[i] == NULL) {
172 return -1; /* full table */