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