5
/* diagnostic interface
11
/* void msg_info(format, ...)
12
/* const char *format;
14
/* void msg_warn(format, ...)
15
/* const char *format;
17
/* void msg_error(format, ...)
18
/* const char *format;
20
/* NORETURN msg_fatal(format, ...)
21
/* const char *format;
23
/* NORETURN msg_fatal_status(status, format, ...)
25
/* const char *format;
27
/* NORETURN msg_panic(format, ...)
28
/* const char *format;
30
/* MSG_CLEANUP_FN msg_cleanup(cleanup)
31
/* void (*cleanup)(void);
32
/* AUXILIARY FUNCTIONS
33
/* int msg_error_limit(count)
36
/* void msg_error_clear()
38
/* This module reports diagnostics. By default, diagnostics are sent
39
/* to the standard error stream, but the disposition can be changed
40
/* by the user. See the hints below in the SEE ALSO section.
42
/* msg_info(), msg_warn(), msg_error(), msg_fatal() and msg_panic()
43
/* produce a one-line record with the program name, a severity code
44
/* (except for msg_info()), and an informative message. The program
45
/* name must have been set by calling one of the msg_XXX_init()
46
/* functions (see the SEE ALSO section).
48
/* msg_error() reports a recoverable error and increments the error
49
/* counter. When the error count exceeds a pre-set limit (default: 13)
50
/* the program terminates by calling msg_fatal().
52
/* msg_fatal() reports an unrecoverable error and terminates the program
53
/* with a non-zero exit status.
55
/* msg_fatal_status() reports an unrecoverable error and terminates the
56
/* program with the specified exit status.
58
/* msg_panic() reports an internal inconsistency, terminates the
59
/* program immediately (i.e. without calling the optional user-specified
60
/* cleanup routine), and forces a core dump when possible.
62
/* msg_cleanup() specifies a function that msg_fatal[_status]() should
63
/* invoke before terminating the program, and returns the
64
/* current function pointer. Specify a null argument to disable
67
/* msg_error_limit() sets the error message count limit, and returns.
70
/* msg_error_clear() sets the error message count to zero.
72
/* msg_verbose is a global flag that can be set to make software
73
/* more verbose about what it is doing. By default the flag is zero.
74
/* By convention, a larger value means more noise.
76
/* msg_output(3) specify diagnostics disposition
77
/* msg_stdio(3) direct diagnostics to standard I/O stream
78
/* msg_vstream(3) direct diagnostics to VSTREAM.
79
/* msg_syslog(3) direct diagnostics to syslog daemon
81
/* Some output functions may suffer from intentional or accidental
82
/* record length restrictions that are imposed by library routines
83
/* and/or by the runtime environment.
87
/* The Secure Mailer license must be distributed with this software.
90
/* IBM T.J. Watson Research
92
/* Yorktown Heights, NY 10598, USA
95
/* System libraries. */
102
/* Application-specific. */
105
#include "msg_output.h"
108
* Default is verbose logging off.
113
* Private state. The msg_exiting flag prevents us from recursively
114
* reporting an error.
116
static MSG_CLEANUP_FN msg_cleanup_fn = 0;
117
static int msg_exiting = 0;
118
static int msg_error_count = 0;
119
static int msg_error_bound = 13;
121
/* msg_info - report informative message */
123
void msg_info(const char *fmt,...)
128
msg_vprintf(MSG_INFO, fmt, ap);
132
/* msg_warn - report warning message */
134
void msg_warn(const char *fmt,...)
139
msg_vprintf(MSG_WARN, fmt, ap);
143
/* msg_error - report recoverable error */
145
void msg_error(const char *fmt,...)
150
msg_vprintf(MSG_ERROR, fmt, ap);
152
if (++msg_error_count >= msg_error_bound)
153
msg_fatal("too many errors - program terminated");
156
/* msg_fatal - report error and terminate gracefully */
158
NORETURN msg_fatal(const char *fmt,...)
162
if (msg_exiting++ == 0) {
164
msg_vprintf(MSG_FATAL, fmt, ap);
173
/* msg_fatal_status - report error and terminate gracefully */
175
NORETURN msg_fatal_status(int status, const char *fmt,...)
179
if (msg_exiting++ == 0) {
181
msg_vprintf(MSG_FATAL, fmt, ap);
190
/* msg_panic - report error and dump core */
192
NORETURN msg_panic(const char *fmt,...)
196
if (msg_exiting++ == 0) {
198
msg_vprintf(MSG_PANIC, fmt, ap);
206
/* msg_cleanup - specify cleanup routine */
208
MSG_CLEANUP_FN msg_cleanup(MSG_CLEANUP_FN cleanup_fn)
210
MSG_CLEANUP_FN old_fn = msg_cleanup_fn;
212
msg_cleanup_fn = cleanup_fn;
216
/* msg_error_limit - set error message counter limit */
218
int msg_error_limit(int limit)
220
int old = msg_error_bound;
222
msg_error_bound = limit;
226
/* msg_error_clear - reset error message counter */
228
void msg_error_clear(void)