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