Home | History | Annotate | Line # | Download | only in altqd
libaltq2.c revision 1.3
      1  1.3   itojun /*	$NetBSD: libaltq2.c,v 1.3 2001/08/16 07:48:09 itojun Exp $	*/
      2  1.2   itojun /*	$KAME: libaltq2.c,v 1.2 2001/08/15 03:38:04 kjc 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.1  thorpej 
     47  1.1  thorpej #include "altq_qop.h"
     48  1.1  thorpej 
     49  1.1  thorpej /* from rsvp_main.c */
     50  1.1  thorpej char *altqconfigfile = "/etc/altq.conf";
     51  1.1  thorpej 
     52  1.1  thorpej /* from rsvp_global.h */
     53  1.1  thorpej int	if_num;		/* number of phyints */
     54  1.1  thorpej int	m_debug;	/* Debug output control bits */
     55  1.1  thorpej int	l_debug;	/* Logging severity level */
     56  1.1  thorpej 
     57  1.1  thorpej int daemonize = 1;
     58  1.1  thorpej 
     59  1.1  thorpej /* taken from rsvp_debug.c and modified. */
     60  1.1  thorpej void
     61  1.1  thorpej log_write(int severity, int syserr, const char *format, ...)
     62  1.1  thorpej {
     63  1.1  thorpej 	va_list ap;
     64  1.1  thorpej 
     65  1.1  thorpej #ifdef __STDC__
     66  1.1  thorpej 	va_start(ap, format);
     67  1.1  thorpej #else
     68  1.1  thorpej 	va_start(ap);
     69  1.1  thorpej #endif
     70  1.1  thorpej 
     71  1.1  thorpej 	if (severity <= l_debug) {
     72  1.1  thorpej 		if (!daemonize)
     73  1.1  thorpej 			vfprintf(stderr, format, ap);
     74  1.1  thorpej 		else
     75  1.1  thorpej 			vsyslog(severity, format, ap);
     76  1.1  thorpej 	}
     77  1.1  thorpej 
     78  1.1  thorpej 	va_end(ap);
     79  1.1  thorpej 
     80  1.1  thorpej 	if (syserr == 0) {
     81  1.1  thorpej 		/* Do nothing for now */
     82  1.1  thorpej 	} else if (syserr < sys_nerr) {
     83  1.1  thorpej 		if (severity <= l_debug) {
     84  1.1  thorpej 			if (!daemonize)
     85  1.1  thorpej 				fprintf(stderr, ": %s\n", sys_errlist[syserr]);
     86  1.1  thorpej 			else
     87  1.1  thorpej 				syslog(severity, ": %s", sys_errlist[syserr]);
     88  1.1  thorpej 		}
     89  1.1  thorpej 	} else {
     90  1.1  thorpej 		if (severity <= l_debug) {
     91  1.1  thorpej 			if (!daemonize)
     92  1.1  thorpej 				fprintf(stderr, ": errno %d\n", syserr);
     93  1.1  thorpej 			else
     94  1.1  thorpej 				syslog(severity, ": errno %d", syserr);
     95  1.1  thorpej 		}
     96  1.1  thorpej 	}
     97  1.1  thorpej }
     98