1 const char errlog_rcs[] = "$Id: errlog.c,v 1.53 2007/08/05 13:53:14 fabiankeil 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-2007 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.53 2007/08/05 13:53:14 fabiankeil
37 * #1763173 from Stefan Huehner: declare some more functions
38 * static and use void instead of empty parameter lists.
40 * Revision 1.52 2007/07/14 07:28:47 fabiankeil
41 * Add translation function for JB_ERR_FOO codes.
43 * Revision 1.51 2007/05/11 11:51:34 fabiankeil
44 * Fix a type mismatch warning.
46 * Revision 1.50 2007/04/11 10:55:44 fabiankeil
47 * Enforce some assertions that could be triggered
48 * on mingw32 and other systems where we use threads
51 * Revision 1.49 2007/04/08 16:44:15 fabiankeil
52 * We need <sys/time.h> for gettimeofday(), not <time.h>.
54 * Revision 1.48 2007/03/31 13:33:28 fabiankeil
55 * Add alternative log_error() with timestamps
56 * that contain milliseconds and without using
57 * strcpy(), strcat() or sprintf().
59 * Revision 1.47 2006/11/28 15:25:15 fabiankeil
60 * Only unlink the pidfile if it's actually used.
62 * Revision 1.46 2006/11/13 19:05:51 fabiankeil
63 * Make pthread mutex locking more generic. Instead of
64 * checking for OSX and OpenBSD, check for FEATURE_PTHREAD
65 * and use mutex locking unless there is an _r function
66 * available. Better safe than sorry.
68 * Fixes "./configure --disable-pthread" and should result
69 * in less threading-related problems on pthread-using platforms,
70 * but it still doesn't fix BR#1122404.
72 * Revision 1.45 2006/08/21 11:15:54 david__schmidt
73 * MS Visual C++ build updates
75 * Revision 1.44 2006/08/18 16:03:16 david__schmidt
76 * Tweak for OS/2 build happiness.
78 * Revision 1.43 2006/08/03 02:46:41 david__schmidt
79 * Incorporate Fabian Keil's patch work:
80 * http://www.fabiankeil.de/sourcecode/privoxy/
82 * Revision 1.42 2006/07/18 14:48:46 david__schmidt
83 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
84 * with what was really the latest development (the v_3_0_branch branch)
86 * Revision 1.40.2.4 2005/04/03 20:10:50 david__schmidt
87 * Thanks to Jindrich Makovicka for a race condition fix for the log
88 * file. The race condition remains for non-pthread implementations.
89 * Reference patch #1175720.
91 * Revision 1.40.2.3 2003/03/07 03:41:04 david__schmidt
92 * Wrapping all *_r functions (the non-_r versions of them) with mutex
93 * semaphores for OSX. Hopefully this will take care of all of those pesky
96 * Revision 1.40.2.2 2002/09/28 00:30:57 david__schmidt
97 * Update error logging to give sane values for thread IDs on Mach kernels.
98 * It's still a hack, but at least it looks farily normal. We print the
99 * absolute value of the first 4 bytes of the pthread_t modded with 1000.
101 * Revision 1.40.2.1 2002/09/25 12:47:42 oes
102 * Make log_error safe against NULL string arguments
104 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
106 * Add os2_socket_strerr mirroring w32_socket_strerr.
108 * Revision 1.39 2002/04/03 17:15:27 gliptak
109 * zero padding thread ids in log
111 * Revision 1.38 2002/03/31 17:18:59 jongfoster
112 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
114 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
115 * More compiler warning message maintenance
117 * Revision 1.36 2002/03/26 22:29:54 swa
118 * we have a new homepage!
120 * Revision 1.35 2002/03/24 15:23:33 jongfoster
123 * Revision 1.34 2002/03/24 13:25:43 swa
124 * name change related issues
126 * Revision 1.33 2002/03/13 00:27:04 jongfoster
129 * Revision 1.32 2002/03/07 03:46:17 oes
130 * Fixed compiler warnings
132 * Revision 1.31 2002/03/06 23:02:57 jongfoster
135 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
136 * - Better error reporting on OS/2
137 * - Fix double-slash comment (oops)
139 * Revision 1.29 2002/03/04 23:45:13 jongfoster
140 * Printing thread ID if using Win32 native threads
142 * Revision 1.28 2002/03/04 17:59:59 oes
143 * Deleted deletePidFile(), cosmetics
145 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
146 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
148 * Revision 1.26 2002/01/09 19:05:45 steudten
149 * Fix big memory leak.
151 * Revision 1.25 2002/01/09 14:32:08 oes
152 * Added support for gmtime_r and localtime_r.
154 * Revision 1.24 2001/12/30 14:07:32 steudten
155 * - Add signal handling (unix)
156 * - Add SIGHUP handler (unix)
157 * - Add creation of pidfile (unix)
158 * - Add action 'top' in rc file (RH)
159 * - Add entry 'SIGNALS' to manpage
160 * - Add exit message to logfile (unix)
162 * Revision 1.23 2001/11/07 00:02:13 steudten
163 * Add line number in error output for lineparsing for
164 * actionsfile and configfile.
165 * Special handling for CLF added.
167 * Revision 1.22 2001/11/05 23:43:05 steudten
168 * Add time+date to log files.
170 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
171 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
172 * threads to call select() simultaneously. So, it's time to do a real, live,
173 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
174 * (native). Both versions will work, but using __OS2__ offers multi-threading.
176 * Revision 1.20 2001/09/16 23:04:34 jongfoster
179 * Revision 1.19 2001/09/13 20:08:06 jongfoster
180 * Adding support for LOG_LEVEL_CGI
182 * Revision 1.18 2001/09/10 11:27:24 oes
183 * Declaration of w32_socket_strerr now conditional
185 * Revision 1.17 2001/09/10 10:17:13 oes
186 * Removed unused variable; Fixed sprintf format
188 * Revision 1.16 2001/07/30 22:08:36 jongfoster
189 * Tidying up #defines:
190 * - All feature #defines are now of the form FEATURE_xxx
191 * - Permanently turned off WIN_GUI_EDIT
192 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
194 * Revision 1.15 2001/07/29 17:41:10 jongfoster
195 * Now prints thread ID for each message (pthreads only)
197 * Revision 1.14 2001/07/19 19:03:48 haroon
198 * - Added case for LOG_LEVEL_POPUPS
200 * Revision 1.13 2001/07/13 13:58:58 oes
201 * - Added case for LOG_LEVEL_DEANIMATE
202 * - Removed all #ifdef PCRS
204 * Revision 1.12 2001/06/09 10:55:28 jongfoster
205 * Changing BUFSIZ ==> BUFFER_SIZE
207 * Revision 1.11 2001/06/01 18:14:49 jongfoster
208 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
209 * in config.h if appropriate) rather than the NO_STRERR macro.
211 * Revision 1.10 2001/05/29 11:52:21 oes
212 * Conditional compilation of w32_socket_error
214 * Revision 1.9 2001/05/28 16:15:17 jongfoster
215 * Improved reporting of errors under Win32.
217 * Revision 1.8 2001/05/26 17:25:14 jongfoster
218 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
220 * Revision 1.7 2001/05/26 15:21:28 jongfoster
221 * Activity animation in Win32 GUI now works even if debug==0
223 * Revision 1.6 2001/05/25 21:55:08 jongfoster
224 * Now cleans up properly on FATAL (removes taskbar icon etc)
226 * Revision 1.5 2001/05/22 18:46:04 oes
228 * - Enabled filtering banners by size rather than URL
229 * by adding patterns that replace all standard banner
230 * sizes with the "Junkbuster" gif to the re_filterfile
232 * - Enabled filtering WebBugs by providing a pattern
233 * which kills all 1x1 images
235 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
236 * which is selected by the (nonstandard and therefore
237 * capital) letter 'U' in the option string.
238 * It causes the quantifiers to be ungreedy by default.
239 * Appending a ? turns back to greedy (!).
241 * - Added a new interceptor ijb-send-banner, which
242 * sends back the "Junkbuster" gif. Without imagelist or
243 * MSIE detection support, or if tinygif = 1, or the
244 * URL isn't recognized as an imageurl, a lame HTML
245 * explanation is sent instead.
247 * - Added new feature, which permits blocking remote
248 * script redirects and firing back a local redirect
250 * The feature is conditionally compiled, i.e. it
251 * can be disabled with --disable-fast-redirects,
252 * plus it must be activated by a "fast-redirects"
253 * line in the config file, has its own log level
254 * and of course wants to be displayed by show-proxy-args
255 * Note: Boy, all the #ifdefs in 1001 locations and
256 * all the fumbling with configure.in and acconfig.h
257 * were *way* more work than the feature itself :-(
259 * - Because a generic redirect template was needed for
260 * this, tinygif = 3 now uses the same.
262 * - Moved GIFs, and other static HTTP response templates
267 * - Removed some >400 CRs again (Jon, you really worked
270 * Revision 1.4 2001/05/21 19:32:54 jongfoster
271 * Added another #ifdef _WIN_CONSOLE
273 * Revision 1.3 2001/05/20 01:11:40 jongfoster
274 * Added support for LOG_LEVEL_FATAL
275 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
276 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
278 * Revision 1.2 2001/05/17 22:42:01 oes
279 * - Cleaned CRLF's from the sources and related files
280 * - Repaired logging for REF and FRC
282 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
283 * Initial import of version 2.9.3 source tree
286 *********************************************************************/
295 #include "miscutil.h"
297 #if defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY)
298 #define USE_NEW_LOG_ERROR
299 /* For gettimeofday() */
300 #include <sys/time.h>
301 #endif /* defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY) */
303 #if !defined(_WIN32) && !defined(__OS2__)
305 #endif /* !defined(_WIN32) && !defined(__OS2__) */
317 #endif /* ndef _WIN_CONSOLE */
318 #endif /* def _WIN32 */
320 #define inline __inline
321 #endif /* def _MSC_VER */
324 #include <sys/socket.h> /* For sock_errno */
333 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
337 * LOG_LEVEL_FATAL cannot be turned off. (There are
338 * some exceptional situations where we need to get a
339 * message to the user).
341 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
343 /* where to log (default: stderr) */
344 static FILE *logfp = NULL;
346 /* logging detail level. */
347 int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
349 /* static functions */
350 static void fatal_error(const char * error_message);
352 static char *w32_socket_strerr(int errcode, char *tmp_buf);
355 static char *os2_socket_strerr(int errcode, char *tmp_buf);
358 #ifdef FEATURE_PTHREAD
359 static inline void lock_logfile(void)
361 pthread_mutex_lock(&log_mutex);
363 static inline void unlock_logfile(void)
365 pthread_mutex_unlock(&log_mutex);
367 static inline void lock_loginit(void)
369 pthread_mutex_lock(&log_init_mutex);
371 static inline void unlock_loginit(void)
373 pthread_mutex_unlock(&log_init_mutex);
375 #else /* ! FEATURE_PTHREAD */
377 * FIXME we need a cross-platform locking mechanism.
378 * The locking/unlocking functions below should be
379 * fleshed out for non-pthread implementations.
381 static inline void lock_logfile() {}
382 static inline void unlock_logfile() {}
383 static inline void lock_loginit() {}
384 static inline void unlock_loginit() {}
387 /*********************************************************************
389 * Function : fatal_error
391 * Description : Displays a fatal error to standard error (or, on
392 * a WIN32 GUI, to a dialog box), and exits
393 * JunkBuster with status code 1.
396 * 1 : error_message = The error message to display.
398 * Returns : Does not return.
400 *********************************************************************/
401 static void fatal_error(const char * error_message)
403 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
404 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
405 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
407 /* Cleanup - remove taskbar icon etc. */
410 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
411 fputs(error_message, stderr);
412 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
425 /*********************************************************************
427 * Function : init_error_log
429 * Description : Initializes the logging module. Must call before
433 * 1 : prog_name = The program name.
434 * 2 : logfname = The logfile name, or NULL for stderr.
435 * 3 : debuglevel = The debugging level.
439 *********************************************************************/
440 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
446 /* set the logging detail level */
447 debug = debuglevel | LOG_LEVEL_MINIMUM;
449 if ((logfp != NULL) && (logfp != stderr))
451 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
460 /* set the designated log file */
463 if( NULL == (fp = fopen(logfname, "a")) )
465 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
468 /* set logging to be completely unbuffered */
476 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
477 if (prog_name != NULL)
479 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
484 } /* init_error_log */
486 #if defined(USE_NEW_LOG_ERROR)
488 * Use an alternative log_error version and its helper functions.
490 * The code is mostly copied from the old log_error
491 * function but it's divided into multiple functions,
492 * doesn't use strcpy, strcat or sprintf and compiles
493 * with gcc43 without warnings (on FreeBSD that is).
495 * It should behave like the old log_error function with
498 * - too long format strings are logged truncated instead
499 * of completely replaced with the truncation warning,
500 * - its time stamps contain milliseconds.
503 /*********************************************************************
505 * Function : get_thread_id
507 * Description : Returns a number that is different for each thread.
509 * XXX: Should be moved elsewhere (miscutil.c?)
513 * Returns : thread_id
515 *********************************************************************/
516 static long get_thread_id(void)
518 long this_thread = 1; /* was: pthread_t this_thread;*/
522 APIRET ulrc; /* XXX: I have no clue what this does */
525 /* FIXME get current thread id */
526 #ifdef FEATURE_PTHREAD
527 this_thread = (long)pthread_self();
530 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
531 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
532 * pthread_t is supposed to be opaque... but it's fairly random, though, so
533 * we make it mostly presentable.
535 this_thread = abs(this_thread % 1000);
536 #endif /* def __MACH__ */
537 #elif defined(_WIN32)
538 this_thread = GetCurrentThreadId();
539 #elif defined(__OS2__)
540 ulrc = DosGetInfoBlocks(&ptib, NULL);
542 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
543 #endif /* def FEATURE_PTHREAD */
549 /*********************************************************************
551 * Function : get_log_timestamp
553 * Description : Generates the time stamp for the log message prefix.
556 * 1 : buffer = Storage buffer
557 * 2 : buffer_size = Size of storage buffer
559 * Returns : Number of written characters or 0 for error.
561 *********************************************************************/
562 static inline size_t get_log_timestamp(char *buffer, size_t buffer_size)
567 struct timeval tv_now; /* XXX: stupid name */
569 int msecs_length = 0;
571 gettimeofday(&tv_now, NULL);
572 msecs = tv_now.tv_usec / 1000;
576 #ifdef HAVE_LOCALTIME_R
577 tm_now = *localtime_r(&now, &tm_now);
578 #elif FEATURE_PTHREAD
579 pthread_mutex_lock(&localtime_mutex);
580 tm_now = *localtime(&now);
581 pthread_mutex_unlock(&localtime_mutex);
583 tm_now = *localtime(&now);
586 length = strftime(buffer, buffer_size, "%b %d %H:%M:%S", &tm_now);
589 msecs_length = snprintf(buffer+length, buffer_size - length, ".%.3ld", msecs);
591 if (msecs_length > 0)
593 length += (size_t)msecs_length;
604 /*********************************************************************
606 * Function : get_clf_timestamp
608 * Description : Generates a Common Log Format time string.
611 * 1 : buffer = Storage buffer
612 * 2 : buffer_size = Size of storage buffer
614 * Returns : Number of written characters or 0 for error.
616 *********************************************************************/
617 static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size)
620 * Complex because not all OSs have tm_gmtoff or
621 * the %z field in strftime()
626 #ifdef HAVE_LOCALTIME_R
635 gmt = *gmtime_r(&now, &gmt);
636 #elif FEATURE_PTHREAD
637 pthread_mutex_lock(&gmtime_mutex);
639 pthread_mutex_unlock(&gmtime_mutex);
643 #ifdef HAVE_LOCALTIME_R
644 tm_now = localtime_r(&now, &dummy);
645 #elif FEATURE_PTHREAD
646 pthread_mutex_lock(&localtime_mutex);
647 tm_now = localtime(&now);
648 pthread_mutex_unlock(&localtime_mutex);
650 tm_now = localtime(&now);
652 days = tm_now->tm_yday - gmt.tm_yday;
653 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
654 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
656 length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now);
660 tz_length = snprintf(buffer+length, buffer_size-length,
661 "%+03d%02d", mins / 60, abs(mins) % 60);
665 length += (size_t)tz_length;
676 /*********************************************************************
678 * Function : get_log_level_string
680 * Description : Translates a numerical loglevel into a string.
683 * 1 : loglevel = LOG_LEVEL_FOO
685 * Returns : Log level string.
687 *********************************************************************/
688 static inline const char *get_log_level_string(int loglevel)
690 char *log_level_string = NULL;
692 assert(0 < loglevel);
696 case LOG_LEVEL_ERROR:
697 log_level_string = "Error";
699 case LOG_LEVEL_FATAL:
700 log_level_string = "Fatal error";
703 log_level_string = "Request";
705 case LOG_LEVEL_CONNECT:
706 log_level_string = "Connect";
709 log_level_string = "Writing";
711 case LOG_LEVEL_HEADER:
712 log_level_string = "Header";
715 log_level_string = "Info";
717 case LOG_LEVEL_RE_FILTER:
718 log_level_string = "Re-Filter";
720 #ifdef FEATURE_FORCE_LOAD
721 case LOG_LEVEL_FORCE:
722 log_level_string = "Force";
724 #endif /* def FEATURE_FORCE_LOAD */
725 #ifdef FEATURE_FAST_REDIRECTS
726 case LOG_LEVEL_REDIRECTS:
727 log_level_string = "Redirect";
729 #endif /* def FEATURE_FAST_REDIRECTS */
730 case LOG_LEVEL_DEANIMATE:
731 log_level_string = "Gif-Deanimate";
733 #ifdef FEATURE_KILL_POPUPS
734 case LOG_LEVEL_POPUPS:
735 log_level_string = "Kill-Popups";
737 #endif /* def FEATURE_KILL_POPUPS */
739 log_level_string = "CGI";
742 log_level_string = "Unknown log level";
745 assert(NULL != log_level_string);
747 return log_level_string;
751 /*********************************************************************
753 * Function : log_error
755 * Description : This is the error-reporting and logging function.
758 * 1 : loglevel = the type of message to be logged
759 * 2 : fmt = the main string we want logged, printf-like
760 * 3 : ... = arguments to be inserted in fmt (printf-like).
764 *********************************************************************/
765 void log_error(int loglevel, const char *fmt, ...)
769 static char *outbuf_save = NULL;
770 char tempbuf[BUFFER_SIZE];
772 const char * src = fmt;
776 * XXX: Make this a config option,
777 * why else do we allocate instead of using
780 size_t log_buffer_size = BUFFER_SIZE;
782 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
784 * Irrespective of debug setting, a GET/POST/CONNECT makes
785 * the taskbar icon animate. (There is an option to disable
786 * this but checking that is handled inside LogShowActivity()).
788 if (loglevel == LOG_LEVEL_GPC)
792 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
794 /* verify if loglevel applies to current settings and bail out if negative */
795 if ((loglevel & debug) == 0)
800 thread_id = get_thread_id();
801 get_log_timestamp(timestamp, sizeof(timestamp));
803 /* protect the whole function because of the static buffer (outbuf) */
806 if (NULL == outbuf_save)
808 outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */
809 if (NULL == outbuf_save)
811 snprintf(tempbuf, sizeof(tempbuf),
812 "%s Privoxy(%08lx) Fatal error: log_error() failed to allocate buffer memory.\n"
813 "\nExiting.", timestamp, thread_id);
818 fputs(tempbuf, logfp);
820 fatal_error(tempbuf); /* Exit */
823 outbuf = outbuf_save;
826 * Memsetting the whole buffer to zero (in theory)
827 * makes things easier later on.
829 memset(outbuf, 0, log_buffer_size);
831 /* Add prefix for everything but Common Log Format messages */
832 if (loglevel != LOG_LEVEL_CLF)
834 length = (size_t)snprintf(outbuf, log_buffer_size, "%s Privoxy(%08lx) %s: ",
835 timestamp, thread_id, get_log_level_string(loglevel));
838 /* get ready to scan var. args. */
841 /* build formatted message from fmt and var-args */
842 while ((*src) && (length < log_buffer_size-2))
844 const char *sval = NULL; /* %N string */
845 int ival; /* %N string length or an error code */
846 unsigned uval; /* %u value */
847 long lval; /* %l value */
848 unsigned long ulval; /* %ul value */
850 const char *format_string = tempbuf;
855 outbuf[length++] = ch;
857 * XXX: Only necessary on platforms which don't use pthread
858 * mutexes (mingw32 for example), where multiple threads can
859 * write to the buffer at the same time.
861 outbuf[length] = '\0';
864 outbuf[length] = '\0';
872 ival = va_arg( ap, int );
873 snprintf(tempbuf, sizeof(tempbuf), "%d", ival);
876 uval = va_arg( ap, unsigned );
877 snprintf(tempbuf, sizeof(tempbuf), "%u", uval);
880 /* this is a modifier that must be followed by u or d */
884 lval = va_arg( ap, long );
885 snprintf(tempbuf, sizeof(tempbuf), "%ld", lval);
889 ulval = va_arg( ap, unsigned long );
890 snprintf(tempbuf, sizeof(tempbuf), "%lu", ulval);
894 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
895 loglevel = LOG_LEVEL_FATAL;
900 * Note that char paramaters are converted to int, so we need to
901 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
903 tempbuf[0] = (char) va_arg(ap, int);
907 format_string = va_arg(ap, char *);
908 if (format_string == NULL)
910 format_string = "[null]";
915 * Non-standard: Print a counted unterminated string.
916 * Takes 2 parameters: int length, const char * string.
918 ival = va_arg(ap, int);
919 sval = va_arg(ap, char *);
922 format_string = "[null]";
928 /* That's ok (but stupid) */
934 * That's not ok (and even more stupid)
937 format_string = "[counted string lenght < 0]";
940 else if (ival >= sizeof(tempbuf))
943 * String is too long, copy as much as possible.
944 * It will be further truncated later.
946 memcpy(tempbuf, sval, sizeof(tempbuf)-1);
947 tempbuf[sizeof(tempbuf)-1] = '\0';
951 memcpy(tempbuf, sval, (size_t) ival);
952 tempbuf[ival] = '\0';
956 /* Non-standard: Print error code from errno */
958 ival = WSAGetLastError();
959 format_string = w32_socket_strerr(ival, tempbuf);
964 format_string = os2_socket_strerr(ival, tempbuf);
969 format_string = strerror(ival);
971 #else /* ifndef _WIN32 */
974 format_string = strerror(ival);
975 #else /* ifndef HAVE_STRERROR */
976 format_string = NULL;
977 #endif /* ndef HAVE_STRERROR */
980 snprintf(tempbuf, sizeof(tempbuf), "(errno = %d)", ival);
982 #endif /* ndef _WIN32 */
985 /* Non-standard: Print a Common Log File timestamp */
986 get_clf_timestamp(tempbuf, sizeof(tempbuf));
989 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
990 loglevel = LOG_LEVEL_FATAL;
994 assert(length < log_buffer_size);
995 length += strlcpy(outbuf + length, format_string, log_buffer_size - length);
997 if (length >= log_buffer_size-2)
999 static char warning[] = "... [too long, truncated]";
1001 length = log_buffer_size - sizeof(warning) - 1;
1002 length += strlcpy(outbuf + length, warning, log_buffer_size - length);
1003 assert(length < log_buffer_size);
1007 } /* for( p ... ) */
1009 /* done with var. args */
1012 assert(length < log_buffer_size);
1013 length += strlcpy(outbuf + length, "\n", log_buffer_size - length);
1015 /* Some sanity checks */
1016 if (!(length < log_buffer_size)
1017 || !(outbuf[log_buffer_size-1] == '\0')
1018 || !(outbuf[log_buffer_size] == '\0')
1021 /* Repeat as assertions */
1022 assert(length < log_buffer_size);
1023 assert(outbuf[log_buffer_size-1] == '\0');
1025 * outbuf's real size is log_buffer_size+1,
1026 * so while this looks like an off-by-one,
1027 * we're only checking our paranoia byte.
1029 assert(outbuf[log_buffer_size] == '\0');
1031 snprintf(outbuf, log_buffer_size,
1032 "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %d\n"
1033 "Exiting.", timestamp, thread_id, (int)length);
1034 loglevel = LOG_LEVEL_FATAL;
1037 /* deal with glibc stupidity - it won't let you initialize logfp */
1038 /* XXX: Still necessary? */
1044 fputs(outbuf_save, logfp);
1046 if (loglevel == LOG_LEVEL_FATAL)
1048 fatal_error(outbuf_save);
1049 /* Never get here */
1054 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1055 /* Write to display */
1056 LogPutString(outbuf_save);
1057 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1061 #else /* use traditional log_error version */
1063 /*********************************************************************
1065 * Function : log_error
1067 * Description : This is the error-reporting and logging function.
1070 * 1 : loglevel = the type of message to be logged
1071 * 2 : fmt = the main string we want logged, printf-like
1072 * 3 : ... = arguments to be inserted in fmt (printf-like).
1076 *********************************************************************/
1077 void log_error(int loglevel, const char *fmt, ...)
1081 static char *outbuf_save = NULL;
1082 const char * src = fmt;
1084 long this_thread = 1; /* was: pthread_t this_thread;*/
1088 #endif /* __OS2__ */
1090 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1092 * Irrespective of debug setting, a GET/POST/CONNECT makes
1093 * the taskbar icon animate. (There is an option to disable
1094 * this but checking that is handled inside LogShowActivity()).
1096 if (loglevel == LOG_LEVEL_GPC)
1100 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1102 /* verify if loglevel applies to current settings and bail out if negative */
1103 if ((loglevel & debug) == 0)
1108 /* protect the whole function because of the static buffer (outbuf) */
1111 /* FIXME get current thread id */
1112 #ifdef FEATURE_PTHREAD
1113 this_thread = (long)pthread_self();
1116 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
1117 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
1118 * pthread_t is supposed to be opaque... but it's fairly random, though, so
1119 * we make it mostly presentable.
1121 this_thread = abs(this_thread % 1000);
1122 #endif /* def __MACH__ */
1123 #elif defined(_WIN32)
1124 this_thread = GetCurrentThreadId();
1125 #elif defined(__OS2__)
1126 ulrc = DosGetInfoBlocks(&ptib, NULL);
1128 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
1129 #endif /* def FEATURE_PTHREAD */
1133 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
1134 if (NULL == outbuf_save)
1136 fatal_error("Privoxy failed to allocate log buffer.");
1139 outbuf = outbuf_save;
1143 * Write timestamp into tempbuf.
1145 * Complex because not all OSs have tm_gmtoff or
1146 * the %z field in strftime()
1151 #ifdef HAVE_LOCALTIME_R
1152 tm_now = *localtime_r(&now, &tm_now);
1153 #elif FEATURE_PTHREAD
1154 pthread_mutex_lock(&localtime_mutex);
1155 tm_now = *localtime (&now);
1156 pthread_mutex_unlock(&localtime_mutex);
1158 tm_now = *localtime (&now);
1160 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1161 outbuf += strlen( outbuf );
1165 case LOG_LEVEL_ERROR:
1166 outc = sprintf(outbuf, "Privoxy(%08lx) Error: ", this_thread);
1168 case LOG_LEVEL_FATAL:
1169 outc = sprintf(outbuf, "Privoxy(%08lx) Fatal error: ", this_thread);
1172 outc = sprintf(outbuf, "Privoxy(%08lx) Request: ", this_thread);
1174 case LOG_LEVEL_CONNECT:
1175 outc = sprintf(outbuf, "Privoxy(%08lx) Connect: ", this_thread);
1178 outc = sprintf(outbuf, "Privoxy(%08lx) Writing: ", this_thread);
1180 case LOG_LEVEL_HEADER:
1181 outc = sprintf(outbuf, "Privoxy(%08lx) Header: ", this_thread);
1183 case LOG_LEVEL_INFO:
1184 outc = sprintf(outbuf, "Privoxy(%08lx) Info: ", this_thread);
1186 case LOG_LEVEL_RE_FILTER:
1187 outc = sprintf(outbuf, "Privoxy(%08lx) Re-Filter: ", this_thread);
1189 #ifdef FEATURE_FORCE_LOAD
1190 case LOG_LEVEL_FORCE:
1191 outc = sprintf(outbuf, "Privoxy(%08lx) Force: ", this_thread);
1193 #endif /* def FEATURE_FORCE_LOAD */
1194 #ifdef FEATURE_FAST_REDIRECTS
1195 case LOG_LEVEL_REDIRECTS:
1196 outc = sprintf(outbuf, "Privoxy(%08lx) Redirect: ", this_thread);
1198 #endif /* def FEATURE_FAST_REDIRECTS */
1199 case LOG_LEVEL_DEANIMATE:
1200 outc = sprintf(outbuf, "Privoxy(%08lx) Gif-Deanimate: ", this_thread);
1203 outbuf = outbuf_save;
1207 #ifdef FEATURE_KILL_POPUPS
1208 case LOG_LEVEL_POPUPS:
1209 outc = sprintf(outbuf, "Privoxy(%08lx) Kill-Popups: ", this_thread);
1211 #endif /* def FEATURE_KILL_POPUPS */
1213 outc = sprintf(outbuf, "Privoxy(%08lx) CGI: ", this_thread);
1216 outc = sprintf(outbuf, "Privoxy(%08lx) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
1220 /* get ready to scan var. args. */
1221 va_start( ap, fmt );
1223 /* build formatted message from fmt and var-args */
1224 while ((*src) && (outc < BUFFER_SIZE-2))
1226 char tempbuf[BUFFER_SIZE];
1231 unsigned long ulval;
1238 outbuf[outc++] = ch;
1245 outbuf[outc++] = '%';
1248 ival = va_arg( ap, int );
1250 outc += sprintf(tempbuf, "%d", ival);
1251 if (outc < BUFFER_SIZE-1)
1253 strcpy(outbuf + oldoutc, tempbuf);
1257 outbuf[oldoutc] = '\0';
1261 uval = va_arg( ap, unsigned );
1263 outc += sprintf(tempbuf, "%u", uval);
1264 if (outc < BUFFER_SIZE-1)
1266 strcpy(outbuf + oldoutc, tempbuf);
1270 outbuf[oldoutc] = '\0';
1274 /* this is a modifier that must be followed by u or d */
1278 lval = va_arg( ap, long );
1280 outc += sprintf(tempbuf, "%ld", lval);
1284 ulval = va_arg( ap, unsigned long );
1286 outc += sprintf(tempbuf, "%lu", ulval);
1291 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1293 "Exiting.", this_thread, fmt);
1298 fputs(outbuf, logfp);
1299 fatal_error(outbuf);
1300 /* Never get here */
1303 if (outc < BUFFER_SIZE-1)
1305 strcpy(outbuf + oldoutc, tempbuf);
1309 outbuf[oldoutc] = '\0';
1314 * Note that char paramaters are converted to int, so we need to
1315 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
1317 outbuf[outc++] = (char) va_arg( ap, int );
1320 sval = va_arg( ap, char * );
1326 outc += strlen(sval);
1327 if (outc < BUFFER_SIZE-1)
1329 strcpy(outbuf + oldoutc, sval);
1333 outbuf[oldoutc] = '\0';
1337 /* Non-standard: Print a counted string. Takes 2 parameters:
1338 * int length, const char * string
1340 ival = va_arg( ap, int );
1341 sval = va_arg( ap, char * );
1352 if (outc < BUFFER_SIZE-1)
1354 memcpy(outbuf + oldoutc, sval, (size_t) ival);
1358 outbuf[oldoutc] = '\0';
1362 /* Non-standard: Print error code from errno */
1364 ival = WSAGetLastError();
1365 sval = w32_socket_strerr(ival, tempbuf);
1367 ival = sock_errno();
1369 sval = os2_socket_strerr(ival, tempbuf);
1373 sval = strerror(ival);
1375 #else /* ifndef _WIN32 */
1377 #ifdef HAVE_STRERROR
1378 sval = strerror(ival);
1379 #else /* ifndef HAVE_STRERROR */
1381 #endif /* ndef HAVE_STRERROR */
1384 sprintf(tempbuf, "(errno = %d)", ival);
1387 #endif /* ndef _WIN32 */
1389 outc += strlen(sval);
1390 if (outc < BUFFER_SIZE-1)
1392 strcpy(outbuf + oldoutc, sval);
1396 outbuf[oldoutc] = '\0';
1400 /* Non-standard: Print a Common Log File timestamp */
1403 * Write timestamp into tempbuf.
1405 * Complex because not all OSs have tm_gmtoff or
1406 * the %z field in strftime()
1411 #ifdef HAVE_LOCALTIME_R
1414 int days, hrs, mins;
1416 #ifdef HAVE_GMTIME_R
1417 gmt = *gmtime_r(&now, &gmt);
1418 #elif FEATURE_PTHREAD
1419 pthread_mutex_lock(&gmtime_mutex);
1420 gmt = *gmtime(&now);
1421 pthread_mutex_unlock(&gmtime_mutex);
1423 gmt = *gmtime(&now);
1425 #ifdef HAVE_LOCALTIME_R
1426 tm_now = localtime_r(&now, &dummy);
1427 #elif FEATURE_PTHREAD
1428 pthread_mutex_lock(&localtime_mutex);
1429 tm_now = localtime (&now);
1430 pthread_mutex_unlock(&localtime_mutex);
1432 tm_now = localtime (&now);
1434 days = tm_now->tm_yday - gmt.tm_yday;
1435 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
1436 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
1437 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
1438 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
1441 outc += strlen(tempbuf);
1442 if (outc < BUFFER_SIZE-1)
1444 strcpy(outbuf + oldoutc, tempbuf);
1448 outbuf[oldoutc] = '\0';
1452 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1454 "Exiting.", this_thread, fmt);
1459 fputs(outbuf_save, logfp);
1461 fatal_error(outbuf_save);
1462 /* Never get here */
1467 } /* for( p ... ) */
1469 /* done with var. args */
1472 if (outc >= BUFFER_SIZE-2)
1474 /* insufficient room for newline and trailing null. */
1476 static const char warning[] = "... [too long, truncated]\n";
1478 if (outc < BUFFER_SIZE)
1480 /* Need to add terminating null in this case. */
1481 outbuf[outc] = '\0';
1484 /* Truncate output */
1485 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
1487 /* Append warning */
1488 strcat(outbuf, warning);
1492 /* Add terminating newline and null */
1493 outbuf[outc++] = '\n';
1494 outbuf[outc] = '\0';
1497 /* deal with glibc stupidity - it won't let you initialize logfp */
1503 fputs(outbuf_save, logfp);
1505 if (loglevel == LOG_LEVEL_FATAL)
1507 fatal_error(outbuf_save);
1508 /* Never get here */
1513 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1514 /* Write to display */
1515 LogPutString(outbuf_save);
1516 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1519 #endif /* defined(USE_NEW_LOG_ERROR) */
1522 /*********************************************************************
1524 * Function : jb_err_to_string
1526 * Description : Translates JB_ERR_FOO codes into strings.
1528 * XXX: the type of error codes is jb_err
1529 * but the typedef'inition is currently not
1530 * visible to all files that include errlog.h.
1533 * 1 : error = a valid jb_err code
1535 * Returns : A string with the jb_err translation
1537 *********************************************************************/
1538 const char *jb_err_to_string(int error)
1543 return "Success, no error";
1545 return "Out of memory";
1546 case JB_ERR_CGI_PARAMS:
1547 return "Missing or corrupt CGI parameters";
1549 return "Error opening, reading or writing a file";
1551 return "Parse error";
1552 case JB_ERR_MODIFIED:
1553 return "File has been modified outside of the CGI actions editor.";
1554 case JB_ERR_COMPRESS:
1555 return "(De)compression failure";
1558 return "Unknown error";
1561 return "Internal error";
1565 /*********************************************************************
1567 * Function : w32_socket_strerr
1569 * Description : Translate the return value from WSAGetLastError()
1573 * 1 : errcode = The return value from WSAGetLastError().
1574 * 2 : tmp_buf = A temporary buffer that might be used to
1577 * Returns : String representing the error code. This may be
1578 * a global string constant or a string stored in
1581 *********************************************************************/
1582 static char *w32_socket_strerr(int errcode, char *tmp_buf)
1584 #define TEXT_FOR_ERROR(code,text) \
1585 if (errcode == code) \
1587 return #code " - " text; \
1590 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
1591 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
1592 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
1593 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
1594 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
1595 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
1596 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
1597 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
1598 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
1599 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
1600 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
1601 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
1602 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
1603 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
1604 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
1605 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
1606 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
1607 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
1608 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
1609 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
1610 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
1611 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
1612 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
1613 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
1614 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
1615 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
1616 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
1617 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
1618 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
1619 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
1620 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
1621 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
1622 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
1623 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
1624 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
1625 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
1626 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
1627 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
1628 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
1629 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
1630 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
1631 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
1633 * The following error codes are documented in the Microsoft WinSock
1634 * reference guide, but don't actually exist.
1636 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
1637 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
1638 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
1639 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
1640 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
1641 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
1642 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
1643 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
1644 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
1645 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
1648 sprintf(tmp_buf, "(error number %d)", errcode);
1651 #endif /* def _WIN32 */
1655 /*********************************************************************
1657 * Function : os2_socket_strerr
1659 * Description : Translate the return value from sock_errno()
1663 * 1 : errcode = The return value from sock_errno().
1664 * 2 : tmp_buf = A temporary buffer that might be used to
1667 * Returns : String representing the error code. This may be
1668 * a global string constant or a string stored in
1671 *********************************************************************/
1672 static char *os2_socket_strerr(int errcode, char *tmp_buf)
1674 #define TEXT_FOR_ERROR(code,text) \
1675 if (errcode == code) \
1677 return #code " - " text; \
1680 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
1681 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
1682 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
1683 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
1684 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
1685 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
1686 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
1687 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
1688 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
1689 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
1690 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
1691 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
1692 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
1693 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
1694 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
1695 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
1696 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
1697 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
1698 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
1699 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
1700 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
1701 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
1702 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
1703 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
1704 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
1705 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
1706 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
1707 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
1708 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
1709 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
1710 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
1711 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
1712 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
1713 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
1714 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
1715 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
1716 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
1717 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
1718 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
1719 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
1720 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
1721 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
1722 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
1724 sprintf(tmp_buf, "(error number %d)", errcode);
1727 #endif /* def __OS2__ */