| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * err.c | |
| 3 * | |
| 4 * error status reporting functions | |
| 5 * | |
| 6 * David A. McGrew | |
| 7 * Cisco Systems, Inc. | |
| 8 */ | |
| 9 /* | |
| 10 * | |
| 11 * Copyright(c) 2001-2006 Cisco Systems, Inc. | |
| 12 * All rights reserved. | |
| 13 * | |
| 14 * Redistribution and use in source and binary forms, with or without | |
| 15 * modification, are permitted provided that the following conditions | |
| 16 * are met: | |
| 17 * | |
| 18 * Redistributions of source code must retain the above copyright | |
| 19 * notice, this list of conditions and the following disclaimer. | |
| 20 * | |
| 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. | |
| 25 * | |
| 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. | |
| 29 * | |
| 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. | |
| 42 * | |
| 43 */ | |
| 44 | |
| 45 #ifdef HAVE_CONFIG_H | |
| 46 #include <config.h> | |
| 47 #endif | |
| 48 | |
| 49 #include "err.h" | |
| 50 | |
| 51 #ifdef ERR_REPORTING_SYSLOG | |
| 52 # ifdef HAVE_SYSLOG_H | |
| 53 # include <syslog.h> | |
| 54 # endif | |
| 55 #endif | |
| 56 | |
| 57 | |
| 58 /* err_level reflects the level of errors that are reported */ | |
| 59 | |
| 60 err_reporting_level_t err_level = err_level_none; | |
| 61 | |
| 62 #ifdef SRTP_KERNEL_LINUX | |
| 63 err_status_t | |
| 64 err_reporting_init(const char *ident) { | |
| 65 | |
| 66 return err_status_ok; | |
| 67 } | |
| 68 | |
| 69 #else /* SRTP_KERNEL_LINUX */ | |
| 70 | |
| 71 /* err_file is the FILE to which errors are reported */ | |
| 72 | |
| 73 static FILE *err_file = NULL; | |
| 74 | |
| 75 err_status_t | |
| 76 err_reporting_init(const char *ident) { | |
| 77 #ifdef ERR_REPORTING_SYSLOG | |
| 78 openlog(ident, LOG_PID, LOG_AUTHPRIV); | |
| 79 #endif | |
| 80 | |
| 81 /* | |
| 82 * Believe it or not, openlog doesn't return an error on failure. | |
| 83 * But then, neither does the syslog() call... | |
| 84 */ | |
| 85 | |
| 86 #ifdef ERR_REPORTING_STDOUT | |
| 87 err_file = stdout; | |
| 88 #elif defined(USE_ERR_REPORTING_FILE) | |
| 89 /* open file for error reporting */ | |
| 90 err_file = fopen(ERR_REPORTING_FILE, "w"); | |
| 91 if (err_file == NULL) | |
| 92 return err_status_init_fail; | |
| 93 #endif | |
| 94 | |
| 95 return err_status_ok; | |
| 96 } | |
| 97 | |
| 98 void | |
| 99 err_report(int priority, const char *format, ...) { | |
| 100 va_list args; | |
| 101 | |
| 102 if (priority <= err_level) { | |
| 103 | |
| 104 va_start(args, format); | |
| 105 if (err_file != NULL) { | |
| 106 vfprintf(err_file, format, args); | |
| 107 /* fprintf(err_file, "\n"); */ | |
| 108 } | |
| 109 #ifdef ERR_REPORTING_SYSLOG | |
| 110 if (1) { /* FIXME: Make this a runtime option. */ | |
| 111 int syslogpri; | |
| 112 | |
| 113 switch (priority) { | |
| 114 case err_level_emergency: | |
| 115 syslogpri = LOG_EMERG; | |
| 116 break; | |
| 117 case err_level_alert: | |
| 118 syslogpri = LOG_ALERT; | |
| 119 break; | |
| 120 case err_level_critical: | |
| 121 syslogpri = LOG_CRIT; | |
| 122 break; | |
| 123 case err_level_error: | |
| 124 syslogpri = LOG_ERR; | |
| 125 break; | |
| 126 case err_level_warning: | |
| 127 syslogpri = LOG_WARNING; | |
| 128 break; | |
| 129 case err_level_notice: | |
| 130 syslogpri = LOG_NOTICE; | |
| 131 break; | |
| 132 case err_level_info: | |
| 133 syslogpri = LOG_INFO; | |
| 134 break; | |
| 135 case err_level_debug: | |
| 136 case err_level_none: | |
| 137 default: | |
| 138 syslogpri = LOG_DEBUG; | |
| 139 break; | |
| 140 } | |
| 141 | |
| 142 vsyslog(syslogpri, format, args); | |
| 143 #endif | |
| 144 va_end(args); | |
| 145 } | |
| 146 } | |
| 147 #endif /* SRTP_KERNEL_LINUX */ | |
| 148 | |
| 149 void | |
| 150 err_reporting_set_level(err_reporting_level_t lvl) { | |
| 151 err_level = lvl; | |
| 152 } | |
| OLD | NEW |