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