File: debug.h

package info (click to toggle)
amanda 1%3A3.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,420 kB
  • sloc: ansic: 197,218; perl: 109,331; xml: 16,126; sh: 4,180; makefile: 2,810; awk: 502; lex: 407; yacc: 347; tcl: 118; sql: 19; sed: 16; php: 2
file content (244 lines) | stat: -rw-r--r-- 7,911 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
 * Copyright (c) 1991-1999 University of Maryland at College Park
 * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
 * Copyright (c) 2013-2016 Carbonite, Inc.  All Rights Reserved.
 * All Rights Reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of U.M. not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  U.M. makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Authors: the Amanda Development Team.  Its members are listed in a
 * file named AUTHORS, in the root directory of this distribution.
 */
/*
 * $Id: debug.h 6789 2007-06-18 20:18:52Z dustin $
 *
 * Logging support
 */

/* this file is included from amanda.h; there is no need to include
 * it explicitly in source files. */

#ifndef AMANDA_DEBUG_H
#define AMANDA_DEBUG_H

/*
 * GENERAL LOGGING
 */

/* Amanda uses glib's logging facilities.  See
 *  http://developer.gnome.org/doc/API/2.2/glib/glib-Message-Logging.html
 *
 * Note that log output will go to stderr until debug_open is called.
 *
 * The error levels are assigned as follows:
 *  g_error -- errors that should dump core (will not return)
 *  g_critical -- fatal errors, exiting with exit status in 
 *    error_exit_status() (will not return)
 *  g_warning -- non-fatal problems
 *  g_message -- normal status information
 *  g_info -- helpful extra details, but not verbose
 *  g_debug -- debug messages
 */

/* g_debug was introduced in glib 2.6, so define it here for systems where
 * it is lacking.  g_info doesn't exist even in glib 2.13, but maybe it will
 * be invented soon..
 */

#ifndef g_debug
#define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
#endif

#ifndef g_info
#define g_info(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
#endif

/* Initialize the debugging interface.  This is the "high-level"
 * initialization function; older and lower-level applications can call
 * dbopen() and friends directly.
 *
 * This function sets up debug logging and error-handling according to
 * the current process name, type, and context, as defined in util.
 */
void debug_init(void);

/*
 * ADDITIONAL LOGGING
 */

/* Amanda implements a rudimentary method of distributing log information to
 * arbitrary consumers.  Some consumers are available here, and other modules
 * (e.g., server-src/logfile.c) may implement them, too.
 *
 * If amanda_log_handler has never been called, then the default disposition
 * depends on the application context: amanda_log_stderr is always used, and
 * amanda_log_syslog is used in the 'daemon' context.  The 'scriptutil' context
 * does not do any debug logging.
 */

/* prototype for log-handling functions; these will be called with only a single
 * bit set in the log_level. */
typedef void (amanda_log_handler_t)(GLogLevelFlags log_level, const gchar *message);

/* add an amanda_log_handler_t to the list of handlers */
void add_amanda_log_handler(amanda_log_handler_t *hdlr);

/* log ERROR, CRITICAL, and WARNING messages to syslog */
void amanda_log_syslog(GLogLevelFlags log_level, const gchar *message);

/* log ERROR and CRITICAL to stderr */
void amanda_log_stderr(GLogLevelFlags log_level, const gchar *message);

/* log nothing */
void amanda_log_null(GLogLevelFlags log_level, const gchar *message);

/*
 * FATAL ERROR HANDLING
 */

/* for compatibility; these should eventually be substituted throughout
 * the codebase.  Extra calls to exit() and abort() should be optimized
 * away, and are there only for stupid compilers. */
#define errordump(...) do { g_error(__VA_ARGS__); abort(); } while (0)
#define error(...) do { g_critical(__VA_ARGS__); exit(error_exit_status); } while (0)

/* The process exit status that will be given when error()
 * or errordump() is called.
 */
extern int error_exit_status;

/*
 * DEBUG LOGGING
 */

/* short names */
#define dbopen(a)	debug_open(a)
#define dbreopen(a,b)	debug_reopen(a,b)
#define dbrename(a,b)	debug_rename(a,b)
#define dbclose()	debug_close()
#define dbprintf	debug_printf
#define dbfd()		debug_fd()
#define dbfp()		debug_fp()
#define dbfn()		debug_fn()

/* constants for db(re)open */
#define DBG_SUBDIR_SERVER  "server"
#define DBG_SUBDIR_CLIENT  "client"
#define DBG_SUBDIR_AMANDAD "amandad"

/* Open the debugging log in the given subdirectory.  Once 
 * this function is called, debug logging is available.
 *
 * The debugging file is created in the given subdirectory of the
 * amanda debugging directory, with a filename based on the current
 * process name (from get_pname).
 *
 * @param subdir: subdirectory in which to create the debug file.
 * This is usually one of the DBG_SUBDIR_* constants.  
 */
void	debug_open(char *subdir);

/* Re-open a previously debug_close()d debug file, given by 
 * filename, optionally adding a notation as to why it was
 * reopened.
 *
 * @param file: the filename of the debug file to reopen
 * @param notation: reason for re-opening the file
 */
void	debug_reopen(char *file, char *notation);

/* Rename the debugging logfile into a configuration-specific subdirectory
 * of SUBDIR.  Any existing content of the file will be preserved.
 *
 * @param config: configuration name
 * @param subdir: subdirectory in which to create the debug file.
 */
void	debug_rename(char *config, char *subdir);

/* Flush and close the debugging logfile.  Call this function at application
 * shutdown.
 */
void	debug_close(void);

/* Add a message to the debugging logfile.  A newline is not automatically 
 * added.
 *
 * This function is deprecated in favor of glib's g_debug().
 */
void	debug_printf(const char *format, ...) G_GNUC_PRINTF(1,2);

/* Get the file descriptor for the debug file
 *
 * @returns: the file descriptor
 */
int	debug_fd(void);

/* Get the stdio file handle for the debug file.
 *
 * @returns: the file handle
 */
FILE *	debug_fp(void);

/* Get the pathname of the debug file.
 *
 * The result should not be freed by the caller.
 *
 * @returns: the pathname
 */
char *	debug_fn(void);

/* Use 'dup2' to send stderr output to the debug file.  This is useful
 * when launching other applications, where the stderr of those applications
 * may be necessary for debugging.  It should be called in the child, after
 * the fork().
 */
void debug_dup_stderr_to_debug(void);

/* error() and critical() will print a C stack trace if possible.  Set this to
 * TRUE to avoid this stack trace.  This is used by perl wrappers, for example */
void suppress_error_traceback(void);

/*
 * PROCESS NAME
 */

/*
 * ASSERTIONS
 */

#ifndef SWIG
#ifdef ASSERTIONS

/* Like the standard assert(), but call g_error() to log the result properly */
#define assert(exp)	do {						\
    if (!(exp)) {							\
	g_error(_("assert: %s is false: file %s, line %d"),		\
	   stringize(exp), __FILE__, __LINE__);				\
        g_assert_not_reached();						\
    }									\
} while (0)

#else	/* ASSERTIONS */

#define assert(exp) ((void)0)

#endif	/* ASSERTIONS */
#endif	/* SWIG */

#endif /* AMANDA_DEBUG_H */