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