2 * Prototypes for message and error reporting (possibly fatal).
4 * The canonical version of this file is maintained in the rra-c-util package,
5 * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
7 * Copyright 2008, 2010, 2013
8 * The Board of Trustees of the Leland Stanford Junior University
9 * Copyright (c) 2004, 2005, 2006
10 * by Internet Systems Consortium, Inc. ("ISC")
11 * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
12 * 2002, 2003 by The Internet Software Consortium and Rich Salz
14 * This code is derived from software contributed to the Internet Software
15 * Consortium by Rich Salz.
17 * Permission to use, copy, modify, and distribute this software for any
18 * purpose with or without fee is hereby granted, provided that the above
19 * copyright notice and this permission notice appear in all copies.
21 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
22 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
24 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
26 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27 * PERFORMANCE OF THIS SOFTWARE.
30 #ifndef UTIL_MESSAGES_H
31 #define UTIL_MESSAGES_H 1
34 #include <portable/macros.h>
41 /* Default to a hidden visibility for all util functions. */
42 #pragma GCC visibility push(hidden)
45 * The reporting functions. The ones prefaced by "sys" add a colon, a space,
46 * and the results of strerror(errno) to the output and are intended for
47 * reporting failures of system calls.
49 void debug(const char *, ...)
50 __attribute__((__nonnull__, __format__(printf, 1, 2)));
51 void notice(const char *, ...)
52 __attribute__((__nonnull__, __format__(printf, 1, 2)));
53 void sysnotice(const char *, ...)
54 __attribute__((__nonnull__, __format__(printf, 1, 2)));
55 void warn(const char *, ...)
56 __attribute__((__nonnull__, __format__(printf, 1, 2)));
57 void syswarn(const char *, ...)
58 __attribute__((__nonnull__, __format__(printf, 1, 2)));
59 void die(const char *, ...)
60 __attribute__((__nonnull__, __noreturn__, __format__(printf, 1, 2)));
61 void sysdie(const char *, ...)
62 __attribute__((__nonnull__, __noreturn__, __format__(printf, 1, 2)));
65 * Set the handlers for various message functions. All of these functions
66 * take a count of the number of handlers and then function pointers for each
67 * of those handlers. These functions are not thread-safe; they set global
70 void message_handlers_debug(unsigned int count, ...);
71 void message_handlers_notice(unsigned int count, ...);
72 void message_handlers_warn(unsigned int count, ...);
73 void message_handlers_die(unsigned int count, ...);
76 * Some useful handlers, intended to be passed to message_handlers_*. All
77 * handlers take the length of the formatted message, the format, a variadic
78 * argument list, and the errno setting if any.
80 void message_log_stdout(size_t, const char *, va_list, int)
81 __attribute__((__nonnull__));
82 void message_log_stderr(size_t, const char *, va_list, int)
83 __attribute__((__nonnull__));
84 void message_log_syslog_debug(size_t, const char *, va_list, int)
85 __attribute__((__nonnull__));
86 void message_log_syslog_info(size_t, const char *, va_list, int)
87 __attribute__((__nonnull__));
88 void message_log_syslog_notice(size_t, const char *, va_list, int)
89 __attribute__((__nonnull__));
90 void message_log_syslog_warning(size_t, const char *, va_list, int)
91 __attribute__((__nonnull__));
92 void message_log_syslog_err(size_t, const char *, va_list, int)
93 __attribute__((__nonnull__));
94 void message_log_syslog_crit(size_t, const char *, va_list, int)
95 __attribute__((__nonnull__));
97 /* The type of a message handler. */
98 typedef void (*message_handler_func)(size_t, const char *, va_list, int);
100 /* If non-NULL, called before exit and its return value passed to exit. */
101 extern int (*message_fatal_cleanup)(void);
104 * If non-NULL, prepended (followed by ": ") to all messages printed by either
105 * message_log_stdout or message_log_stderr.
107 extern const char *message_program_name;
109 /* Undo default visibility change. */
110 #pragma GCC visibility pop
114 #endif /* UTIL_MESSAGES_H */