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