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