]> git.ipfire.org Git - thirdparty/dhcp.git/blob - omapip/errwarn.c
[19430] Unnecessary dot removed.
[thirdparty/dhcp.git] / omapip / errwarn.c
1 /* errwarn.c
2
3 Errors and warnings... */
4
5 /*
6 * Copyright (c) 1995 RadioMail Corporation.
7 * Copyright (c) 2009,2014 by Internet Systems Consortium, Inc. ("ISC")
8 * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 1996-2003 by Internet Software Consortium
10 *
11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Internet Systems Consortium, Inc.
24 * 950 Charter Street
25 * Redwood City, CA 94063
26 * <info@isc.org>
27 * https://www.isc.org/
28 *
29 * This software was written for RadioMail Corporation by Ted Lemon
30 * under a contract with Vixie Enterprises. Further modifications have
31 * been made for Internet Systems Consortium under a contract
32 * with Vixie Laboratories.
33 */
34
35 #include "dhcpd.h"
36
37 #include <omapip/omapip_p.h>
38 #include <errno.h>
39 #include <syslog.h>
40
41 #ifdef DEBUG
42 int log_perror = -1;
43 #else
44 int log_perror = 1;
45 #endif
46 void (*log_cleanup) (void);
47
48 #define CVT_BUF_MAX 1023
49 static char mbuf [CVT_BUF_MAX + 1];
50 static char fbuf [CVT_BUF_MAX + 1];
51
52 /* Log an error message, then exit... */
53
54 void log_fatal (const char * fmt, ... )
55 {
56 va_list list;
57
58 do_percentm (fbuf, fmt);
59
60 /* %Audit% This is log output. %2004.06.17,Safe%
61 * If we truncate we hope the user can get a hint from the log.
62 */
63 va_start (list, fmt);
64 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
65 va_end (list);
66
67 #ifndef DEBUG
68 syslog (LOG_ERR, "%s", mbuf);
69 #endif
70
71 /* Also log it to stderr? */
72 if (log_perror) {
73 IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
74 IGNORE_RET (write (STDERR_FILENO, "\n", 1));
75 }
76
77 log_error ("%s", "");
78 log_error ("If you think you have received this message due to a bug rather");
79 log_error ("than a configuration issue please read the section on submitting");
80 log_error ("bugs on either our web page at www.isc.org or in the README file");
81 log_error ("before submitting a bug. These pages explain the proper");
82 log_error ("process and the information we find helpful for debugging.");
83 log_error ("%s", "");
84 log_error ("exiting.");
85
86 if (log_cleanup)
87 (*log_cleanup) ();
88 exit (1);
89 }
90
91 /* Log an error message... */
92
93 int log_error (const char * fmt, ...)
94 {
95 va_list list;
96
97 do_percentm (fbuf, fmt);
98
99 /* %Audit% This is log output. %2004.06.17,Safe%
100 * If we truncate we hope the user can get a hint from the log.
101 */
102 va_start (list, fmt);
103 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
104 va_end (list);
105
106 #ifndef DEBUG
107 syslog (LOG_ERR, "%s", mbuf);
108 #endif
109
110 if (log_perror) {
111 IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
112 IGNORE_RET (write (STDERR_FILENO, "\n", 1));
113 }
114
115 return 0;
116 }
117
118 /* Log a note... */
119
120 int log_info (const char *fmt, ...)
121 {
122 va_list list;
123
124 do_percentm (fbuf, fmt);
125
126 /* %Audit% This is log output. %2004.06.17,Safe%
127 * If we truncate we hope the user can get a hint from the log.
128 */
129 va_start (list, fmt);
130 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
131 va_end (list);
132
133 #ifndef DEBUG
134 syslog (LOG_INFO, "%s", mbuf);
135 #endif
136
137 if (log_perror) {
138 IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
139 IGNORE_RET (write (STDERR_FILENO, "\n", 1));
140 }
141
142 return 0;
143 }
144
145 /* Log a debug message... */
146
147 int log_debug (const char *fmt, ...)
148 {
149 va_list list;
150
151 do_percentm (fbuf, fmt);
152
153 /* %Audit% This is log output. %2004.06.17,Safe%
154 * If we truncate we hope the user can get a hint from the log.
155 */
156 va_start (list, fmt);
157 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
158 va_end (list);
159
160 #ifndef DEBUG
161 syslog (LOG_DEBUG, "%s", mbuf);
162 #endif
163
164 if (log_perror) {
165 IGNORE_RET (write (STDERR_FILENO, mbuf, strlen (mbuf)));
166 IGNORE_RET (write (STDERR_FILENO, "\n", 1));
167 }
168
169 return 0;
170 }
171
172 /* Find %m in the input string and substitute an error message string. */
173
174 void do_percentm (obuf, ibuf)
175 char *obuf;
176 const char *ibuf;
177 {
178 const char *s = ibuf;
179 char *p = obuf;
180 int infmt = 0;
181 const char *m;
182 int len = 0;
183
184 while (*s) {
185 if (infmt) {
186 if (*s == 'm') {
187 #ifndef __CYGWIN32__
188 m = strerror (errno);
189 #else
190 m = pWSAError ();
191 #endif
192 if (!m)
193 m = "<unknown error>";
194 len += strlen (m);
195 if (len > CVT_BUF_MAX)
196 goto out;
197 strcpy (p - 1, m);
198 p += strlen (p);
199 ++s;
200 } else {
201 if (++len > CVT_BUF_MAX)
202 goto out;
203 *p++ = *s++;
204 }
205 infmt = 0;
206 } else {
207 if (*s == '%')
208 infmt = 1;
209 if (++len > CVT_BUF_MAX)
210 goto out;
211 *p++ = *s++;
212 }
213 }
214 out:
215 *p = 0;
216 }
217
218 #ifdef NO_STRERROR
219 char *strerror (err)
220 int err;
221 {
222 extern char *sys_errlist [];
223 extern int sys_nerr;
224 static char errbuf [128];
225
226 if (err < 0 || err >= sys_nerr) {
227 sprintf (errbuf, "Error %d", err);
228 return errbuf;
229 }
230 return sys_errlist [err];
231 }
232 #endif /* NO_STRERROR */
233
234 #ifdef _WIN32
235 char *pWSAError ()
236 {
237 int err = WSAGetLastError ();
238
239 switch (err)
240 {
241 case WSAEACCES:
242 return "Permission denied";
243 case WSAEADDRINUSE:
244 return "Address already in use";
245 case WSAEADDRNOTAVAIL:
246 return "Cannot assign requested address";
247 case WSAEAFNOSUPPORT:
248 return "Address family not supported by protocol family";
249 case WSAEALREADY:
250 return "Operation already in progress";
251 case WSAECONNABORTED:
252 return "Software caused connection abort";
253 case WSAECONNREFUSED:
254 return "Connection refused";
255 case WSAECONNRESET:
256 return "Connection reset by peer";
257 case WSAEDESTADDRREQ:
258 return "Destination address required";
259 case WSAEFAULT:
260 return "Bad address";
261 case WSAEHOSTDOWN:
262 return "Host is down";
263 case WSAEHOSTUNREACH:
264 return "No route to host";
265 case WSAEINPROGRESS:
266 return "Operation now in progress";
267 case WSAEINTR:
268 return "Interrupted function call";
269 case WSAEINVAL:
270 return "Invalid argument";
271 case WSAEISCONN:
272 return "Socket is already connected";
273 case WSAEMFILE:
274 return "Too many open files";
275 case WSAEMSGSIZE:
276 return "Message too long";
277 case WSAENETDOWN:
278 return "Network is down";
279 case WSAENETRESET:
280 return "Network dropped connection on reset";
281 case WSAENETUNREACH:
282 return "Network is unreachable";
283 case WSAENOBUFS:
284 return "No buffer space available";
285 case WSAENOPROTOOPT:
286 return "Bad protocol option";
287 case WSAENOTCONN:
288 return "Socket is not connected";
289 case WSAENOTSOCK:
290 return "Socket operation on non-socket";
291 case WSAEOPNOTSUPP:
292 return "Operation not supported";
293 case WSAEPFNOSUPPORT:
294 return "Protocol family not supported";
295 case WSAEPROCLIM:
296 return "Too many processes";
297 case WSAEPROTONOSUPPORT:
298 return "Protocol not supported";
299 case WSAEPROTOTYPE:
300 return "Protocol wrong type for socket";
301 case WSAESHUTDOWN:
302 return "Cannot send after socket shutdown";
303 case WSAESOCKTNOSUPPORT:
304 return "Socket type not supported";
305 case WSAETIMEDOUT:
306 return "Connection timed out";
307 case WSAEWOULDBLOCK:
308 return "Resource temporarily unavailable";
309 case WSAHOST_NOT_FOUND:
310 return "Host not found";
311 #if 0
312 case WSA_INVALID_HANDLE:
313 return "Specified event object handle is invalid";
314 case WSA_INVALID_PARAMETER:
315 return "One or more parameters are invalid";
316 case WSAINVALIDPROCTABLE:
317 return "Invalid procedure table from service provider";
318 case WSAINVALIDPROVIDER:
319 return "Invalid service provider version number";
320 case WSA_IO_PENDING:
321 return "Overlapped operations will complete later";
322 case WSA_IO_INCOMPLETE:
323 return "Overlapped I/O event object not in signaled state";
324 case WSA_NOT_ENOUGH_MEMORY:
325 return "Insufficient memory available";
326 #endif
327 case WSANOTINITIALISED:
328 return "Successful WSAStartup not yet performer";
329 case WSANO_DATA:
330 return "Valid name, no data record of requested type";
331 case WSANO_RECOVERY:
332 return "This is a non-recoverable error";
333 #if 0
334 case WSAPROVIDERFAILEDINIT:
335 return "Unable to initialize a service provider";
336 case WSASYSCALLFAILURE:
337 return "System call failure";
338 #endif
339 case WSASYSNOTREADY:
340 return "Network subsystem is unavailable";
341 case WSATRY_AGAIN:
342 return "Non-authoritative host not found";
343 case WSAVERNOTSUPPORTED:
344 return "WINSOCK.DLL version out of range";
345 case WSAEDISCON:
346 return "Graceful shutdown in progress";
347 #if 0
348 case WSA_OPERATION_ABORTED:
349 return "Overlapped operation aborted";
350 #endif
351 }
352 return "Unknown WinSock error";
353 }
354 #endif /* _WIN32 */