1 const char errlog_rcs[] = "$Id: errlog.c,v 1.48 2007/03/31 13:33:28 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.48 2007/03/31 13:33:28 fabiankeil
37 * Add alternative log_error() with timestamps
38 * that contain milliseconds and without using
39 * strcpy(), strcat() or sprintf().
41 * Revision 1.47 2006/11/28 15:25:15 fabiankeil
42 * Only unlink the pidfile if it's actually used.
44 * Revision 1.46 2006/11/13 19:05:51 fabiankeil
45 * Make pthread mutex locking more generic. Instead of
46 * checking for OSX and OpenBSD, check for FEATURE_PTHREAD
47 * and use mutex locking unless there is an _r function
48 * available. Better safe than sorry.
50 * Fixes "./configure --disable-pthread" and should result
51 * in less threading-related problems on pthread-using platforms,
52 * but it still doesn't fix BR#1122404.
54 * Revision 1.45 2006/08/21 11:15:54 david__schmidt
55 * MS Visual C++ build updates
57 * Revision 1.44 2006/08/18 16:03:16 david__schmidt
58 * Tweak for OS/2 build happiness.
60 * Revision 1.43 2006/08/03 02:46:41 david__schmidt
61 * Incorporate Fabian Keil's patch work:
62 * http://www.fabiankeil.de/sourcecode/privoxy/
64 * Revision 1.42 2006/07/18 14:48:46 david__schmidt
65 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
66 * with what was really the latest development (the v_3_0_branch branch)
68 * Revision 1.40.2.4 2005/04/03 20:10:50 david__schmidt
69 * Thanks to Jindrich Makovicka for a race condition fix for the log
70 * file. The race condition remains for non-pthread implementations.
71 * Reference patch #1175720.
73 * Revision 1.40.2.3 2003/03/07 03:41:04 david__schmidt
74 * Wrapping all *_r functions (the non-_r versions of them) with mutex
75 * semaphores for OSX. Hopefully this will take care of all of those pesky
78 * Revision 1.40.2.2 2002/09/28 00:30:57 david__schmidt
79 * Update error logging to give sane values for thread IDs on Mach kernels.
80 * It's still a hack, but at least it looks farily normal. We print the
81 * absolute value of the first 4 bytes of the pthread_t modded with 1000.
83 * Revision 1.40.2.1 2002/09/25 12:47:42 oes
84 * Make log_error safe against NULL string arguments
86 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
88 * Add os2_socket_strerr mirroring w32_socket_strerr.
90 * Revision 1.39 2002/04/03 17:15:27 gliptak
91 * zero padding thread ids in log
93 * Revision 1.38 2002/03/31 17:18:59 jongfoster
94 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
96 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
97 * More compiler warning message maintenance
99 * Revision 1.36 2002/03/26 22:29:54 swa
100 * we have a new homepage!
102 * Revision 1.35 2002/03/24 15:23:33 jongfoster
105 * Revision 1.34 2002/03/24 13:25:43 swa
106 * name change related issues
108 * Revision 1.33 2002/03/13 00:27:04 jongfoster
111 * Revision 1.32 2002/03/07 03:46:17 oes
112 * Fixed compiler warnings
114 * Revision 1.31 2002/03/06 23:02:57 jongfoster
117 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
118 * - Better error reporting on OS/2
119 * - Fix double-slash comment (oops)
121 * Revision 1.29 2002/03/04 23:45:13 jongfoster
122 * Printing thread ID if using Win32 native threads
124 * Revision 1.28 2002/03/04 17:59:59 oes
125 * Deleted deletePidFile(), cosmetics
127 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
128 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
130 * Revision 1.26 2002/01/09 19:05:45 steudten
131 * Fix big memory leak.
133 * Revision 1.25 2002/01/09 14:32:08 oes
134 * Added support for gmtime_r and localtime_r.
136 * Revision 1.24 2001/12/30 14:07:32 steudten
137 * - Add signal handling (unix)
138 * - Add SIGHUP handler (unix)
139 * - Add creation of pidfile (unix)
140 * - Add action 'top' in rc file (RH)
141 * - Add entry 'SIGNALS' to manpage
142 * - Add exit message to logfile (unix)
144 * Revision 1.23 2001/11/07 00:02:13 steudten
145 * Add line number in error output for lineparsing for
146 * actionsfile and configfile.
147 * Special handling for CLF added.
149 * Revision 1.22 2001/11/05 23:43:05 steudten
150 * Add time+date to log files.
152 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
153 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
154 * threads to call select() simultaneously. So, it's time to do a real, live,
155 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
156 * (native). Both versions will work, but using __OS2__ offers multi-threading.
158 * Revision 1.20 2001/09/16 23:04:34 jongfoster
161 * Revision 1.19 2001/09/13 20:08:06 jongfoster
162 * Adding support for LOG_LEVEL_CGI
164 * Revision 1.18 2001/09/10 11:27:24 oes
165 * Declaration of w32_socket_strerr now conditional
167 * Revision 1.17 2001/09/10 10:17:13 oes
168 * Removed unused variable; Fixed sprintf format
170 * Revision 1.16 2001/07/30 22:08:36 jongfoster
171 * Tidying up #defines:
172 * - All feature #defines are now of the form FEATURE_xxx
173 * - Permanently turned off WIN_GUI_EDIT
174 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
176 * Revision 1.15 2001/07/29 17:41:10 jongfoster
177 * Now prints thread ID for each message (pthreads only)
179 * Revision 1.14 2001/07/19 19:03:48 haroon
180 * - Added case for LOG_LEVEL_POPUPS
182 * Revision 1.13 2001/07/13 13:58:58 oes
183 * - Added case for LOG_LEVEL_DEANIMATE
184 * - Removed all #ifdef PCRS
186 * Revision 1.12 2001/06/09 10:55:28 jongfoster
187 * Changing BUFSIZ ==> BUFFER_SIZE
189 * Revision 1.11 2001/06/01 18:14:49 jongfoster
190 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
191 * in config.h if appropriate) rather than the NO_STRERR macro.
193 * Revision 1.10 2001/05/29 11:52:21 oes
194 * Conditional compilation of w32_socket_error
196 * Revision 1.9 2001/05/28 16:15:17 jongfoster
197 * Improved reporting of errors under Win32.
199 * Revision 1.8 2001/05/26 17:25:14 jongfoster
200 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
202 * Revision 1.7 2001/05/26 15:21:28 jongfoster
203 * Activity animation in Win32 GUI now works even if debug==0
205 * Revision 1.6 2001/05/25 21:55:08 jongfoster
206 * Now cleans up properly on FATAL (removes taskbar icon etc)
208 * Revision 1.5 2001/05/22 18:46:04 oes
210 * - Enabled filtering banners by size rather than URL
211 * by adding patterns that replace all standard banner
212 * sizes with the "Junkbuster" gif to the re_filterfile
214 * - Enabled filtering WebBugs by providing a pattern
215 * which kills all 1x1 images
217 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
218 * which is selected by the (nonstandard and therefore
219 * capital) letter 'U' in the option string.
220 * It causes the quantifiers to be ungreedy by default.
221 * Appending a ? turns back to greedy (!).
223 * - Added a new interceptor ijb-send-banner, which
224 * sends back the "Junkbuster" gif. Without imagelist or
225 * MSIE detection support, or if tinygif = 1, or the
226 * URL isn't recognized as an imageurl, a lame HTML
227 * explanation is sent instead.
229 * - Added new feature, which permits blocking remote
230 * script redirects and firing back a local redirect
232 * The feature is conditionally compiled, i.e. it
233 * can be disabled with --disable-fast-redirects,
234 * plus it must be activated by a "fast-redirects"
235 * line in the config file, has its own log level
236 * and of course wants to be displayed by show-proxy-args
237 * Note: Boy, all the #ifdefs in 1001 locations and
238 * all the fumbling with configure.in and acconfig.h
239 * were *way* more work than the feature itself :-(
241 * - Because a generic redirect template was needed for
242 * this, tinygif = 3 now uses the same.
244 * - Moved GIFs, and other static HTTP response templates
249 * - Removed some >400 CRs again (Jon, you really worked
252 * Revision 1.4 2001/05/21 19:32:54 jongfoster
253 * Added another #ifdef _WIN_CONSOLE
255 * Revision 1.3 2001/05/20 01:11:40 jongfoster
256 * Added support for LOG_LEVEL_FATAL
257 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
258 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
260 * Revision 1.2 2001/05/17 22:42:01 oes
261 * - Cleaned CRLF's from the sources and related files
262 * - Repaired logging for REF and FRC
264 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
265 * Initial import of version 2.9.3 source tree
268 *********************************************************************/
272 #include "miscutil.h"
279 #if defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY)
280 #define USE_NEW_LOG_ERROR
281 /* For gettimeofday() */
282 #include <sys/time.h>
283 #endif /* defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY) */
285 #if !defined(_WIN32) && !defined(__OS2__)
287 #endif /* !defined(_WIN32) && !defined(__OS2__) */
299 #endif /* ndef _WIN_CONSOLE */
300 #endif /* def _WIN32 */
302 #define inline __inline
303 #endif /* def _MSC_VER */
306 #include <sys/socket.h> /* For sock_errno */
315 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
319 * LOG_LEVEL_FATAL cannot be turned off. (There are
320 * some exceptional situations where we need to get a
321 * message to the user).
323 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
325 /* where to log (default: stderr) */
326 static FILE *logfp = NULL;
328 /* logging detail level. */
329 int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
331 /* static functions */
332 static void fatal_error(const char * error_message);
334 static char *w32_socket_strerr(int errcode, char *tmp_buf);
337 static char *os2_socket_strerr(int errcode, char *tmp_buf);
340 #ifdef FEATURE_PTHREAD
341 static inline void lock_logfile()
343 pthread_mutex_lock(&log_mutex);
345 static inline void unlock_logfile()
347 pthread_mutex_unlock(&log_mutex);
349 static inline void lock_loginit()
351 pthread_mutex_lock(&log_init_mutex);
353 static inline void unlock_loginit()
355 pthread_mutex_unlock(&log_init_mutex);
357 #else /* ! FEATURE_PTHREAD */
359 * FIXME we need a cross-platform locking mechanism.
360 * The locking/unlocking functions below should be
361 * fleshed out for non-pthread implementations.
363 static inline void lock_logfile() {}
364 static inline void unlock_logfile() {}
365 static inline void lock_loginit() {}
366 static inline void unlock_loginit() {}
369 /*********************************************************************
371 * Function : fatal_error
373 * Description : Displays a fatal error to standard error (or, on
374 * a WIN32 GUI, to a dialog box), and exits
375 * JunkBuster with status code 1.
378 * 1 : error_message = The error message to display.
380 * Returns : Does not return.
382 *********************************************************************/
383 static void fatal_error(const char * error_message)
385 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
386 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
387 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
389 /* Cleanup - remove taskbar icon etc. */
392 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
393 fputs(error_message, stderr);
394 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
407 /*********************************************************************
409 * Function : init_error_log
411 * Description : Initializes the logging module. Must call before
415 * 1 : prog_name = The program name.
416 * 2 : logfname = The logfile name, or NULL for stderr.
417 * 3 : debuglevel = The debugging level.
421 *********************************************************************/
422 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
428 /* set the logging detail level */
429 debug = debuglevel | LOG_LEVEL_MINIMUM;
431 if ((logfp != NULL) && (logfp != stderr))
433 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
442 /* set the designated log file */
445 if( NULL == (fp = fopen(logfname, "a")) )
447 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
450 /* set logging to be completely unbuffered */
458 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
459 if (prog_name != NULL)
461 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
466 } /* init_error_log */
468 #if defined(USE_NEW_LOG_ERROR)
470 * Use an alternative log_error version and its helper functions.
472 * The code is mostly copied from the old log_error
473 * function but it's divided into multiple functions,
474 * doesn't use strcpy, strcat or sprintf and compiles
475 * with gcc43 without warnings (on FreeBSD that is).
477 * It should behave like the old log_error function with
480 * - too long format strings are logged truncated instead
481 * of completely replaced with the truncation warning,
482 * - its time stamps contain milliseconds.
485 /*********************************************************************
487 * Function : get_thread_id
489 * Description : Returns a number that is different for each thread.
491 * XXX: Should be moved elsewhere (miscutil.c?)
495 * Returns : thread_id
497 *********************************************************************/
498 long get_thread_id(void)
500 long this_thread = 1; /* was: pthread_t this_thread;*/
504 APIRET ulrc; /* XXX: I have no clue what this does */
507 /* FIXME get current thread id */
508 #ifdef FEATURE_PTHREAD
509 this_thread = (long)pthread_self();
512 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
513 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
514 * pthread_t is supposed to be opaque... but it's fairly random, though, so
515 * we make it mostly presentable.
517 this_thread = abs(this_thread % 1000);
518 #endif /* def __MACH__ */
519 #elif defined(_WIN32)
520 this_thread = GetCurrentThreadId();
521 #elif defined(__OS2__)
522 ulrc = DosGetInfoBlocks(&ptib, NULL);
524 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
525 #endif /* def FEATURE_PTHREAD */
531 /*********************************************************************
533 * Function : get_log_timestamp
535 * Description : Generates the time stamp for the log message prefix.
538 * 1 : buffer = Storage buffer
539 * 2 : buffer_size = Size of storage buffer
541 * Returns : Number of written characters or 0 for error.
543 *********************************************************************/
544 static inline size_t get_log_timestamp(char *buffer, size_t buffer_size)
549 struct timeval tv_now; /* XXX: stupid name */
550 gettimeofday(&tv_now, NULL);
551 long msecs = tv_now.tv_usec / 1000;
552 int msecs_length = 0;
556 #ifdef HAVE_LOCALTIME_R
557 tm_now = *localtime_r(&now, &tm_now);
558 #elif FEATURE_PTHREAD
559 pthread_mutex_lock(&localtime_mutex);
560 tm_now = *localtime(&now);
561 pthread_mutex_unlock(&localtime_mutex);
563 tm_now = *localtime(&now);
566 length = strftime(buffer, buffer_size, "%b %d %H:%M:%S", &tm_now);
569 msecs_length = snprintf(buffer+length, buffer_size - length, ".%.3ld", msecs);
571 if (msecs_length > 0)
573 length += (size_t)msecs_length;
584 /*********************************************************************
586 * Function : get_clf_timestamp
588 * Description : Generates a Common Log Format time string.
591 * 1 : buffer = Storage buffer
592 * 2 : buffer_size = Size of storage buffer
594 * Returns : Number of written characters or 0 for error.
596 *********************************************************************/
597 static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size)
600 * Complex because not all OSs have tm_gmtoff or
601 * the %z field in strftime()
606 #ifdef HAVE_LOCALTIME_R
615 gmt = *gmtime_r(&now, &gmt);
616 #elif FEATURE_PTHREAD
617 pthread_mutex_lock(&gmtime_mutex);
619 pthread_mutex_unlock(&gmtime_mutex);
623 #ifdef HAVE_LOCALTIME_R
624 tm_now = localtime_r(&now, &dummy);
625 #elif FEATURE_PTHREAD
626 pthread_mutex_lock(&localtime_mutex);
627 tm_now = localtime(&now);
628 pthread_mutex_unlock(&localtime_mutex);
630 tm_now = localtime(&now);
632 days = tm_now->tm_yday - gmt.tm_yday;
633 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
634 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
636 length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now);
640 tz_length = snprintf(buffer+length, buffer_size-length,
641 "%+03d%02d", mins / 60, abs(mins) % 60);
645 length += (size_t)tz_length;
656 /*********************************************************************
658 * Function : get_log_level_string
660 * Description : Translates a numerical loglevel into a string.
663 * 1 : loglevel = LOG_LEVEL_FOO
665 * Returns : Log level string.
667 *********************************************************************/
668 inline const char *get_log_level_string(int loglevel)
670 char *log_level_string = NULL;
672 assert(0 < loglevel);
676 case LOG_LEVEL_ERROR:
677 log_level_string = "Error";
679 case LOG_LEVEL_FATAL:
680 log_level_string = "Fatal error";
683 log_level_string = "Request";
685 case LOG_LEVEL_CONNECT:
686 log_level_string = "Connect";
689 log_level_string = "Writing";
691 case LOG_LEVEL_HEADER:
692 log_level_string = "Header";
695 log_level_string = "Info";
697 case LOG_LEVEL_RE_FILTER:
698 log_level_string = "Re-Filter";
700 #ifdef FEATURE_FORCE_LOAD
701 case LOG_LEVEL_FORCE:
702 log_level_string = "Force";
704 #endif /* def FEATURE_FORCE_LOAD */
705 #ifdef FEATURE_FAST_REDIRECTS
706 case LOG_LEVEL_REDIRECTS:
707 log_level_string = "Redirect";
709 #endif /* def FEATURE_FAST_REDIRECTS */
710 case LOG_LEVEL_DEANIMATE:
711 log_level_string = "Gif-Deanimate";
713 #ifdef FEATURE_KILL_POPUPS
714 case LOG_LEVEL_POPUPS:
715 log_level_string = "Kill-Popups";
717 #endif /* def FEATURE_KILL_POPUPS */
719 log_level_string = "CGI";
722 log_level_string = "Unknown log level";
725 assert(NULL != log_level_string);
727 return log_level_string;
731 /*********************************************************************
733 * Function : log_error
735 * Description : This is the error-reporting and logging function.
738 * 1 : loglevel = the type of message to be logged
739 * 2 : fmt = the main string we want logged, printf-like
740 * 3 : ... = arguments to be inserted in fmt (printf-like).
744 *********************************************************************/
745 void log_error(int loglevel, const char *fmt, ...)
749 static char *outbuf_save = NULL;
750 char tempbuf[BUFFER_SIZE];
752 const char * src = fmt;
756 * XXX: Make this a config option,
757 * why else do we allocate instead of using
760 size_t log_buffer_size = BUFFER_SIZE;
762 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
764 * Irrespective of debug setting, a GET/POST/CONNECT makes
765 * the taskbar icon animate. (There is an option to disable
766 * this but checking that is handled inside LogShowActivity()).
768 if (loglevel == LOG_LEVEL_GPC)
772 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
774 /* verify if loglevel applies to current settings and bail out if negative */
775 if ((loglevel & debug) == 0)
780 thread_id = get_thread_id();
781 get_log_timestamp(timestamp, sizeof(timestamp));
783 /* protect the whole function because of the static buffer (outbuf) */
786 if (NULL == outbuf_save)
788 outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */
789 if (NULL == outbuf_save)
791 snprintf(tempbuf, sizeof(tempbuf),
792 "%s Privoxy(%08lx) Fatal error: log_error() failed to allocate buffer memory.\n"
793 "\nExiting.", timestamp, thread_id);
798 fputs(tempbuf, logfp);
800 fatal_error(tempbuf); /* Exit */
803 outbuf = outbuf_save;
806 * Memsetting the whole buffer to zero
807 * here make things easier later on.
809 memset(outbuf, 0, log_buffer_size);
811 /* Add prefix for everything but Common Log Format messages */
812 if (loglevel != LOG_LEVEL_CLF)
814 length = (size_t)snprintf(outbuf, log_buffer_size, "%s Privoxy(%08lx) %s: ",
815 timestamp, thread_id, get_log_level_string(loglevel));
818 /* get ready to scan var. args. */
821 /* build formatted message from fmt and var-args */
822 while ((*src) && (length < log_buffer_size-2))
824 const char *sval = NULL; /* %N string */
825 int ival; /* %N string length or an error code */
826 unsigned uval; /* %u value */
827 long lval; /* %l value */
828 unsigned long ulval; /* %ul value */
830 const char *format_string = tempbuf;
835 outbuf[length++] = ch;
836 assert(outbuf[length] == '\0');
839 assert(outbuf[length] == '\0');
847 ival = va_arg( ap, int );
848 snprintf(tempbuf, sizeof(tempbuf), "%d", ival);
851 uval = va_arg( ap, unsigned );
852 snprintf(tempbuf, sizeof(tempbuf), "%u", uval);
855 /* this is a modifier that must be followed by u or d */
859 lval = va_arg( ap, long );
860 snprintf(tempbuf, sizeof(tempbuf), "%ld", lval);
864 ulval = va_arg( ap, unsigned long );
865 snprintf(tempbuf, sizeof(tempbuf), "%lu", ulval);
869 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
870 loglevel = LOG_LEVEL_FATAL;
875 * Note that char paramaters are converted to int, so we need to
876 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
878 tempbuf[0] = (char) va_arg(ap, int);
882 format_string = va_arg(ap, char *);
883 if (format_string == NULL)
885 format_string = "[null]";
890 * Non-standard: Print a counted unterminated string.
891 * Takes 2 parameters: int length, const char * string.
893 ival = va_arg(ap, int);
894 sval = va_arg(ap, char *);
897 format_string = "[null]";
903 /* That's ok (but stupid) */
909 * That's not ok (and even more stupid)
912 format_string = "[counted string lenght < 0]";
915 else if (ival >= sizeof(tempbuf))
918 * String is too long, copy as much as possible.
919 * It will be further truncated later.
921 memcpy(tempbuf, sval, sizeof(tempbuf)-1);
922 tempbuf[sizeof(tempbuf)-1] = '\0';
926 memcpy(tempbuf, sval, (size_t) ival);
927 tempbuf[ival] = '\0';
931 /* Non-standard: Print error code from errno */
933 ival = WSAGetLastError();
934 format_string = w32_socket_strerr(ival, tempbuf);
939 format_string = os2_socket_strerr(ival, tempbuf);
944 format_string = strerror(ival);
946 #else /* ifndef _WIN32 */
949 format_string = strerror(ival);
950 #else /* ifndef HAVE_STRERROR */
951 format_string = NULL;
952 #endif /* ndef HAVE_STRERROR */
955 snprintf(tempbuf, sizeof(tempbuf), "(errno = %d)", ival);
957 #endif /* ndef _WIN32 */
960 /* Non-standard: Print a Common Log File timestamp */
961 get_clf_timestamp(tempbuf, sizeof(tempbuf));
964 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
965 loglevel = LOG_LEVEL_FATAL;
969 assert(length < log_buffer_size);
970 length += strlcpy(outbuf + length, format_string, log_buffer_size - length);
972 if (length >= log_buffer_size-2)
974 static char warning[] = "... [too long, truncated]";
976 length = log_buffer_size - sizeof(warning) - 1;
977 length += strlcpy(outbuf + length, warning, log_buffer_size - length);
978 assert(length < log_buffer_size);
984 /* done with var. args */
987 assert(length < log_buffer_size);
988 length += strlcpy(outbuf + length, "\n", log_buffer_size - length);
990 /* Some sanity checks */
991 if (!(length < log_buffer_size)
992 || !(outbuf[log_buffer_size-1] == '\0')
993 || !(outbuf[log_buffer_size] == '\0')
996 /* Repeat as assertions */
997 assert(length < log_buffer_size);
998 assert(outbuf[log_buffer_size-1] == '\0');
1000 * outbuf's real size is log_buffer_size+1,
1001 * so while this looks like an off-by-one,
1002 * we're only checking our paranoia byte.
1004 assert(outbuf[log_buffer_size] == '\0');
1006 snprintf(outbuf, log_buffer_size,
1007 "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %u\n"
1008 "Exiting.", timestamp, thread_id, length);
1009 loglevel = LOG_LEVEL_FATAL;
1012 /* deal with glibc stupidity - it won't let you initialize logfp */
1013 /* XXX: Still necessary? */
1019 fputs(outbuf_save, logfp);
1021 if (loglevel == LOG_LEVEL_FATAL)
1023 fatal_error(outbuf_save);
1024 /* Never get here */
1029 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1030 /* Write to display */
1031 LogPutString(outbuf_save);
1032 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1036 #else /* use traditional log_error version */
1038 /*********************************************************************
1040 * Function : log_error
1042 * Description : This is the error-reporting and logging function.
1045 * 1 : loglevel = the type of message to be logged
1046 * 2 : fmt = the main string we want logged, printf-like
1047 * 3 : ... = arguments to be inserted in fmt (printf-like).
1051 *********************************************************************/
1052 void log_error(int loglevel, const char *fmt, ...)
1056 static char *outbuf_save = NULL;
1057 const char * src = fmt;
1059 long this_thread = 1; /* was: pthread_t this_thread;*/
1063 #endif /* __OS2__ */
1065 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1067 * Irrespective of debug setting, a GET/POST/CONNECT makes
1068 * the taskbar icon animate. (There is an option to disable
1069 * this but checking that is handled inside LogShowActivity()).
1071 if (loglevel == LOG_LEVEL_GPC)
1075 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1077 /* verify if loglevel applies to current settings and bail out if negative */
1078 if ((loglevel & debug) == 0)
1083 /* protect the whole function because of the static buffer (outbuf) */
1086 /* FIXME get current thread id */
1087 #ifdef FEATURE_PTHREAD
1088 this_thread = (long)pthread_self();
1091 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
1092 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
1093 * pthread_t is supposed to be opaque... but it's fairly random, though, so
1094 * we make it mostly presentable.
1096 this_thread = abs(this_thread % 1000);
1097 #endif /* def __MACH__ */
1098 #elif defined(_WIN32)
1099 this_thread = GetCurrentThreadId();
1100 #elif defined(__OS2__)
1101 ulrc = DosGetInfoBlocks(&ptib, NULL);
1103 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
1104 #endif /* def FEATURE_PTHREAD */
1108 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
1109 if (NULL == outbuf_save)
1111 fatal_error("Privoxy failed to allocate log buffer.");
1114 outbuf = outbuf_save;
1118 * Write timestamp into tempbuf.
1120 * Complex because not all OSs have tm_gmtoff or
1121 * the %z field in strftime()
1126 #ifdef HAVE_LOCALTIME_R
1127 tm_now = *localtime_r(&now, &tm_now);
1128 #elif FEATURE_PTHREAD
1129 pthread_mutex_lock(&localtime_mutex);
1130 tm_now = *localtime (&now);
1131 pthread_mutex_unlock(&localtime_mutex);
1133 tm_now = *localtime (&now);
1135 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1136 outbuf += strlen( outbuf );
1140 case LOG_LEVEL_ERROR:
1141 outc = sprintf(outbuf, "Privoxy(%08lx) Error: ", this_thread);
1143 case LOG_LEVEL_FATAL:
1144 outc = sprintf(outbuf, "Privoxy(%08lx) Fatal error: ", this_thread);
1147 outc = sprintf(outbuf, "Privoxy(%08lx) Request: ", this_thread);
1149 case LOG_LEVEL_CONNECT:
1150 outc = sprintf(outbuf, "Privoxy(%08lx) Connect: ", this_thread);
1153 outc = sprintf(outbuf, "Privoxy(%08lx) Writing: ", this_thread);
1155 case LOG_LEVEL_HEADER:
1156 outc = sprintf(outbuf, "Privoxy(%08lx) Header: ", this_thread);
1158 case LOG_LEVEL_INFO:
1159 outc = sprintf(outbuf, "Privoxy(%08lx) Info: ", this_thread);
1161 case LOG_LEVEL_RE_FILTER:
1162 outc = sprintf(outbuf, "Privoxy(%08lx) Re-Filter: ", this_thread);
1164 #ifdef FEATURE_FORCE_LOAD
1165 case LOG_LEVEL_FORCE:
1166 outc = sprintf(outbuf, "Privoxy(%08lx) Force: ", this_thread);
1168 #endif /* def FEATURE_FORCE_LOAD */
1169 #ifdef FEATURE_FAST_REDIRECTS
1170 case LOG_LEVEL_REDIRECTS:
1171 outc = sprintf(outbuf, "Privoxy(%08lx) Redirect: ", this_thread);
1173 #endif /* def FEATURE_FAST_REDIRECTS */
1174 case LOG_LEVEL_DEANIMATE:
1175 outc = sprintf(outbuf, "Privoxy(%08lx) Gif-Deanimate: ", this_thread);
1178 outbuf = outbuf_save;
1182 #ifdef FEATURE_KILL_POPUPS
1183 case LOG_LEVEL_POPUPS:
1184 outc = sprintf(outbuf, "Privoxy(%08lx) Kill-Popups: ", this_thread);
1186 #endif /* def FEATURE_KILL_POPUPS */
1188 outc = sprintf(outbuf, "Privoxy(%08lx) CGI: ", this_thread);
1191 outc = sprintf(outbuf, "Privoxy(%08lx) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
1195 /* get ready to scan var. args. */
1196 va_start( ap, fmt );
1198 /* build formatted message from fmt and var-args */
1199 while ((*src) && (outc < BUFFER_SIZE-2))
1201 char tempbuf[BUFFER_SIZE];
1206 unsigned long ulval;
1213 outbuf[outc++] = ch;
1220 outbuf[outc++] = '%';
1223 ival = va_arg( ap, int );
1225 outc += sprintf(tempbuf, "%d", ival);
1226 if (outc < BUFFER_SIZE-1)
1228 strcpy(outbuf + oldoutc, tempbuf);
1232 outbuf[oldoutc] = '\0';
1236 uval = va_arg( ap, unsigned );
1238 outc += sprintf(tempbuf, "%u", uval);
1239 if (outc < BUFFER_SIZE-1)
1241 strcpy(outbuf + oldoutc, tempbuf);
1245 outbuf[oldoutc] = '\0';
1249 /* this is a modifier that must be followed by u or d */
1253 lval = va_arg( ap, long );
1255 outc += sprintf(tempbuf, "%ld", lval);
1259 ulval = va_arg( ap, unsigned long );
1261 outc += sprintf(tempbuf, "%lu", ulval);
1266 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1268 "Exiting.", this_thread, fmt);
1273 fputs(outbuf, logfp);
1274 fatal_error(outbuf);
1275 /* Never get here */
1278 if (outc < BUFFER_SIZE-1)
1280 strcpy(outbuf + oldoutc, tempbuf);
1284 outbuf[oldoutc] = '\0';
1289 * Note that char paramaters are converted to int, so we need to
1290 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
1292 outbuf[outc++] = (char) va_arg( ap, int );
1295 sval = va_arg( ap, char * );
1301 outc += strlen(sval);
1302 if (outc < BUFFER_SIZE-1)
1304 strcpy(outbuf + oldoutc, sval);
1308 outbuf[oldoutc] = '\0';
1312 /* Non-standard: Print a counted string. Takes 2 parameters:
1313 * int length, const char * string
1315 ival = va_arg( ap, int );
1316 sval = va_arg( ap, char * );
1327 if (outc < BUFFER_SIZE-1)
1329 memcpy(outbuf + oldoutc, sval, (size_t) ival);
1333 outbuf[oldoutc] = '\0';
1337 /* Non-standard: Print error code from errno */
1339 ival = WSAGetLastError();
1340 sval = w32_socket_strerr(ival, tempbuf);
1342 ival = sock_errno();
1344 sval = os2_socket_strerr(ival, tempbuf);
1348 sval = strerror(ival);
1350 #else /* ifndef _WIN32 */
1352 #ifdef HAVE_STRERROR
1353 sval = strerror(ival);
1354 #else /* ifndef HAVE_STRERROR */
1356 #endif /* ndef HAVE_STRERROR */
1359 sprintf(tempbuf, "(errno = %d)", ival);
1362 #endif /* ndef _WIN32 */
1364 outc += strlen(sval);
1365 if (outc < BUFFER_SIZE-1)
1367 strcpy(outbuf + oldoutc, sval);
1371 outbuf[oldoutc] = '\0';
1375 /* Non-standard: Print a Common Log File timestamp */
1378 * Write timestamp into tempbuf.
1380 * Complex because not all OSs have tm_gmtoff or
1381 * the %z field in strftime()
1386 #ifdef HAVE_LOCALTIME_R
1389 int days, hrs, mins;
1391 #ifdef HAVE_GMTIME_R
1392 gmt = *gmtime_r(&now, &gmt);
1393 #elif FEATURE_PTHREAD
1394 pthread_mutex_lock(&gmtime_mutex);
1395 gmt = *gmtime(&now);
1396 pthread_mutex_unlock(&gmtime_mutex);
1398 gmt = *gmtime(&now);
1400 #ifdef HAVE_LOCALTIME_R
1401 tm_now = localtime_r(&now, &dummy);
1402 #elif FEATURE_PTHREAD
1403 pthread_mutex_lock(&localtime_mutex);
1404 tm_now = localtime (&now);
1405 pthread_mutex_unlock(&localtime_mutex);
1407 tm_now = localtime (&now);
1409 days = tm_now->tm_yday - gmt.tm_yday;
1410 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
1411 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
1412 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
1413 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
1416 outc += strlen(tempbuf);
1417 if (outc < BUFFER_SIZE-1)
1419 strcpy(outbuf + oldoutc, tempbuf);
1423 outbuf[oldoutc] = '\0';
1427 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1429 "Exiting.", this_thread, fmt);
1434 fputs(outbuf_save, logfp);
1436 fatal_error(outbuf_save);
1437 /* Never get here */
1442 } /* for( p ... ) */
1444 /* done with var. args */
1447 if (outc >= BUFFER_SIZE-2)
1449 /* insufficient room for newline and trailing null. */
1451 static const char warning[] = "... [too long, truncated]\n";
1453 if (outc < BUFFER_SIZE)
1455 /* Need to add terminating null in this case. */
1456 outbuf[outc] = '\0';
1459 /* Truncate output */
1460 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
1462 /* Append warning */
1463 strcat(outbuf, warning);
1467 /* Add terminating newline and null */
1468 outbuf[outc++] = '\n';
1469 outbuf[outc] = '\0';
1472 /* deal with glibc stupidity - it won't let you initialize logfp */
1478 fputs(outbuf_save, logfp);
1480 if (loglevel == LOG_LEVEL_FATAL)
1482 fatal_error(outbuf_save);
1483 /* Never get here */
1488 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1489 /* Write to display */
1490 LogPutString(outbuf_save);
1491 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1494 #endif /* defined(USE_NEW_LOG_ERROR) */
1498 /*********************************************************************
1500 * Function : w32_socket_strerr
1502 * Description : Translate the return value from WSAGetLastError()
1506 * 1 : errcode = The return value from WSAGetLastError().
1507 * 2 : tmp_buf = A temporary buffer that might be used to
1510 * Returns : String representing the error code. This may be
1511 * a global string constant or a string stored in
1514 *********************************************************************/
1515 static char *w32_socket_strerr(int errcode, char *tmp_buf)
1517 #define TEXT_FOR_ERROR(code,text) \
1518 if (errcode == code) \
1520 return #code " - " text; \
1523 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
1524 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
1525 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
1526 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
1527 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
1528 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
1529 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
1530 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
1531 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
1532 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
1533 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
1534 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
1535 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
1536 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
1537 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
1538 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
1539 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
1540 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
1541 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
1542 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
1543 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
1544 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
1545 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
1546 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
1547 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
1548 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
1549 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
1550 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
1551 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
1552 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
1553 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
1554 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
1555 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
1556 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
1557 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
1558 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
1559 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
1560 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
1561 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
1562 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
1563 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
1564 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
1566 * The following error codes are documented in the Microsoft WinSock
1567 * reference guide, but don't actually exist.
1569 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
1570 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
1571 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
1572 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
1573 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
1574 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
1575 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
1576 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
1577 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
1578 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
1581 sprintf(tmp_buf, "(error number %d)", errcode);
1584 #endif /* def _WIN32 */
1588 /*********************************************************************
1590 * Function : os2_socket_strerr
1592 * Description : Translate the return value from sock_errno()
1596 * 1 : errcode = The return value from sock_errno().
1597 * 2 : tmp_buf = A temporary buffer that might be used to
1600 * Returns : String representing the error code. This may be
1601 * a global string constant or a string stored in
1604 *********************************************************************/
1605 static char *os2_socket_strerr(int errcode, char *tmp_buf)
1607 #define TEXT_FOR_ERROR(code,text) \
1608 if (errcode == code) \
1610 return #code " - " text; \
1613 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
1614 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
1615 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
1616 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
1617 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
1618 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
1619 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
1620 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
1621 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
1622 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
1623 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
1624 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
1625 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
1626 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
1627 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
1628 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
1629 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
1630 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
1631 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
1632 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
1633 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
1634 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
1635 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
1636 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
1637 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
1638 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
1639 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
1640 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
1641 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
1642 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
1643 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
1644 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
1645 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
1646 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
1647 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
1648 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
1649 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
1650 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
1651 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
1652 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
1653 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
1654 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
1655 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
1657 sprintf(tmp_buf, "(error number %d)", errcode);
1660 #endif /* def __OS2__ */