1 /* $NetBSD: errwarn.c,v 1.1.1.3 2014/07/12 11:57:58 spz Exp $ */
4 Errors and warnings... */
7 * Copyright (c) 1995 RadioMail Corporation.
8 * Copyright (c) 2009,2014 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
10 * Copyright (c) 1996-2003 by Internet Software Consortium
12 * Permission to use, copy, modify, and distribute this software for any
13 * purpose with or without fee is hereby granted, provided that the above
14 * copyright notice and this permission notice appear in all copies.
16 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
17 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
19 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
22 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Internet Systems Consortium, Inc.
26 * Redwood City, CA 94063
28 * https://www.isc.org/
30 * This software was written for RadioMail Corporation by Ted Lemon
31 * under a contract with Vixie Enterprises. Further modifications have
32 * been made for Internet Systems Consortium under a contract
33 * with Vixie Laboratories.
36 #include <sys/cdefs.h>
37 __RCSID("$NetBSD: errwarn.c,v 1.1.1.3 2014/07/12 11:57:58 spz Exp $");
41 #include <omapip/omapip_p.h>
51 void (*log_cleanup
) (void);
53 #define CVT_BUF_MAX 1023
54 static char mbuf
[CVT_BUF_MAX
+ 1];
55 static char fbuf
[CVT_BUF_MAX
+ 1];
57 /* Log an error message, then exit... */
59 void log_fatal (const char * fmt
, ... )
63 do_percentm (fbuf
, fmt
);
65 /* %Audit% This is log output. %2004.06.17,Safe%
66 * If we truncate we hope the user can get a hint from the log.
69 vsnprintf (mbuf
, sizeof mbuf
, fbuf
, list
);
73 syslog (log_priority
| LOG_ERR
, "%s", mbuf
);
76 /* Also log it to stderr? */
78 IGNORE_RET (write (STDERR_FILENO
, mbuf
, strlen (mbuf
)));
79 IGNORE_RET (write (STDERR_FILENO
, "\n", 1));
83 log_error ("If you think you have received this message due to a bug rather");
84 log_error ("than a configuration issue please read the section on submitting");
85 log_error ("bugs on either our web page at www.isc.org or in the README file");
86 log_error ("before submitting a bug. These pages explain the proper");
87 log_error ("process and the information we find helpful for debugging..");
89 log_error ("exiting.");
96 /* Log an error message... */
98 int log_error (const char * fmt
, ...)
102 do_percentm (fbuf
, fmt
);
104 /* %Audit% This is log output. %2004.06.17,Safe%
105 * If we truncate we hope the user can get a hint from the log.
107 va_start (list
, fmt
);
108 vsnprintf (mbuf
, sizeof mbuf
, fbuf
, list
);
112 syslog (log_priority
| LOG_ERR
, "%s", mbuf
);
116 IGNORE_RET (write (STDERR_FILENO
, mbuf
, strlen (mbuf
)));
117 IGNORE_RET (write (STDERR_FILENO
, "\n", 1));
125 int log_info (const char *fmt
, ...)
129 do_percentm (fbuf
, fmt
);
131 /* %Audit% This is log output. %2004.06.17,Safe%
132 * If we truncate we hope the user can get a hint from the log.
134 va_start (list
, fmt
);
135 vsnprintf (mbuf
, sizeof mbuf
, fbuf
, list
);
139 syslog (log_priority
| LOG_INFO
, "%s", mbuf
);
143 IGNORE_RET (write (STDERR_FILENO
, mbuf
, strlen (mbuf
)));
144 IGNORE_RET (write (STDERR_FILENO
, "\n", 1));
150 /* Log a debug message... */
152 int log_debug (const char *fmt
, ...)
156 do_percentm (fbuf
, fmt
);
158 /* %Audit% This is log output. %2004.06.17,Safe%
159 * If we truncate we hope the user can get a hint from the log.
161 va_start (list
, fmt
);
162 vsnprintf (mbuf
, sizeof mbuf
, fbuf
, list
);
166 syslog (log_priority
| LOG_DEBUG
, "%s", mbuf
);
170 IGNORE_RET (write (STDERR_FILENO
, mbuf
, strlen (mbuf
)));
171 IGNORE_RET (write (STDERR_FILENO
, "\n", 1));
177 /* Find %m in the input string and substitute an error message string. */
179 void do_percentm (obuf
, ibuf
)
183 const char *s
= ibuf
;
193 m
= strerror (errno
);
198 m
= "<unknown error>";
200 if (len
> CVT_BUF_MAX
)
206 if (++len
> CVT_BUF_MAX
)
214 if (++len
> CVT_BUF_MAX
)
227 extern char *sys_errlist
[];
229 static char errbuf
[128];
231 if (err
< 0 || err
>= sys_nerr
) {
232 sprintf (errbuf
, "Error %d", err
);
235 return sys_errlist
[err
];
237 #endif /* NO_STRERROR */
242 int err
= WSAGetLastError ();
247 return "Permission denied";
249 return "Address already in use";
250 case WSAEADDRNOTAVAIL
:
251 return "Cannot assign requested address";
252 case WSAEAFNOSUPPORT
:
253 return "Address family not supported by protocol family";
255 return "Operation already in progress";
256 case WSAECONNABORTED
:
257 return "Software caused connection abort";
258 case WSAECONNREFUSED
:
259 return "Connection refused";
261 return "Connection reset by peer";
262 case WSAEDESTADDRREQ
:
263 return "Destination address required";
265 return "Bad address";
267 return "Host is down";
268 case WSAEHOSTUNREACH
:
269 return "No route to host";
271 return "Operation now in progress";
273 return "Interrupted function call";
275 return "Invalid argument";
277 return "Socket is already connected";
279 return "Too many open files";
281 return "Message too long";
283 return "Network is down";
285 return "Network dropped connection on reset";
287 return "Network is unreachable";
289 return "No buffer space available";
291 return "Bad protocol option";
293 return "Socket is not connected";
295 return "Socket operation on non-socket";
297 return "Operation not supported";
298 case WSAEPFNOSUPPORT
:
299 return "Protocol family not supported";
301 return "Too many processes";
302 case WSAEPROTONOSUPPORT
:
303 return "Protocol not supported";
305 return "Protocol wrong type for socket";
307 return "Cannot send after socket shutdown";
308 case WSAESOCKTNOSUPPORT
:
309 return "Socket type not supported";
311 return "Connection timed out";
313 return "Resource temporarily unavailable";
314 case WSAHOST_NOT_FOUND
:
315 return "Host not found";
317 case WSA_INVALID_HANDLE
:
318 return "Specified event object handle is invalid";
319 case WSA_INVALID_PARAMETER
:
320 return "One or more parameters are invalid";
321 case WSAINVALIDPROCTABLE
:
322 return "Invalid procedure table from service provider";
323 case WSAINVALIDPROVIDER
:
324 return "Invalid service provider version number";
326 return "Overlapped operations will complete later";
327 case WSA_IO_INCOMPLETE
:
328 return "Overlapped I/O event object not in signaled state";
329 case WSA_NOT_ENOUGH_MEMORY
:
330 return "Insufficient memory available";
332 case WSANOTINITIALISED
:
333 return "Successful WSAStartup not yet performer";
335 return "Valid name, no data record of requested type";
337 return "This is a non-recoverable error";
339 case WSAPROVIDERFAILEDINIT
:
340 return "Unable to initialize a service provider";
341 case WSASYSCALLFAILURE
:
342 return "System call failure";
345 return "Network subsystem is unavailable";
347 return "Non-authoritative host not found";
348 case WSAVERNOTSUPPORTED
:
349 return "WINSOCK.DLL version out of range";
351 return "Graceful shutdown in progress";
353 case WSA_OPERATION_ABORTED
:
354 return "Overlapped operation aborted";
357 return "Unknown WinSock error";