kernel - VM PAGER part 1/2 - Remove vm_page_alloc()
[dragonfly.git] / usr.sbin / atm / scspd / scsp_log.c
blobf4463d4e5b41b710d98522cf390d9de1d3181151
1 /*
3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
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.
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.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_log.c,v 1.3 1999/08/28 01:15:33 peter Exp $
27 * @(#) $DragonFly: src/usr.sbin/atm/scspd/scsp_log.c,v 1.3 2003/11/15 20:33:43 eirikn Exp $
32 * Server Cache Synchronization Protocol (SCSP) Support
33 * ----------------------------------------------------
35 * SCSP logging routines
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/port.h>
45 #include <netatm/queue.h>
46 #include <netatm/atm.h>
47 #include <netatm/atm_if.h>
48 #include <netatm/atm_sap.h>
49 #include <netatm/atm_sys.h>
50 #include <netatm/atm_ioctl.h>
52 #include <errno.h>
53 #include <libatm.h>
54 #if __STDC__
55 #include <stdarg.h>
56 #else
57 #include <varargs.h>
58 #endif
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <syslog.h>
63 #include <unistd.h>
65 #include "scsp_msg.h"
66 #include "scsp_if.h"
67 #include "scsp_var.h"
70 * Global variables
72 FILE *scsp_trace_file = NULL;
76 * Write a message to SCSP's log
78 * Arguments:
79 * level pointer to an SCSP cache key structure
80 * fmt printf-style format string
81 * ... parameters for printf-style use according to fmt
83 * Returns:
84 * none
87 void
88 scsp_log(const int level, const char *fmt, ...)
90 va_list ap;
92 va_start(ap, fmt);
95 * In debug mode, just write to stdout
97 if (scsp_debug_mode) {
98 vprintf(fmt, ap);
99 printf("\n");
100 return;
104 * Write to syslog if it's active or if no log file is set up
106 if (scsp_log_syslog || !scsp_log_file) {
107 vsyslog(level, fmt, ap);
111 * Write to the log file if there's one set up
113 if (scsp_log_file) {
114 vfprintf(scsp_log_file, fmt, ap);
115 fprintf(scsp_log_file, "\n");
118 va_end(ap);
123 * Open SCSP's trace file
125 * Arguments:
126 * none
128 * Returns:
129 * none
132 void
133 scsp_open_trace(void)
135 char fname[64];
138 * Build a file name
140 UM_ZERO(fname, sizeof(fname));
141 sprintf(fname, "/tmp/scspd.%d.trace", getpid());
144 * Open the trace file. If the open fails, log an error, but
145 * keep going. The trace routine will notice that the file
146 * isn't open and won't try to write to it.
148 scsp_trace_file = fopen(fname, "w");
149 if (scsp_trace_file == NULL) {
150 scsp_log(LOG_ERR, "Can't open trace file");
156 * Write a message to SCSP's trace file
158 * Arguments:
159 * fmt printf-style format string
160 * ... parameters for printf-style use according to fmt
162 * Returns:
163 * none
166 void
167 scsp_trace(const char *fmt, ...)
169 va_list ap;
171 va_start(ap, fmt);
174 * Write the message to the trace file, if it's open
176 if (scsp_trace_file) {
177 vfprintf(scsp_trace_file, fmt, ap);
180 va_end(ap);
185 * Write an SCSP message to SCSP's trace file
187 * Arguments:
188 * dcsp pointer to DCS block for the message
189 * msg pointer to the message
190 * dir a direction indicator--0 for sending, 1 for receiving
192 * Returns:
193 * none
196 void
197 scsp_trace_msg(Scsp_dcs *dcsp, Scsp_msg *msg, int dir)
199 struct in_addr addr;
202 * Copy the remote IP address into a struct in_addr
204 UM_COPY(dcsp->sd_dcsid.id, &addr.s_addr,
205 sizeof(struct in_addr));
208 * Write the message to the trace file, if it's open
210 if (scsp_trace_file) {
211 scsp_trace("SCSP message at 0x%x %s %s\n",
212 (u_long)msg,
213 (dir ? "received from" : "sent to"),
214 format_ip_addr(&addr));
215 print_scsp_msg(scsp_trace_file, msg);
221 * Log a memory error and exit
223 * Arguments:
224 * cp message to log
226 * Returns:
227 * exits, does not return
230 void
231 scsp_mem_err(char *cp)
233 scsp_log(LOG_CRIT, "out of memory: %s", cp);
234 exit(2);