X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=errlog.c;h=927289ff45ad1de44af54deefb4ad6bb0059cae1;hp=ddcc39b2b44c60cadb4538d1a7408972fb447b5e;hb=f82b06d9dd4c8a25437659dff457c8c60a529f32;hpb=932f6a29501949c99204c8f2ed8ae7d9704e53af diff --git a/errlog.c b/errlog.c index ddcc39b2..927289ff 100644 --- a/errlog.c +++ b/errlog.c @@ -1,4 +1,4 @@ -const char errlog_rcs[] = "$Id: errlog.c,v 1.115 2012/07/27 17:27:47 fabiankeil Exp $"; +const char errlog_rcs[] = "$Id: errlog.c,v 1.125 2016/01/26 17:12:14 diem Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $ @@ -6,7 +6,7 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.115 2012/07/27 17:27:47 fabiankeil * Purpose : Log errors to a designated destination in an elegant, * printf-like fashion. * - * Copyright : Written by and Copyright (C) 2001-2010 the + * Copyright : Written by and Copyright (C) 2001-2014 the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -75,6 +75,9 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.115 2012/07/27 17:27:47 fabiankeil #include "errlog.h" #include "project.h" #include "jcc.h" +#ifdef FEATURE_EXTERNAL_FILTERS +#include "jbsockets.h" +#endif const char errlog_h_rcs[] = ERRLOG_H_VERSION; @@ -146,25 +149,27 @@ static inline void unlock_loginit() {} *********************************************************************/ static void fatal_error(const char *error_message) { -#if defined(_WIN32) && !defined(_WIN_CONSOLE) - /* Skip timestamp and thread id for the message box. */ - const char *box_message = strstr(error_message, "Fatal error"); - if (NULL == box_message) + if (logfp != NULL) { - /* Shouldn't happen but ... */ - box_message = error_message; + fputs(error_message, logfp); } - MessageBox(g_hwndLogFrame, box_message, "Privoxy Error", - MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST); - - /* Cleanup - remove taskbar icon etc. */ - TermLogWindow(); -#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */ - if (logfp != NULL) +#if defined(_WIN32) && !defined(_WIN_CONSOLE) { - fputs(error_message, logfp); + /* Skip timestamp and thread id for the message box. */ + const char *box_message = strstr(error_message, "Fatal error"); + if (NULL == box_message) + { + /* Shouldn't happen but ... */ + box_message = error_message; + } + MessageBox(g_hwndLogFrame, box_message, "Privoxy Error", + MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST); + + /* Cleanup - remove taskbar icon etc. */ + TermLogWindow(); } +#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */ #if defined(unix) if (pidfile) @@ -352,6 +357,10 @@ void init_error_log(const char *prog_name, const char *logfname) log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: \'%s\'", logfname); } +#ifdef FEATURE_EXTERNAL_FILTERS + mark_socket_for_close_on_execute(3); +#endif + /* set logging to be completely unbuffered */ setbuf(fp, NULL); @@ -400,7 +409,7 @@ void init_error_log(const char *prog_name, const char *logfname) *********************************************************************/ static long get_thread_id(void) { - long this_thread = 1; /* was: pthread_t this_thread;*/ + long this_thread; #ifdef __OS2__ PTIB ptib; @@ -412,12 +421,11 @@ static long get_thread_id(void) this_thread = (long)pthread_self(); #ifdef __MACH__ /* - * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable - * value at the first 4 bytes of pthread_self()'s return value, a pthread_t. - * pthread_t is supposed to be opaque... but it's fairly random, though, so - * we make it mostly presentable. + * Mac OSX (and perhaps other Mach instances) doesn't have a unique + * value at the lowest order 4 bytes of pthread_self()'s return value, a pthread_t, + * so trim the three lowest-order bytes from the value (16^3). */ - this_thread = abs(this_thread % 1000); + this_thread = this_thread / 4096; #endif /* def __MACH__ */ #elif defined(_WIN32) this_thread = GetCurrentThreadId(); @@ -425,6 +433,9 @@ static long get_thread_id(void) ulrc = DosGetInfoBlocks(&ptib, NULL); if (ulrc == 0) this_thread = ptib -> tib_ptib2 -> tib2_ultid; +#else + /* Forking instead of threading. */ + this_thread = 1; #endif /* def FEATURE_PTHREAD */ return this_thread; @@ -634,6 +645,7 @@ static inline const char *get_log_level_string(int loglevel) } +#define LOG_BUFFER_SIZE BUFFER_SIZE /********************************************************************* * * Function : log_error @@ -653,7 +665,7 @@ void log_error(int loglevel, const char *fmt, ...) va_list ap; char *outbuf = NULL; static char *outbuf_save = NULL; - char tempbuf[BUFFER_SIZE]; + char tempbuf[LOG_BUFFER_SIZE]; size_t length = 0; const char * src = fmt; long thread_id; @@ -663,7 +675,7 @@ void log_error(int loglevel, const char *fmt, ...) * why else do we allocate instead of using * an array? */ - size_t log_buffer_size = BUFFER_SIZE; + size_t log_buffer_size = LOG_BUFFER_SIZE; #if defined(_WIN32) && !defined(_WIN_CONSOLE) /* @@ -704,15 +716,7 @@ void log_error(int loglevel, const char *fmt, ...) if (NULL == outbuf_save) { - outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */ - if (NULL == outbuf_save) - { - snprintf(tempbuf, sizeof(tempbuf), - "%s %08lx Fatal error: Out of memory in log_error().", - timestamp, thread_id); - fatal_error(tempbuf); /* Exit */ - return; - } + outbuf_save = zalloc_or_die(log_buffer_size + 1); /* +1 for paranoia */ } outbuf = outbuf_save; @@ -988,9 +992,6 @@ const char *jb_err_to_string(int jb_error) return "File has been modified outside of the CGI actions editor."; case JB_ERR_COMPRESS: return "(De)compression failure"; - default: - assert(0); - return "Unknown error"; } assert(0); return "Internal error";