2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 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 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: debug.h 6789 2007-06-18 20:18:52Z dustin $
32 /* this file is included from amanda.h; there is no need to include
33 * it explicitly in source files. */
35 #ifndef AMANDA_DEBUG_H
36 #define AMANDA_DEBUG_H
42 /* Amanda uses glib's logging facilities. See
43 * http://developer.gnome.org/doc/API/2.2/glib/glib-Message-Logging.html
45 * Note that log output will go to stderr until debug_open is called.
47 * The error levels are assigned as follows:
48 * g_error -- errors that should dump core (will not return)
49 * g_critical -- fatal errors, exiting with exit status in
50 * error_exit_status() (will not return)
51 * g_warning -- non-fatal problems
52 * g_message -- normal status information
53 * g_info -- helpful extra details, but not verbose
54 * g_debug -- debug messages
56 * g_error and g_critical will respect erroutput_type, potentially
57 * sending the error to the Amanda logfile for this run (see logfile.c).
60 /* g_debug was introduced in glib 2.6, so define it here for systems where
61 * it is lacking. g_info doesn't exist even in glib 2.13, but maybe it will
66 #define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
70 #define g_info(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
74 * FATAL ERROR HANDLING
77 /* for compatibility; these should eventually be substituted throughout
78 * the codebase. Extra calls to exit() and abort() should be optimized
79 * away, and are there only for stupid compilers. */
80 #define errordump(...) do { g_error(__VA_ARGS__); abort(); } while (0)
81 #define error(...) do { g_critical(__VA_ARGS__); exit(error_exit_status); } while (0)
83 /* Additional handling for error and critical messages. */
85 /* send message to stderr (for interactive programs) */
86 ERR_INTERACTIVE = 1 << 0, /* (default) */
91 /* add an L_FATAL entry in the Amanda logfile for the
93 ERR_AMANDALOG = 1 << 2
95 extern erroutput_type_t erroutput_type;
97 /* The process exit status that will be given when error()
98 * or errordump() is called.
100 extern int error_exit_status;
102 /* Supply a pointer to the logfile module's logerror(), if
103 * ERR_AMANDALOG is set.
105 * This function is required because libamanda, which contains
106 * debug.c, is not always linked with the logerror module
107 * (which only appears in server applications).
109 * @param logerror_fn: function pointer
111 void set_logerror(void (*logerror_fn)(char *));
118 #define dbopen(a) debug_open(a)
119 #define dbreopen(a,b) debug_reopen(a,b)
120 #define dbrename(a,b) debug_rename(a,b)
121 #define dbclose() debug_close()
122 #define dbprintf debug_printf
123 #define dbfd() debug_fd()
124 #define dbfp() debug_fp()
125 #define dbfn() debug_fn()
127 /* constants for db(re)open */
128 #define DBG_SUBDIR_SERVER "server"
129 #define DBG_SUBDIR_CLIENT "client"
130 #define DBG_SUBDIR_AMANDAD "amandad"
132 /* Open the debugging log in the given subdirectory. Once
133 * this function is called, debug logging is available.
135 * The debugging file is created in the given subdirectory of the
136 * amanda debugging directory, with a filename based on the current
137 * process name (from get_pname).
139 * @param subdir: subdirectory in which to create the debug file.
140 * This is usually one of the DBG_SUBDIR_* constants.
142 void debug_open(char *subdir);
144 /* Re-open a previously debug_close()d debug file, given by
145 * filename, optionally adding a notation as to why it was
148 * @param file: the filename of the debug file to reopen
149 * @param notation: reason for re-opening the file
151 void debug_reopen(char *file, char *notation);
153 /* Rename the debugging logfile into a configuration-specific subdirectory
154 * of SUBDIR. Any existing content of the file will be preserved.
156 * @param config: configuration name
157 * @param subdir: subdirectory in which to create the debug file.
159 void debug_rename(char *config, char *subdir);
161 /* Flush and close the debugging logfile. Call this function at application
164 void debug_close(void);
166 /* Add a message to the debugging logfile. A newline is not automatically
169 * This function is deprecated in favor of glib's g_debug().
171 void debug_printf(const char *format, ...) G_GNUC_PRINTF(1,2);
173 /* Get the file descriptor for the debug file
175 * @returns: the file descriptor
179 /* Get the stdio file handle for the debug file.
181 * @returns: the file handle
183 FILE * debug_fp(void);
185 /* Get the pathname of the debug file.
187 * The result should not be freed by the caller.
189 * @returns: the pathname
191 char * debug_fn(void);
193 /* Use 'dup2' to send stderr output to the debug file. This is useful
194 * when launching other applications, where the stderr of those applications
195 * may be necessary for debugging. It should be called in the child, after
198 void debug_dup_stderr_to_debug(void);
211 /* Like the standard assert(), but call g_error() to log the result properly */
212 #define assert(exp) do { \
214 g_error(_("assert: %s is false: file %s, line %d"), \
215 stringize(exp), __FILE__, __LINE__); \
216 g_assert_not_reached(); \
220 #else /* ASSERTIONS */
222 #define assert(exp) ((void)0)
224 #endif /* ASSERTIONS */
227 #endif /* AMANDA_DEBUG_H */