xref: /freebsd/usr.sbin/ypserv/yp_error.c (revision 033af09de113cdcba4b72685dd5311fffb1025c5)
1778c7b1cSBill Paul /*
2778c7b1cSBill Paul  * Copyright (c) 1995
3778c7b1cSBill Paul  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
4778c7b1cSBill Paul  *
5778c7b1cSBill Paul  * Redistribution and use in source and binary forms, with or without
6778c7b1cSBill Paul  * modification, are permitted provided that the following conditions
7778c7b1cSBill Paul  * are met:
8778c7b1cSBill Paul  * 1. Redistributions of source code must retain the above copyright
9778c7b1cSBill Paul  *    notice, this list of conditions and the following disclaimer.
10778c7b1cSBill Paul  * 2. Redistributions in binary form must reproduce the above copyright
11778c7b1cSBill Paul  *    notice, this list of conditions and the following disclaimer in the
12778c7b1cSBill Paul  *    documentation and/or other materials provided with the distribution.
13778c7b1cSBill Paul  * 3. All advertising materials mentioning features or use of this software
14778c7b1cSBill Paul  *    must display the following acknowledgement:
15778c7b1cSBill Paul  *	This product includes software developed by Bill Paul.
16778c7b1cSBill Paul  * 4. Neither the name of the author nor the names of any co-contributors
17778c7b1cSBill Paul  *    may be used to endorse or promote products derived from this software
18778c7b1cSBill Paul  *    without specific prior written permission.
19778c7b1cSBill Paul  *
20778c7b1cSBill Paul  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21778c7b1cSBill Paul  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22778c7b1cSBill Paul  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23778c7b1cSBill Paul  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
24778c7b1cSBill Paul  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25778c7b1cSBill Paul  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26778c7b1cSBill Paul  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27778c7b1cSBill Paul  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28778c7b1cSBill Paul  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29778c7b1cSBill Paul  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30778c7b1cSBill Paul  * SUCH DAMAGE.
31778c7b1cSBill Paul  *
32778c7b1cSBill Paul  */
3398834523SPhilippe Charnier 
34b728350eSDavid E. O'Brien #include <sys/cdefs.h>
35b728350eSDavid E. O'Brien __FBSDID("$FreeBSD$");
3698834523SPhilippe Charnier 
37778c7b1cSBill Paul /*
38778c7b1cSBill Paul  * error logging/reporting facilities
39778c7b1cSBill Paul  * stolen from /usr/libexec/mail.local via ypserv
40778c7b1cSBill Paul  */
41778c7b1cSBill Paul 
42778c7b1cSBill Paul #include <sys/types.h>
43dc584ddbSDag-Erling Smørgrav #include <stdio.h>
44dc584ddbSDag-Erling Smørgrav #include <stdarg.h>
45778c7b1cSBill Paul #include <syslog.h>
462c0643afSKris Kennaway #include "yp_extern.h"
47778c7b1cSBill Paul 
48778c7b1cSBill Paul int debug;
49*033af09dSMarcelo Araujo 
50778c7b1cSBill Paul extern int _rpcpmstart;
51778c7b1cSBill Paul extern char *progname;
52dc584ddbSDag-Erling Smørgrav static void __verr(const char *fmt, va_list ap) __printflike(1, 0);
53778c7b1cSBill Paul 
54*033af09dSMarcelo Araujo static void
55*033af09dSMarcelo Araujo __verr(const char *fmt, va_list ap)
56778c7b1cSBill Paul {
57778c7b1cSBill Paul 	if (debug && !_rpcpmstart) {
58778c7b1cSBill Paul 		fprintf(stderr,"%s: ",progname);
59778c7b1cSBill Paul 		vfprintf(stderr, fmt, ap);
60778c7b1cSBill Paul 		fprintf(stderr, "\n");
61778c7b1cSBill Paul 	} else {
62778c7b1cSBill Paul 		vsyslog(LOG_NOTICE, fmt, ap);
63778c7b1cSBill Paul 	}
64778c7b1cSBill Paul }
65778c7b1cSBill Paul 
66778c7b1cSBill Paul void
67778c7b1cSBill Paul yp_error(const char *fmt, ...)
68778c7b1cSBill Paul {
69778c7b1cSBill Paul 	va_list ap;
70778c7b1cSBill Paul 	va_start(ap, fmt);
71ce5b7be8SBill Paul 	__verr(fmt,ap);
72778c7b1cSBill Paul 	va_end(ap);
73778c7b1cSBill Paul }
74