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