libaltq2.c revision 1.2 1 /* $KAME: libaltq2.c,v 1.2 2001/08/15 03:38:04 kjc Exp $ */
2 /*
3 * Copyright (C) 1997-2000
4 * Sony Computer Science Laboratories, Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 /*
29 * this file contains functions and variables needed to use libaltq.
30 * since these are defined in rsvpd, they should be separated in order
31 * to link libaltq to rsvpd.
32 */
33 #include <sys/param.h>
34
35 #include <altq/altq.h>
36
37 #include <stdio.h>
38 #include <errno.h>
39 #include <syslog.h>
40 #ifdef __STDC__
41 #include <stdarg.h>
42 #else
43 #include <varargs.h>
44 #endif
45
46 #include "altq_qop.h"
47
48 /* from rsvp_main.c */
49 char *altqconfigfile = "/etc/altq.conf";
50
51 /* from rsvp_global.h */
52 int if_num; /* number of phyints */
53 int m_debug; /* Debug output control bits */
54 int l_debug; /* Logging severity level */
55
56 int daemonize = 1;
57
58 /* taken from rsvp_debug.c and modified. */
59 void
60 log_write(int severity, int syserr, const char *format, ...)
61 {
62 va_list ap;
63
64 #ifdef __STDC__
65 va_start(ap, format);
66 #else
67 va_start(ap);
68 #endif
69
70 if (severity <= l_debug) {
71 if (!daemonize)
72 vfprintf(stderr, format, ap);
73 else
74 vsyslog(severity, format, ap);
75 }
76
77 va_end(ap);
78
79 if (syserr == 0) {
80 /* Do nothing for now */
81 } else if (syserr < sys_nerr) {
82 if (severity <= l_debug) {
83 if (!daemonize)
84 fprintf(stderr, ": %s\n", sys_errlist[syserr]);
85 else
86 syslog(severity, ": %s", sys_errlist[syserr]);
87 }
88 } else {
89 if (severity <= l_debug) {
90 if (!daemonize)
91 fprintf(stderr, ": errno %d\n", syserr);
92 else
93 syslog(severity, ": errno %d", syserr);
94 }
95 }
96 }
97