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.19 2006/05/25 01:47:11 johnfranks Exp $
30 * error handling common to Amanda programs
37 typedef void (*voidfunc)(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 output_error_message(char *msg);
47 static void (*logerror)(char *) = NULL;
74 /* print and/or log message */
76 if((erroutput_type & ERR_AMANDALOG) != 0 && logerror != NULL) {
80 if(erroutput_type & ERR_SYSLOG) {
82 openlog(get_pname(), LOG_PID, LOG_AUTH);
84 openlog(get_pname(), LOG_PID, 0);
86 syslog(LOG_NOTICE, "%s", msg);
90 if(erroutput_type & ERR_INTERACTIVE) {
91 fprintf(stderr, "%s: %s\n", get_pname(), msg);
96 dbprintf(("%s: %s\n", debug_prefix_time(NULL), msg));
103 * Prints an error message, calls the functions installed via onerror(),
106 printf_arglist_function(void error, const char *, format)
110 char linebuf[STR_SIZE];
113 /* format and output the error message */
115 arglist_start(argp, format);
116 vsnprintf(linebuf, SIZEOF(linebuf), format, argp);
118 output_error_message(linebuf);
120 /* traverse function list, calling in reverse order */
122 for(i=MAXFUNCS-1; i >= 0; i--) {
123 if(onerr[i] != NULL) (*onerr[i])();
132 * Prints an error message, calls the functions installed via onerror(),
133 * then calls abort() to drop core.
135 printf_arglist_function(void errordump, const char *, format)
139 char linebuf[STR_SIZE];
141 /* format error message */
143 arglist_start(argp, format);
144 vsnprintf(linebuf, SIZEOF(linebuf), format, argp);
146 output_error_message(linebuf);
148 /* traverse function list, calling in reverse order */
150 for(i=MAXFUNCS-1; i >= 0; i--) {
151 if(onerr[i] != NULL) (*onerr[i])();
154 /* terminate and drop core */
160 * Register function to be called when error is called. Up to MAXFUNCS
161 * functions can be registered. If there isn't room in the table, onerror
162 * returns -1, otherwise it returns 0.
164 * The resemblance to atexit() is on purpose. I wouldn't need onerror()
165 * if everyone had atexit(). Bummer.
174 for(i=0; i < MAXFUNCS; i++) /* find empty slot */
175 if(onerr[i] == NULL) {
180 return -1; /* full table */