compat_syslog.c revision 1.1 1 1.1 christos /* $NetBSD: compat_syslog.c,v 1.1 2012/10/10 22:52:26 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.1 christos #include <compat/sys/syslog.h>
41 1.1 christos
42 1.1 christos #ifdef __weak_alias
43 1.1 christos __weak_alias(closelog_r,_closelog_r)
44 1.1 christos __weak_alias(openlog_r,_openlog_r)
45 1.1 christos __weak_alias(setlogmask_r,_setlogmask_r)
46 1.1 christos __weak_alias(syslog_r,_syslog_r)
47 1.1 christos __weak_alias(vsyslog_r,_vsyslog_r)
48 1.1 christos __weak_alias(syslogp_r,_syslogp_r)
49 1.1 christos __weak_alias(vsyslogp_r,_vsyslogp_r)
50 1.1 christos #endif /* __weak_alias */
51 1.1 christos
52 1.1 christos __warn_references(closelog_r,
53 1.1 christos "warning: reference to compatibility closelog_r();"
54 1.1 christos " include <sys/syslog.h> for correct reference")
55 1.1 christos __warn_references(openlog_r,
56 1.1 christos "warning: reference to compatibility openlog_r();"
57 1.1 christos " include <sys/syslog.h> for correct reference")
58 1.1 christos __warn_references(setlogmask_r,
59 1.1 christos "warning: reference to compatibility setlogmask_r();"
60 1.1 christos " include <sys/syslog.h> for correct reference")
61 1.1 christos __warn_references(syslog_r,
62 1.1 christos "warning: reference to compatibility syslog_r();"
63 1.1 christos " include <sys/syslog.h> for correct reference")
64 1.1 christos __warn_references(vsyslog_r,
65 1.1 christos "warning: reference to compatibility vsyslog_r();"
66 1.1 christos " include <sys/syslog.h> for correct reference")
67 1.1 christos __warn_references(syslogp_r,
68 1.1 christos "warning: reference to compatibility syslogp_r();"
69 1.1 christos " include <sys/syslog.h> for correct reference")
70 1.1 christos __warn_references(vsyslogp_r,
71 1.1 christos "warning: reference to compatibility vsyslogp_r();"
72 1.1 christos " include <sys/syslog.h> for correct reference")
73 1.1 christos
74 1.1 christos static void
75 1.1 christos syslog_data_convert(struct syslog_data *d, const struct syslog_data60 *s)
76 1.1 christos {
77 1.1 christos d->log_file = s->log_file;
78 1.1 christos d->log_connected = s->connected;
79 1.1 christos d->log_opened = s->opened;
80 1.1 christos d->log_stat = s->log_stat;
81 1.1 christos d->log_tag = s->log_tag;
82 1.1 christos d->log_fac = s->log_fac;
83 1.1 christos d->log_mask = s->log_mask;
84 1.1 christos }
85 1.1 christos
86 1.1 christos void
87 1.1 christos closelog_r(struct syslog_data60 *data60)
88 1.1 christos {
89 1.1 christos struct syslog_data data = SYSLOG_DATA_INIT;
90 1.1 christos syslog_data_convert(&data, data60);
91 1.1 christos __closelog_r60(&data);
92 1.1 christos }
93 1.1 christos
94 1.1 christos void
95 1.1 christos openlog_r(const char *ident, int logstat, int logfac,
96 1.1 christos struct syslog_data60 *data60)
97 1.1 christos {
98 1.1 christos struct syslog_data data = SYSLOG_DATA_INIT;
99 1.1 christos syslog_data_convert(&data, data60);
100 1.1 christos __openlog_r60(ident, logstat, logfac, &data);
101 1.1 christos }
102 1.1 christos
103 1.1 christos int
104 1.1 christos setlogmask_r(int pmask, struct syslog_data60 *data60)
105 1.1 christos {
106 1.1 christos struct syslog_data data = SYSLOG_DATA_INIT;
107 1.1 christos syslog_data_convert(&data, data60);
108 1.1 christos return __setlogmask_r60(pmask, &data);
109 1.1 christos }
110 1.1 christos
111 1.1 christos void
112 1.1 christos syslog_r(int pri, struct syslog_data60 *data60, const char *fmt, ...)
113 1.1 christos {
114 1.1 christos va_list ap;
115 1.1 christos struct syslog_data data = SYSLOG_DATA_INIT;
116 1.1 christos syslog_data_convert(&data, data60);
117 1.1 christos
118 1.1 christos va_start(ap, fmt);
119 1.1 christos __vsyslog_r60(pri, &data, fmt, ap);
120 1.1 christos va_end(ap);
121 1.1 christos }
122 1.1 christos
123 1.1 christos void
124 1.1 christos vsyslog_r(int pri, struct syslog_data60 *data60, const char *fmt, __va_list ap)
125 1.1 christos {
126 1.1 christos struct syslog_data data = SYSLOG_DATA_INIT;
127 1.1 christos syslog_data_convert(&data, data60);
128 1.1 christos __vsyslog_r60(pri, &data, fmt, ap);
129 1.1 christos }
130 1.1 christos void
131 1.1 christos syslogp_r(int pri, struct syslog_data60 *data60, const char *msgid,
132 1.1 christos const char *sdfmt, const char *msgfmt, ...)
133 1.1 christos {
134 1.1 christos va_list ap;
135 1.1 christos struct syslog_data data = SYSLOG_DATA_INIT;
136 1.1 christos syslog_data_convert(&data, data60);
137 1.1 christos
138 1.1 christos va_start(ap, msgfmt);
139 1.1 christos __vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap);
140 1.1 christos va_end(ap);
141 1.1 christos }
142 1.1 christos
143 1.1 christos void
144 1.1 christos vsyslogp_r(int pri, struct syslog_data60 *data60, const char *msgid,
145 1.1 christos const char *sdfmt, const char *msgfmt, __va_list ap)
146 1.1 christos {
147 1.1 christos struct syslog_data data = SYSLOG_DATA_INIT;
148 1.1 christos syslog_data_convert(&data, data60);
149 1.1 christos
150 1.1 christos __vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap);
151 1.1 christos }
152