Annotation of embedaddon/dhcp/omapip/errwarn.c, revision 1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>