xref: /netbsd-src/lib/libc/compat/gen/compat_syslog.c (revision ace5b9b5feb0e7608bd2da7a617428d2e1cf8aa3)
1 /*	$NetBSD: compat_syslog.c,v 1.3 2024/01/20 14:52:45 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/include/extern.h>
41 #include <compat/sys/syslog.h>
42 
43 #ifdef __weak_alias
__weak_alias(closelog_r,_closelog_r)44 __weak_alias(closelog_r,_closelog_r)
45 __weak_alias(openlog_r,_openlog_r)
46 __weak_alias(setlogmask_r,_setlogmask_r)
47 __weak_alias(syslog_r,_syslog_r)
48 __weak_alias(vsyslog_r,_vsyslog_r)
49 __weak_alias(syslogp_r,_syslogp_r)
50 __weak_alias(vsyslogp_r,_vsyslogp_r)
51 
52 __weak_alias(syslog_ss,_syslog_ss)
53 __weak_alias(vsyslog_ss,_vsyslog_ss)
54 __weak_alias(syslogp_ss,_syslogp_ss)
55 __weak_alias(vsyslogp_ss,_vsyslogp_ss)
56 #endif /* __weak_alias */
57 
58 __warn_references(closelog_r,
59     "warning: reference to compatibility closelog_r();"
60     " include <sys/syslog.h> for correct reference")
61 __warn_references(openlog_r,
62     "warning: reference to compatibility openlog_r();"
63     " include <sys/syslog.h> for correct reference")
64 __warn_references(setlogmask_r,
65     "warning: reference to compatibility setlogmask_r();"
66     " include <sys/syslog.h> for correct reference")
67 __warn_references(syslog_r,
68     "warning: reference to compatibility syslog_r();"
69     " include <sys/syslog.h> for correct reference")
70 __warn_references(vsyslog_r,
71     "warning: reference to compatibility vsyslog_r();"
72     " include <sys/syslog.h> for correct reference")
73 __warn_references(syslogp_r,
74     "warning: reference to compatibility syslogp_r();"
75     " include <sys/syslog.h> for correct reference")
76 __warn_references(vsyslogp_r,
77     "warning: reference to compatibility vsyslogp_r();"
78     " include <sys/syslog.h> for correct reference")
79 
80 static void
81 syslog_data_convert(struct syslog_data *d, const struct syslog_data60 *s)
82 {
83 	d->log_file = s->log_file;
84 	d->log_connected = s->connected;
85 	d->log_opened = s->opened;
86 	d->log_stat = s->log_stat;
87 	d->log_tag = s->log_tag;
88 	d->log_fac = s->log_fac;
89 	d->log_mask = s->log_mask;
90 }
91 
92 void
closelog_r(struct syslog_data60 * data60)93 closelog_r(struct syslog_data60 *data60)
94 {
95 	struct syslog_data data = SYSLOG_DATA_INIT;
96 	syslog_data_convert(&data, data60);
97 	__closelog_r60(&data);
98 }
99 
100 void
openlog_r(const char * ident,int logstat,int logfac,struct syslog_data60 * data60)101 openlog_r(const char *ident, int logstat, int logfac,
102     struct syslog_data60 *data60)
103 {
104 	struct syslog_data data = SYSLOG_DATA_INIT;
105 	syslog_data_convert(&data, data60);
106 	__openlog_r60(ident, logstat, logfac, &data);
107 }
108 
109 int
setlogmask_r(int pmask,struct syslog_data60 * data60)110 setlogmask_r(int pmask, struct syslog_data60 *data60)
111 {
112 	struct syslog_data data = SYSLOG_DATA_INIT;
113 	syslog_data_convert(&data, data60);
114 	return __setlogmask_r60(pmask, &data);
115 }
116 
117 void
syslog_r(int pri,struct syslog_data60 * data60,const char * fmt,...)118 syslog_r(int pri, struct syslog_data60 *data60, const char *fmt, ...)
119 {
120 	va_list ap;
121 	struct syslog_data data = SYSLOG_DATA_INIT;
122 	syslog_data_convert(&data, data60);
123 
124 	va_start(ap, fmt);
125 	__vsyslog_r60(pri, &data, fmt, ap);
126 	va_end(ap);
127 }
128 
129 void
vsyslog_r(int pri,struct syslog_data60 * data60,const char * fmt,__va_list ap)130 vsyslog_r(int pri, struct syslog_data60 *data60, const char *fmt, __va_list ap)
131 {
132 	struct syslog_data data = SYSLOG_DATA_INIT;
133 	syslog_data_convert(&data, data60);
134 	__vsyslog_r60(pri, &data, fmt, ap);
135 }
136 
137 void
syslogp_r(int pri,struct syslog_data60 * data60,const char * msgid,const char * sdfmt,const char * msgfmt,...)138 syslogp_r(int pri, struct syslog_data60 *data60, const char *msgid,
139     const char *sdfmt, const char *msgfmt, ...)
140 {
141 	va_list ap;
142 	struct syslog_data data = SYSLOG_DATA_INIT;
143 	syslog_data_convert(&data, data60);
144 
145 	va_start(ap, msgfmt);
146 	__vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap);
147 	va_end(ap);
148 }
149 
150 void
vsyslogp_r(int pri,struct syslog_data60 * data60,const char * msgid,const char * sdfmt,const char * msgfmt,__va_list ap)151 vsyslogp_r(int pri, struct syslog_data60 *data60, const char *msgid,
152     const char *sdfmt, const char *msgfmt, __va_list ap)
153 {
154 	struct syslog_data data = SYSLOG_DATA_INIT;
155 	syslog_data_convert(&data, data60);
156 
157 	__vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap);
158 }
159 
160 /*
161  * These are semi-private
162  */
163 #define LOG_SIGNAL_SAFE (int)0x80000000
164 
165 void
syslog_ss(int pri,struct syslog_data60 * data,const char * fmt,...)166 syslog_ss(int pri, struct syslog_data60 *data, const char *fmt, ...)
167 {
168 	va_list ap;
169 
170 	va_start(ap, fmt);
171 	vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap);
172 	va_end(ap);
173 }
174 
175 void
syslogp_ss(int pri,struct syslog_data60 * data,const char * msgid,const char * sdfmt,const char * msgfmt,...)176 syslogp_ss(int pri, struct syslog_data60 *data, const char *msgid,
177     const char *sdfmt, const char *msgfmt, ...)
178 {
179 	va_list ap;
180 
181 	va_start(ap, msgfmt);
182 	vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap);
183 	va_end(ap);
184 }
185 
186 void
vsyslog_ss(int pri,struct syslog_data60 * data,const char * fmt,va_list ap)187 vsyslog_ss(int pri, struct syslog_data60 *data, const char *fmt, va_list ap)
188 {
189 	vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap);
190 }
191 
192 void
vsyslogp_ss(int pri,struct syslog_data60 * data,const char * msgid,const char * sdfmt,const char * msgfmt,va_list ap)193 vsyslogp_ss(int pri, struct syslog_data60 *data, const char *msgid,
194     const char *sdfmt, const char *msgfmt, va_list ap)
195 {
196 	vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap);
197 }
198