Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / atm / atmarpd / atmarp_log.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/usr.sbin/atm/atmarpd/atmarp_log.c,v 1.3 1999/08/28 01:15:30 peter Exp $
27  *
28  */
29
30
31 /*
32  * Server Cache Synchronization Protocol (SCSP) Support
33  * ----------------------------------------------------
34  *
35  * SCSP-ATMARP server interface: logging routines
36  *
37  */
38
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/socket.h>
42 #include <net/if.h>
43 #include <netinet/in.h>
44 #include <netatm/queue.h>
45 #include <netatm/atm.h>
46 #include <netatm/atm_if.h>
47 #include <netatm/atm_sap.h>
48 #include <netatm/atm_sys.h>
49 #include <netatm/atm_ioctl.h>
50  
51 #include <errno.h>
52 #include <libatm.h>
53 #if __STDC__
54 #include <stdarg.h>
55 #else
56 #include <varargs.h>
57 #endif
58 #include <stdio.h>
59 #include <syslog.h>
60
61 #include "../scspd/scsp_msg.h"
62 #include "../scspd/scsp_if.h"
63 #include "../scspd/scsp_var.h"
64 #include "atmarp_var.h"
65
66 #ifndef lint
67 __RCSID("@(#) $FreeBSD: src/usr.sbin/atm/atmarpd/atmarp_log.c,v 1.3 1999/08/28 01:15:30 peter Exp $");
68 #endif
69
70
71 /*
72  * Write a message to atmarpd's log
73  *
74  * Arguments:
75  *      level   the level (error, info, etc.) of the message
76  *      fmt     printf-style format string
77  *      ...     parameters for printf-style use according to fmt
78  *
79  * Returns:
80  *      none
81  *
82  */
83 void
84 #if __STDC__
85 atmarp_log(const int level, const char *fmt, ...)
86 #else
87 atmarp_log(level, fmt, va_alist)
88         int     level;
89         char    *fmt;
90         va_dcl
91 #endif
92 {
93         va_list ap;
94
95 #if __STDC__
96         va_start(ap, fmt);
97 #else
98         va_start(ap);
99 #endif
100
101         /*
102          * In debug mode, just write to stdout
103          */
104         if (atmarp_debug_mode) {
105                 vprintf(fmt, ap);
106                 printf("\n");
107                 return;
108         }
109
110         /*
111          * Check whether we have a log file set up
112          */
113         if (!atmarp_log_file) {
114                 /*
115                  * Write to syslog
116                  */
117                 vsyslog(level, fmt, ap);
118         } else {
119                 /*
120                  * Write to the log file
121                  */
122                 vfprintf(atmarp_log_file, fmt, ap);
123                 fprintf(atmarp_log_file, "\n");
124         }
125
126         va_end(ap);
127 }
128
129
130 /*
131  * Log a memory error and exit
132  *
133  * Arguments:
134  *      cp      message to log
135  *
136  * Returns:
137  *      exits, does not return
138  *
139  */
140 void
141 atmarp_mem_err(cp)
142         char    *cp;
143 {
144         atmarp_log(LOG_CRIT, "out of memory: %s", cp);
145         exit(2);
146 }