Home | History | Annotate | Line # | Download | only in altqd
      1  1.6  xtraeme /*	$NetBSD: libaltq2.c,v 1.6 2008/05/02 19:07:44 xtraeme Exp $	*/
      2  1.5   itojun /*	$KAME: libaltq2.c,v 1.6 2002/02/20 10:43:35 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 #include <stdarg.h>
     42  1.4   itojun #include <string.h>
     43  1.1  thorpej 
     44  1.1  thorpej #include "altq_qop.h"
     45  1.1  thorpej 
     46  1.1  thorpej /* from rsvp_main.c */
     47  1.6  xtraeme const char *altqconfigfile = "/etc/altq.conf";
     48  1.1  thorpej 
     49  1.1  thorpej /* from rsvp_global.h */
     50  1.1  thorpej int	if_num;		/* number of phyints */
     51  1.1  thorpej int	m_debug;	/* Debug output control bits */
     52  1.1  thorpej int	l_debug;	/* Logging severity level */
     53  1.1  thorpej 
     54  1.1  thorpej int daemonize = 1;
     55  1.1  thorpej 
     56  1.1  thorpej /* taken from rsvp_debug.c and modified. */
     57  1.1  thorpej void
     58  1.1  thorpej log_write(int severity, int syserr, const char *format, ...)
     59  1.1  thorpej {
     60  1.1  thorpej 	va_list ap;
     61  1.1  thorpej 
     62  1.1  thorpej 	va_start(ap, format);
     63  1.1  thorpej 
     64  1.1  thorpej 	if (severity <= l_debug) {
     65  1.4   itojun 		if (!daemonize) {
     66  1.1  thorpej 			vfprintf(stderr, format, ap);
     67  1.5   itojun 			if (syserr != 0)
     68  1.5   itojun 				fprintf(stderr, ": %s", strerror(syserr));
     69  1.4   itojun 			fprintf(stderr, "\n");
     70  1.4   itojun 		} else {
     71  1.4   itojun 			if (syserr == 0)
     72  1.4   itojun 				vsyslog(severity, format, ap);
     73  1.4   itojun 			else {
     74  1.4   itojun 				char buf[512];
     75  1.4   itojun 
     76  1.4   itojun 				strlcpy(buf, format, sizeof(buf));
     77  1.4   itojun 				strlcat(buf, ": %m", sizeof(buf));
     78  1.4   itojun 				vsyslog(severity, buf, ap);
     79  1.4   itojun 			}
     80  1.4   itojun 		}
     81  1.1  thorpej 	}
     82  1.1  thorpej 
     83  1.1  thorpej 	va_end(ap);
     84  1.1  thorpej }
     85