1 const char errlog_rcs[] = "$Id: errlog.c,v 1.42 2006/07/18 14:48:46 david__schmidt Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
6 * Purpose : Log errors to a designated destination in an elegant,
9 * Copyright : Written by and Copyright (C) 2001 the SourceForge
10 * Privoxy team. http://www.privoxy.org/
12 * Based on the Internet Junkbuster originally written
13 * by and Copyright (C) 1997 Anonymous Coders and
14 * Junkbusters Corporation. http://www.junkbusters.com
16 * This program is free software; you can redistribute it
17 * and/or modify it under the terms of the GNU General
18 * Public License as published by the Free Software
19 * Foundation; either version 2 of the License, or (at
20 * your option) any later version.
22 * This program is distributed in the hope that it will
23 * be useful, but WITHOUT ANY WARRANTY; without even the
24 * implied warranty of MERCHANTABILITY or FITNESS FOR A
25 * PARTICULAR PURPOSE. See the GNU General Public
26 * License for more details.
28 * The GNU General Public License should be included with
29 * this file. If not, you can view it at
30 * http://www.gnu.org/copyleft/gpl.html
31 * or write to the Free Software Foundation, Inc., 59
32 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 * Revision 1.42 2006/07/18 14:48:46 david__schmidt
37 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
38 * with what was really the latest development (the v_3_0_branch branch)
40 * Revision 1.40.2.4 2005/04/03 20:10:50 david__schmidt
41 * Thanks to Jindrich Makovicka for a race condition fix for the log
42 * file. The race condition remains for non-pthread implementations.
43 * Reference patch #1175720.
45 * Revision 1.40.2.3 2003/03/07 03:41:04 david__schmidt
46 * Wrapping all *_r functions (the non-_r versions of them) with mutex
47 * semaphores for OSX. Hopefully this will take care of all of those pesky
50 * Revision 1.40.2.2 2002/09/28 00:30:57 david__schmidt
51 * Update error logging to give sane values for thread IDs on Mach kernels.
52 * It's still a hack, but at least it looks farily normal. We print the
53 * absolute value of the first 4 bytes of the pthread_t modded with 1000.
55 * Revision 1.40.2.1 2002/09/25 12:47:42 oes
56 * Make log_error safe against NULL string arguments
58 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
60 * Add os2_socket_strerr mirroring w32_socket_strerr.
62 * Revision 1.39 2002/04/03 17:15:27 gliptak
63 * zero padding thread ids in log
65 * Revision 1.38 2002/03/31 17:18:59 jongfoster
66 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
68 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
69 * More compiler warning message maintenance
71 * Revision 1.36 2002/03/26 22:29:54 swa
72 * we have a new homepage!
74 * Revision 1.35 2002/03/24 15:23:33 jongfoster
77 * Revision 1.34 2002/03/24 13:25:43 swa
78 * name change related issues
80 * Revision 1.33 2002/03/13 00:27:04 jongfoster
83 * Revision 1.32 2002/03/07 03:46:17 oes
84 * Fixed compiler warnings
86 * Revision 1.31 2002/03/06 23:02:57 jongfoster
89 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
90 * - Better error reporting on OS/2
91 * - Fix double-slash comment (oops)
93 * Revision 1.29 2002/03/04 23:45:13 jongfoster
94 * Printing thread ID if using Win32 native threads
96 * Revision 1.28 2002/03/04 17:59:59 oes
97 * Deleted deletePidFile(), cosmetics
99 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
100 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
102 * Revision 1.26 2002/01/09 19:05:45 steudten
103 * Fix big memory leak.
105 * Revision 1.25 2002/01/09 14:32:08 oes
106 * Added support for gmtime_r and localtime_r.
108 * Revision 1.24 2001/12/30 14:07:32 steudten
109 * - Add signal handling (unix)
110 * - Add SIGHUP handler (unix)
111 * - Add creation of pidfile (unix)
112 * - Add action 'top' in rc file (RH)
113 * - Add entry 'SIGNALS' to manpage
114 * - Add exit message to logfile (unix)
116 * Revision 1.23 2001/11/07 00:02:13 steudten
117 * Add line number in error output for lineparsing for
118 * actionsfile and configfile.
119 * Special handling for CLF added.
121 * Revision 1.22 2001/11/05 23:43:05 steudten
122 * Add time+date to log files.
124 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
125 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
126 * threads to call select() simultaneously. So, it's time to do a real, live,
127 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
128 * (native). Both versions will work, but using __OS2__ offers multi-threading.
130 * Revision 1.20 2001/09/16 23:04:34 jongfoster
133 * Revision 1.19 2001/09/13 20:08:06 jongfoster
134 * Adding support for LOG_LEVEL_CGI
136 * Revision 1.18 2001/09/10 11:27:24 oes
137 * Declaration of w32_socket_strerr now conditional
139 * Revision 1.17 2001/09/10 10:17:13 oes
140 * Removed unused variable; Fixed sprintf format
142 * Revision 1.16 2001/07/30 22:08:36 jongfoster
143 * Tidying up #defines:
144 * - All feature #defines are now of the form FEATURE_xxx
145 * - Permanently turned off WIN_GUI_EDIT
146 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
148 * Revision 1.15 2001/07/29 17:41:10 jongfoster
149 * Now prints thread ID for each message (pthreads only)
151 * Revision 1.14 2001/07/19 19:03:48 haroon
152 * - Added case for LOG_LEVEL_POPUPS
154 * Revision 1.13 2001/07/13 13:58:58 oes
155 * - Added case for LOG_LEVEL_DEANIMATE
156 * - Removed all #ifdef PCRS
158 * Revision 1.12 2001/06/09 10:55:28 jongfoster
159 * Changing BUFSIZ ==> BUFFER_SIZE
161 * Revision 1.11 2001/06/01 18:14:49 jongfoster
162 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
163 * in config.h if appropriate) rather than the NO_STRERR macro.
165 * Revision 1.10 2001/05/29 11:52:21 oes
166 * Conditional compilation of w32_socket_error
168 * Revision 1.9 2001/05/28 16:15:17 jongfoster
169 * Improved reporting of errors under Win32.
171 * Revision 1.8 2001/05/26 17:25:14 jongfoster
172 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
174 * Revision 1.7 2001/05/26 15:21:28 jongfoster
175 * Activity animation in Win32 GUI now works even if debug==0
177 * Revision 1.6 2001/05/25 21:55:08 jongfoster
178 * Now cleans up properly on FATAL (removes taskbar icon etc)
180 * Revision 1.5 2001/05/22 18:46:04 oes
182 * - Enabled filtering banners by size rather than URL
183 * by adding patterns that replace all standard banner
184 * sizes with the "Junkbuster" gif to the re_filterfile
186 * - Enabled filtering WebBugs by providing a pattern
187 * which kills all 1x1 images
189 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
190 * which is selected by the (nonstandard and therefore
191 * capital) letter 'U' in the option string.
192 * It causes the quantifiers to be ungreedy by default.
193 * Appending a ? turns back to greedy (!).
195 * - Added a new interceptor ijb-send-banner, which
196 * sends back the "Junkbuster" gif. Without imagelist or
197 * MSIE detection support, or if tinygif = 1, or the
198 * URL isn't recognized as an imageurl, a lame HTML
199 * explanation is sent instead.
201 * - Added new feature, which permits blocking remote
202 * script redirects and firing back a local redirect
204 * The feature is conditionally compiled, i.e. it
205 * can be disabled with --disable-fast-redirects,
206 * plus it must be activated by a "fast-redirects"
207 * line in the config file, has its own log level
208 * and of course wants to be displayed by show-proxy-args
209 * Note: Boy, all the #ifdefs in 1001 locations and
210 * all the fumbling with configure.in and acconfig.h
211 * were *way* more work than the feature itself :-(
213 * - Because a generic redirect template was needed for
214 * this, tinygif = 3 now uses the same.
216 * - Moved GIFs, and other static HTTP response templates
221 * - Removed some >400 CRs again (Jon, you really worked
224 * Revision 1.4 2001/05/21 19:32:54 jongfoster
225 * Added another #ifdef _WIN_CONSOLE
227 * Revision 1.3 2001/05/20 01:11:40 jongfoster
228 * Added support for LOG_LEVEL_FATAL
229 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
230 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
232 * Revision 1.2 2001/05/17 22:42:01 oes
233 * - Cleaned CRLF's from the sources and related files
234 * - Repaired logging for REF and FRC
236 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
237 * Initial import of version 2.9.3 source tree
240 *********************************************************************/
244 #include "miscutil.h"
251 #if !defined(_WIN32) && !defined(__OS2__)
253 #endif /* !defined(_WIN32) && !defined(__OS2__) */
257 #ifdef FEATURE_PTHREAD
259 #endif /* def FEATURE_PTHREAD */
268 #endif /* ndef _WIN_CONSOLE */
269 #endif /* def _WIN32 */
272 #include <sys/socket.h> /* For sock_errno */
281 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
285 * LOG_LEVEL_FATAL cannot be turned off. (There are
286 * some exceptional situations where we need to get a
287 * message to the user).
289 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
291 /* where to log (default: stderr) */
292 static FILE *logfp = NULL;
294 /* logging detail level. */
295 int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
297 /* static functions */
298 static void fatal_error(const char * error_message);
300 static char *w32_socket_strerr(int errcode, char *tmp_buf);
303 static char *os2_socket_strerr(int errcode, char *tmp_buf);
306 #ifdef FEATURE_PTHREAD
307 static inline void lock_logfile()
309 pthread_mutex_lock(&log_mutex);
311 static inline void unlock_logfile()
313 pthread_mutex_unlock(&log_mutex);
315 static inline void lock_loginit()
317 pthread_mutex_lock(&log_init_mutex);
319 static inline void unlock_loginit()
321 pthread_mutex_unlock(&log_init_mutex);
323 #else /* ! FEATURE_PTHREAD */
325 * FIXME we need a cross-platform locking mechanism.
326 * The locking/unlocking functions below should be
327 * fleshed out for non-pthread implementations.
329 static inline void lock_logfile() {}
330 static inline void unlock_logfile() {}
331 static inline void lock_loginit() {}
332 static inline void unlock_loginit() {}
335 /*********************************************************************
337 * Function : fatal_error
339 * Description : Displays a fatal error to standard error (or, on
340 * a WIN32 GUI, to a dialog box), and exits
341 * JunkBuster with status code 1.
344 * 1 : error_message = The error message to display.
346 * Returns : Does not return.
348 *********************************************************************/
349 static void fatal_error(const char * error_message)
351 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
352 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
353 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
355 /* Cleanup - remove taskbar icon etc. */
358 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
359 fputs(error_message, stderr);
360 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
370 /*********************************************************************
372 * Function : init_error_log
374 * Description : Initializes the logging module. Must call before
378 * 1 : prog_name = The program name.
379 * 2 : logfname = The logfile name, or NULL for stderr.
380 * 3 : debuglevel = The debugging level.
384 *********************************************************************/
385 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
391 /* set the logging detail level */
392 debug = debuglevel | LOG_LEVEL_MINIMUM;
394 if ((logfp != NULL) && (logfp != stderr))
396 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
405 /* set the designated log file */
408 if( NULL == (fp = fopen(logfname, "a")) )
410 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
413 /* set logging to be completely unbuffered */
421 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
422 if (prog_name != NULL)
424 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
429 } /* init_error_log */
432 /*********************************************************************
434 * Function : log_error
436 * Description : This is the error-reporting and logging function.
439 * 1 : loglevel = the type of message to be logged
440 * 2 : fmt = the main string we want logged, printf-like
441 * 3 : ... = arguments to be inserted in fmt (printf-like).
445 *********************************************************************/
446 void log_error(int loglevel, char *fmt, ...)
450 static char *outbuf_save = NULL;
453 long this_thread = 1; /* was: pthread_t this_thread;*/
459 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
461 * Irrespective of debug setting, a GET/POST/CONNECT makes
462 * the taskbar icon animate. (There is an option to disable
463 * this but checking that is handled inside LogShowActivity()).
465 if (loglevel == LOG_LEVEL_GPC)
469 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
471 /* verify if loglevel applies to current settings and bail out if negative */
472 if ((loglevel & debug) == 0)
477 /* protect the whole function because of the static buffer (outbuf) */
480 /* FIXME get current thread id */
481 #ifdef FEATURE_PTHREAD
482 this_thread = (long)pthread_self();
485 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
486 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
487 * pthread_t is supposed to be opaque... but it's fairly random, though, so
488 * we make it mostly presentable.
490 this_thread = abs(this_thread % 1000);
491 #endif /* def __MACH__ */
492 #elif defined(_WIN32)
493 this_thread = GetCurrentThreadId();
494 #elif defined(__OS2__)
495 ulrc = DosGetInfoBlocks(&ptib, NULL);
497 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
498 #endif /* def FEATURE_PTHREAD */
502 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
505 outbuf = outbuf_save;
509 * Write timestamp into tempbuf.
511 * Complex because not all OSs have tm_gmtoff or
512 * the %z field in strftime()
517 #ifdef HAVE_LOCALTIME_R
518 tm_now = *localtime_r(&now, &tm_now);
520 pthread_mutex_lock(&localtime_mutex);
521 tm_now = *localtime (&now);
522 pthread_mutex_unlock(&localtime_mutex);
524 tm_now = *localtime (&now);
526 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
527 outbuf += strlen( outbuf );
531 case LOG_LEVEL_ERROR:
532 outc = sprintf(outbuf, "Privoxy(%08lx) Error: ", this_thread);
534 case LOG_LEVEL_FATAL:
535 outc = sprintf(outbuf, "Privoxy(%08lx) Fatal error: ", this_thread);
538 outc = sprintf(outbuf, "Privoxy(%08lx) Request: ", this_thread);
540 case LOG_LEVEL_CONNECT:
541 outc = sprintf(outbuf, "Privoxy(%08lx) Connect: ", this_thread);
544 outc = sprintf(outbuf, "Privoxy(%08lx) Writing: ", this_thread);
546 case LOG_LEVEL_HEADER:
547 outc = sprintf(outbuf, "Privoxy(%08lx) Header: ", this_thread);
550 outc = sprintf(outbuf, "Privoxy(%08lx) Info: ", this_thread);
552 case LOG_LEVEL_RE_FILTER:
553 outc = sprintf(outbuf, "Privoxy(%08lx) Re-Filter: ", this_thread);
555 #ifdef FEATURE_FORCE_LOAD
556 case LOG_LEVEL_FORCE:
557 outc = sprintf(outbuf, "Privoxy(%08lx) Force: ", this_thread);
559 #endif /* def FEATURE_FORCE_LOAD */
560 #ifdef FEATURE_FAST_REDIRECTS
561 case LOG_LEVEL_REDIRECTS:
562 outc = sprintf(outbuf, "Privoxy(%08lx) Redirect: ", this_thread);
564 #endif /* def FEATURE_FAST_REDIRECTS */
565 case LOG_LEVEL_DEANIMATE:
566 outc = sprintf(outbuf, "Privoxy(%08lx) Gif-Deanimate: ", this_thread);
569 outbuf = outbuf_save;
573 #ifdef FEATURE_KILL_POPUPS
574 case LOG_LEVEL_POPUPS:
575 outc = sprintf(outbuf, "Privoxy(%08lx) Kill-Popups: ", this_thread);
577 #endif /* def FEATURE_KILL_POPUPS */
579 outc = sprintf(outbuf, "Privoxy(%08lx) CGI: ", this_thread);
582 outc = sprintf(outbuf, "Privoxy(%08lx) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
586 /* get ready to scan var. args. */
589 /* build formatted message from fmt and var-args */
590 while ((*src) && (outc < BUFFER_SIZE-2))
592 char tempbuf[BUFFER_SIZE];
611 outbuf[outc++] = '%';
614 ival = va_arg( ap, int );
616 outc += sprintf(tempbuf, "%d", ival);
617 if (outc < BUFFER_SIZE-1)
619 strcpy(outbuf + oldoutc, tempbuf);
623 outbuf[oldoutc] = '\0';
627 uval = va_arg( ap, unsigned );
629 outc += sprintf(tempbuf, "%u", uval);
630 if (outc < BUFFER_SIZE-1)
632 strcpy(outbuf + oldoutc, tempbuf);
636 outbuf[oldoutc] = '\0';
640 /* this is a modifier that must be followed by u or d */
644 lval = va_arg( ap, long );
646 outc += sprintf(tempbuf, "%ld", lval);
650 ulval = va_arg( ap, unsigned long );
652 outc += sprintf(tempbuf, "%lu", ulval);
657 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
659 "Exiting.", this_thread, fmt);
664 fputs(outbuf, logfp);
669 if (outc < BUFFER_SIZE-1)
671 strcpy(outbuf + oldoutc, tempbuf);
675 outbuf[oldoutc] = '\0';
680 * Note that char paramaters are converted to int, so we need to
681 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
683 outbuf[outc++] = (char) va_arg( ap, int );
686 sval = va_arg( ap, char * );
692 outc += strlen(sval);
693 if (outc < BUFFER_SIZE-1)
695 strcpy(outbuf + oldoutc, sval);
699 outbuf[oldoutc] = '\0';
703 /* Non-standard: Print a counted string. Takes 2 parameters:
704 * int length, const char * string
706 ival = va_arg( ap, int );
707 sval = va_arg( ap, char * );
718 if (outc < BUFFER_SIZE-1)
720 memcpy(outbuf + oldoutc, sval, (size_t) ival);
724 outbuf[oldoutc] = '\0';
728 /* Non-standard: Print error code from errno */
730 ival = WSAGetLastError();
731 sval = w32_socket_strerr(ival, tempbuf);
735 sval = os2_socket_strerr(ival, tempbuf);
739 sval = strerror(ival);
741 #else /* ifndef _WIN32 */
744 sval = strerror(ival);
745 #else /* ifndef HAVE_STRERROR */
747 #endif /* ndef HAVE_STRERROR */
750 sprintf(tempbuf, "(errno = %d)", ival);
753 #endif /* ndef _WIN32 */
755 outc += strlen(sval);
756 if (outc < BUFFER_SIZE-1)
758 strcpy(outbuf + oldoutc, sval);
762 outbuf[oldoutc] = '\0';
766 /* Non-standard: Print a Common Log File timestamp */
769 * Write timestamp into tempbuf.
771 * Complex because not all OSs have tm_gmtoff or
772 * the %z field in strftime()
777 #ifdef HAVE_LOCALTIME_R
783 gmt = *gmtime_r(&now, &gmt);
785 pthread_mutex_lock(&gmtime_mutex);
787 pthread_mutex_unlock(&gmtime_mutex);
791 #ifdef HAVE_LOCALTIME_R
792 tm_now = localtime_r(&now, &dummy);
794 pthread_mutex_lock(&localtime_mutex);
795 tm_now = localtime (&now);
796 pthread_mutex_unlock(&localtime_mutex);
798 tm_now = localtime (&now);
800 days = tm_now->tm_yday - gmt.tm_yday;
801 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
802 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
803 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
804 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
807 outc += strlen(tempbuf);
808 if (outc < BUFFER_SIZE-1)
810 strcpy(outbuf + oldoutc, tempbuf);
814 outbuf[oldoutc] = '\0';
818 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
820 "Exiting.", this_thread, fmt);
825 fputs(outbuf_save, logfp);
827 fatal_error(outbuf_save);
835 /* done with var. args */
838 if (outc >= BUFFER_SIZE-2)
840 /* insufficient room for newline and trailing null. */
842 static const char warning[] = "... [too long, truncated]\n";
844 if (outc < BUFFER_SIZE)
846 /* Need to add terminating null in this case. */
850 /* Truncate output */
851 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
854 strcat(outbuf, warning);
858 /* Add terminating newline and null */
859 outbuf[outc++] = '\n';
863 /* deal with glibc stupidity - it won't let you initialize logfp */
869 fputs(outbuf_save, logfp);
871 if (loglevel == LOG_LEVEL_FATAL)
873 fatal_error(outbuf_save);
879 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
880 /* Write to display */
881 LogPutString(outbuf_save);
882 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
888 /*********************************************************************
890 * Function : w32_socket_strerr
892 * Description : Translate the return value from WSAGetLastError()
896 * 1 : errcode = The return value from WSAGetLastError().
897 * 2 : tmp_buf = A temporary buffer that might be used to
900 * Returns : String representing the error code. This may be
901 * a global string constant or a string stored in
904 *********************************************************************/
905 static char *w32_socket_strerr(int errcode, char *tmp_buf)
907 #define TEXT_FOR_ERROR(code,text) \
908 if (errcode == code) \
910 return #code " - " text; \
913 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
914 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
915 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
916 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
917 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
918 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
919 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
920 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
921 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
922 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
923 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
924 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
925 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
926 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
927 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
928 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
929 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
930 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
931 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
932 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
933 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
934 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
935 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
936 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
937 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
938 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
939 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
940 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
941 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
942 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
943 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
944 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
945 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
946 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
947 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
948 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
949 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
950 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
951 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
952 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
953 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
954 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
956 * The following error codes are documented in the Microsoft WinSock
957 * reference guide, but don't actually exist.
959 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
960 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
961 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
962 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
963 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
964 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
965 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
966 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
967 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
968 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
971 sprintf(tmp_buf, "(error number %d)", errcode);
974 #endif /* def _WIN32 */
978 /*********************************************************************
980 * Function : os2_socket_strerr
982 * Description : Translate the return value from sock_errno()
986 * 1 : errcode = The return value from sock_errno().
987 * 2 : tmp_buf = A temporary buffer that might be used to
990 * Returns : String representing the error code. This may be
991 * a global string constant or a string stored in
994 *********************************************************************/
995 static char *os2_socket_strerr(int errcode, char *tmp_buf)
997 #define TEXT_FOR_ERROR(code,text) \
998 if (errcode == code) \
1000 return #code " - " text; \
1003 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
1004 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
1005 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
1006 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
1007 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
1008 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
1009 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
1010 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
1011 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
1012 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
1013 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
1014 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
1015 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
1016 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
1017 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
1018 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
1019 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
1020 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
1021 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
1022 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
1023 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
1024 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
1025 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
1026 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
1027 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
1028 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
1029 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
1030 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
1031 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
1032 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
1033 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
1034 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
1035 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
1036 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
1037 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
1038 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
1039 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
1040 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
1041 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
1042 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
1043 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
1044 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
1045 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
1047 sprintf(tmp_buf, "(error number %d)", errcode);
1050 #endif /* def __OS2__ */