1 /* $NetBSD: compat_syslog.c,v 1.2 2012/10/11 17:09:55 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2012 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include "namespace.h" 33 #include <sys/cdefs.h> 34 35 #define __LIBC12_SOURCE__ 36 #include <stdarg.h> 37 38 #include <sys/types.h> 39 #include <sys/syslog.h> 40 #include <compat/sys/syslog.h> 41 42 void syslog_ss(int, struct syslog_data60 *, const char *, ...) 43 __printflike(3, 4); 44 void vsyslog_ss(int, struct syslog_data60 *, const char *, va_list) 45 __printflike(3, 0); 46 void syslogp_ss(int, struct syslog_data60 *, const char *, const char *, 47 const char *, ...) __printflike(5, 0); 48 void vsyslogp_ss(int, struct syslog_data60 *, const char *, const char *, 49 const char *, va_list) __printflike(5, 0); 50 51 #ifdef __weak_alias 52 __weak_alias(closelog_r,_closelog_r) 53 __weak_alias(openlog_r,_openlog_r) 54 __weak_alias(setlogmask_r,_setlogmask_r) 55 __weak_alias(syslog_r,_syslog_r) 56 __weak_alias(vsyslog_r,_vsyslog_r) 57 __weak_alias(syslogp_r,_syslogp_r) 58 __weak_alias(vsyslogp_r,_vsyslogp_r) 59 60 __weak_alias(syslog_ss,_syslog_ss) 61 __weak_alias(vsyslog_ss,_vsyslog_ss) 62 __weak_alias(syslogp_ss,_syslogp_ss) 63 __weak_alias(vsyslogp_ss,_vsyslogp_ss) 64 #endif /* __weak_alias */ 65 66 __warn_references(closelog_r, 67 "warning: reference to compatibility closelog_r();" 68 " include <sys/syslog.h> for correct reference") 69 __warn_references(openlog_r, 70 "warning: reference to compatibility openlog_r();" 71 " include <sys/syslog.h> for correct reference") 72 __warn_references(setlogmask_r, 73 "warning: reference to compatibility setlogmask_r();" 74 " include <sys/syslog.h> for correct reference") 75 __warn_references(syslog_r, 76 "warning: reference to compatibility syslog_r();" 77 " include <sys/syslog.h> for correct reference") 78 __warn_references(vsyslog_r, 79 "warning: reference to compatibility vsyslog_r();" 80 " include <sys/syslog.h> for correct reference") 81 __warn_references(syslogp_r, 82 "warning: reference to compatibility syslogp_r();" 83 " include <sys/syslog.h> for correct reference") 84 __warn_references(vsyslogp_r, 85 "warning: reference to compatibility vsyslogp_r();" 86 " include <sys/syslog.h> for correct reference") 87 88 static void 89 syslog_data_convert(struct syslog_data *d, const struct syslog_data60 *s) 90 { 91 d->log_file = s->log_file; 92 d->log_connected = s->connected; 93 d->log_opened = s->opened; 94 d->log_stat = s->log_stat; 95 d->log_tag = s->log_tag; 96 d->log_fac = s->log_fac; 97 d->log_mask = s->log_mask; 98 } 99 100 void 101 closelog_r(struct syslog_data60 *data60) 102 { 103 struct syslog_data data = SYSLOG_DATA_INIT; 104 syslog_data_convert(&data, data60); 105 __closelog_r60(&data); 106 } 107 108 void 109 openlog_r(const char *ident, int logstat, int logfac, 110 struct syslog_data60 *data60) 111 { 112 struct syslog_data data = SYSLOG_DATA_INIT; 113 syslog_data_convert(&data, data60); 114 __openlog_r60(ident, logstat, logfac, &data); 115 } 116 117 int 118 setlogmask_r(int pmask, struct syslog_data60 *data60) 119 { 120 struct syslog_data data = SYSLOG_DATA_INIT; 121 syslog_data_convert(&data, data60); 122 return __setlogmask_r60(pmask, &data); 123 } 124 125 void 126 syslog_r(int pri, struct syslog_data60 *data60, const char *fmt, ...) 127 { 128 va_list ap; 129 struct syslog_data data = SYSLOG_DATA_INIT; 130 syslog_data_convert(&data, data60); 131 132 va_start(ap, fmt); 133 __vsyslog_r60(pri, &data, fmt, ap); 134 va_end(ap); 135 } 136 137 void 138 vsyslog_r(int pri, struct syslog_data60 *data60, const char *fmt, __va_list ap) 139 { 140 struct syslog_data data = SYSLOG_DATA_INIT; 141 syslog_data_convert(&data, data60); 142 __vsyslog_r60(pri, &data, fmt, ap); 143 } 144 145 void 146 syslogp_r(int pri, struct syslog_data60 *data60, const char *msgid, 147 const char *sdfmt, const char *msgfmt, ...) 148 { 149 va_list ap; 150 struct syslog_data data = SYSLOG_DATA_INIT; 151 syslog_data_convert(&data, data60); 152 153 va_start(ap, msgfmt); 154 __vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap); 155 va_end(ap); 156 } 157 158 void 159 vsyslogp_r(int pri, struct syslog_data60 *data60, const char *msgid, 160 const char *sdfmt, const char *msgfmt, __va_list ap) 161 { 162 struct syslog_data data = SYSLOG_DATA_INIT; 163 syslog_data_convert(&data, data60); 164 165 __vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap); 166 } 167 168 /* 169 * These are semi-private 170 */ 171 #define LOG_SIGNAL_SAFE (int)0x80000000 172 173 void 174 syslog_ss(int pri, struct syslog_data60 *data, const char *fmt, ...) 175 { 176 va_list ap; 177 178 va_start(ap, fmt); 179 vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap); 180 va_end(ap); 181 } 182 183 void 184 syslogp_ss(int pri, struct syslog_data60 *data, const char *msgid, 185 const char *sdfmt, const char *msgfmt, ...) 186 { 187 va_list ap; 188 189 va_start(ap, msgfmt); 190 vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap); 191 va_end(ap); 192 } 193 194 void 195 vsyslog_ss(int pri, struct syslog_data60 *data, const char *fmt, va_list ap) 196 { 197 vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap); 198 } 199 200 void 201 vsyslogp_ss(int pri, struct syslog_data60 *data, const char *msgid, 202 const char *sdfmt, const char *msgfmt, va_list ap) 203 { 204 vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap); 205 } 206