summaryrefslogtreecommitdiff
path: root/usr.sbin/altq/altqd/libaltq2.c
blob: 19bdaf33ced4e04ef36fc1f7b88f455ee4b1d6d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*	$OpenBSD: libaltq2.c,v 1.1 2001/06/27 18:23:17 kjc Exp $	*/
/*
 * this file contains functions and variables needed to use libaltq.
 * since these are defined in rsvpd, they should be separated in order
 * to link libaltq to rsvpd.
 */
#include <sys/param.h>

#include <altq/altq.h>

#include <stdio.h>
#include <errno.h>
#include <syslog.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif

#include "altq_qop.h"

/* from rsvp_main.c */
char *altqconfigfile = "/etc/altq.conf";

/* from rsvp_global.h */
int	if_num;		/* number of phyints */
int	m_debug;	/* Debug output control bits */
int	l_debug;	/* Logging severity level */

int daemonize = 1;

/* taken from rsvp_debug.c and modified. */
void
log_write(int severity, int syserr, const char *format, ...)
{
	va_list ap;

#ifdef __STDC__
	va_start(ap, format);
#else
	va_start(ap);
#endif

	if (severity <= l_debug) {
		if (!daemonize)
			vfprintf(stderr, format, ap);
		else
			vsyslog(severity, format, ap);
	}

	va_end(ap);

	if (syserr == 0) {
		/* Do nothing for now */
	} else if (syserr < sys_nerr) {
		if (severity <= l_debug) {
			if (!daemonize)
				fprintf(stderr, ": %s\n", sys_errlist[syserr]);
			else
				syslog(severity, ": %s", sys_errlist[syserr]);
		}
	} else {
		if (severity <= l_debug) {
			if (!daemonize)
				fprintf(stderr, ": errno %d\n", syserr);
			else
				syslog(severity, ": errno %d", syserr);
		}
	}
}