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