xref: /freebsd/usr.sbin/ypserv/yp_error.c (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
1*df57947fSPedro F. Giffuni /*-
2*df57947fSPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3*df57947fSPedro F. Giffuni  *
4778c7b1cSBill Paul  * Copyright (c) 1995
5778c7b1cSBill Paul  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
6778c7b1cSBill Paul  *
7778c7b1cSBill Paul  * Redistribution and use in source and binary forms, with or without
8778c7b1cSBill Paul  * modification, are permitted provided that the following conditions
9778c7b1cSBill Paul  * are met:
10778c7b1cSBill Paul  * 1. Redistributions of source code must retain the above copyright
11778c7b1cSBill Paul  *    notice, this list of conditions and the following disclaimer.
12778c7b1cSBill Paul  * 2. Redistributions in binary form must reproduce the above copyright
13778c7b1cSBill Paul  *    notice, this list of conditions and the following disclaimer in the
14778c7b1cSBill Paul  *    documentation and/or other materials provided with the distribution.
15778c7b1cSBill Paul  * 3. All advertising materials mentioning features or use of this software
16778c7b1cSBill Paul  *    must display the following acknowledgement:
17778c7b1cSBill Paul  *	This product includes software developed by Bill Paul.
18778c7b1cSBill Paul  * 4. Neither the name of the author nor the names of any co-contributors
19778c7b1cSBill Paul  *    may be used to endorse or promote products derived from this software
20778c7b1cSBill Paul  *    without specific prior written permission.
21778c7b1cSBill Paul  *
22778c7b1cSBill Paul  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23778c7b1cSBill Paul  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24778c7b1cSBill Paul  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25778c7b1cSBill Paul  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
26778c7b1cSBill Paul  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27778c7b1cSBill Paul  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28778c7b1cSBill Paul  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29778c7b1cSBill Paul  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30778c7b1cSBill Paul  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31778c7b1cSBill Paul  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32778c7b1cSBill Paul  * SUCH DAMAGE.
33778c7b1cSBill Paul  *
34778c7b1cSBill Paul  */
3598834523SPhilippe Charnier 
36b728350eSDavid E. O'Brien #include <sys/cdefs.h>
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 extern int _rpcpmstart;
49778c7b1cSBill Paul extern char *progname;
50dc584ddbSDag-Erling Smørgrav static void __verr(const char *fmt, va_list ap) __printflike(1, 0);
51778c7b1cSBill Paul 
52033af09dSMarcelo Araujo static void
__verr(const char * fmt,va_list ap)53033af09dSMarcelo Araujo __verr(const char *fmt, va_list ap)
54778c7b1cSBill Paul {
55778c7b1cSBill Paul 	if (debug && !_rpcpmstart) {
56778c7b1cSBill Paul 		fprintf(stderr,"%s: ",progname);
57778c7b1cSBill Paul 		vfprintf(stderr, fmt, ap);
58778c7b1cSBill Paul 		fprintf(stderr, "\n");
59778c7b1cSBill Paul 	} else {
60778c7b1cSBill Paul 		vsyslog(LOG_NOTICE, fmt, ap);
61778c7b1cSBill Paul 	}
62778c7b1cSBill Paul }
63778c7b1cSBill Paul 
64778c7b1cSBill Paul void
yp_error(const char * fmt,...)65778c7b1cSBill Paul yp_error(const char *fmt, ...)
66778c7b1cSBill Paul {
67778c7b1cSBill Paul 	va_list ap;
68778c7b1cSBill Paul 	va_start(ap, fmt);
69ce5b7be8SBill Paul 	__verr(fmt,ap);
70778c7b1cSBill Paul 	va_end(ap);
71778c7b1cSBill Paul }
72