4
* error status reporting functions
11
* Copyright(c) 2001-2006 Cisco Systems, Inc.
12
* All rights reserved.
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions
18
* Redistributions of source code must retain the above copyright
19
* notice, this list of conditions and the following disclaimer.
21
* Redistributions in binary form must reproduce the above
22
* copyright notice, this list of conditions and the following
23
* disclaimer in the documentation and/or other materials provided
24
* with the distribution.
26
* Neither the name of the Cisco Systems, Inc. nor the names of its
27
* contributors may be used to endorse or promote products derived
28
* from this software without specific prior written permission.
30
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41
* OF THE POSSIBILITY OF SUCH DAMAGE.
47
#ifdef ERR_REPORTING_SYSLOG
54
/* err_level reflects the level of errors that are reported */
56
err_reporting_level_t err_level = err_level_none;
58
#ifdef SRTP_KERNEL_LINUX
60
err_reporting_init(char *ident) {
65
#else /* SRTP_KERNEL_LINUX */
67
/* err_file is the FILE to which errors are reported */
69
static FILE *err_file = NULL;
72
err_reporting_init(char *ident) {
73
#ifdef ERR_REPORTING_SYSLOG
74
openlog(ident, LOG_PID, LOG_AUTHPRIV);
78
* Believe it or not, openlog doesn't return an error on failure.
79
* But then, neither does the syslog() call...
82
#ifdef ERR_REPORTING_STDOUT
84
#elif defined(USE_ERR_REPORTING_FILE)
85
/* open file for error reporting */
86
err_file = fopen(ERR_REPORTING_FILE, "w");
88
return err_status_init_fail;
95
err_report(int priority, char *format, ...) {
98
if (priority <= err_level) {
100
va_start(args, format);
101
if (err_file != NULL) {
102
vfprintf(err_file, format, args);
103
/* fprintf(err_file, "\n"); */
105
#ifdef ERR_REPORTING_SYSLOG
106
if (1) { /* FIXME: Make this a runtime option. */
110
case err_level_emergency:
111
syslogpri = LOG_EMERG;
113
case err_level_alert:
114
syslogpri = LOG_ALERT;
116
case err_level_critical:
117
syslogpri = LOG_CRIT;
119
case err_level_error:
122
case err_level_warning:
123
syslogpri = LOG_WARNING;
125
case err_level_notice:
126
syslogpri = LOG_NOTICE;
129
syslogpri = LOG_INFO;
131
case err_level_debug:
134
syslogpri = LOG_DEBUG;
138
vsyslog(syslogpri, format, args);
143
#endif /* SRTP_KERNEL_LINUX */
146
err_reporting_set_level(err_reporting_level_t lvl) {