1 /* $OpenBSD: errwarn.c,v 1.7 2004/05/04 22:23:01 mickey Exp $ */
3 /* Errors and warnings... */
6 * Copyright (c) 1996 The Internet Software Consortium.
8 * Copyright (c) 1995 RadioMail Corporation. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of RadioMail Corporation, the Internet Software
20 * Consortium nor the names of its contributors may be used to endorse
21 * or promote products derived from this software without specific
22 * prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY RADIOMAIL CORPORATION, THE INTERNET
25 * SOFTWARE CONSORTIUM AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL RADIOMAIL CORPORATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 * OF THE POSSIBILITY OF SUCH DAMAGE.
37 * This software was written for RadioMail Corporation by Ted Lemon
38 * under a contract with Vixie Enterprises. Further modifications have
39 * been made for the Internet Software Consortium under a contract
40 * with Vixie Laboratories.
47 static void do_percentm(char *obuf, size_t size, char *ibuf);
49 static char mbuf[1024];
50 static char fbuf[1024];
52 int warnings_occurred;
55 * Log an error message, then exit.
62 do_percentm(fbuf, sizeof(fbuf), fmt);
65 vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
69 syslog(log_priority | LOG_ERR, "%s", mbuf);
72 /* Also log it to stderr? */
74 write(2, mbuf, strlen(mbuf));
78 syslog(LOG_CRIT, "exiting.");
80 fprintf(stderr, "exiting.\n");
87 * Log a warning message...
90 warning(char *fmt, ...)
94 do_percentm(fbuf, sizeof(fbuf), fmt);
97 vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
101 syslog(log_priority | LOG_ERR, "%s", mbuf);
105 write(2, mbuf, strlen(mbuf));
120 do_percentm(fbuf, sizeof(fbuf), fmt);
123 vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
127 syslog(log_priority | LOG_INFO, "%s", mbuf);
131 write(2, mbuf, strlen(mbuf));
139 * Log a debug message...
142 debug(char *fmt, ...)
146 do_percentm(fbuf, sizeof(fbuf), fmt);
149 vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
153 syslog(log_priority | LOG_DEBUG, "%s", mbuf);
157 write(2, mbuf, strlen(mbuf));
165 * Find %m in the input string and substitute an error message string.
168 do_percentm(char *obuf, size_t size, char *ibuf)
175 int saved_errno = errno;
178 * We wouldn't need this mess if printf handled %m, or if
179 * strerror() had been invented before syslog().
181 for (fmt_left = size; (ch = *s); ++s) {
182 if (ch == '%' && s[1] == 'm') {
184 prlen = snprintf(t, fmt_left, "%s",
185 strerror(saved_errno));
186 if (prlen >= fmt_left)
187 prlen = fmt_left - 1;
201 parse_warn(char *fmt, ...)
204 static char spaces[] =
208 do_percentm(mbuf, sizeof(mbuf), fmt);
209 snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf);
211 vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
215 syslog(log_priority | LOG_ERR, "%s", mbuf);
216 syslog(log_priority | LOG_ERR, "%s", token_line);
218 syslog(log_priority | LOG_ERR,
219 "%s^", &spaces[sizeof(spaces) - lexchar]);
223 write(2, mbuf, strlen(mbuf));
225 write(2, token_line, strlen(token_line));
227 write(2, spaces, lexchar - 1);
231 warnings_occurred = 1;