1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 08_log_pthread.dpatch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Fix race conditions in log writing functions (Closes: #299662).
8 diff -urNad privoxy-dpatch~/errlog.c privoxy-dpatch/errlog.c
9 --- privoxy-dpatch~/errlog.c 2006-02-05 16:17:43.000000000 +0100
10 +++ privoxy-dpatch/errlog.c 2006-02-05 16:18:06.000000000 +0100
12 static char *os2_socket_strerr(int errcode, char *tmp_buf);
15 +#ifdef FEATURE_PTHREAD
16 +static inline void lock_logfile()
18 + pthread_mutex_lock(&log_mutex);
20 +static inline void unlock_logfile()
22 + pthread_mutex_unlock(&log_mutex);
24 +static inline void lock_loginit()
26 + pthread_mutex_lock(&log_init_mutex);
28 +static inline void unlock_loginit()
30 + pthread_mutex_unlock(&log_init_mutex);
32 +#else /* ! FEATURE_PTHREAD */
33 +static inline void lock_logfile() {}
34 +static inline void unlock_logfile() {}
35 +static inline void lock_loginit() {}
36 +static inline void unlock_loginit() {}
39 /*********************************************************************
41 * Function : fatal_error
46 - /* FIXME RACE HAZARD: should start critical section error_log_use here */
49 /* set the logging detail level */
50 debug = debuglevel | LOG_LEVEL_MINIMUM;
52 if ((logfp != NULL) && (logfp != stderr))
54 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
63 /* set the designated log file */
66 /* set logging to be completely unbuffered */
74 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
76 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
79 - /* FIXME RACE HAZARD: should end critical section error_log_use here */
82 } /* init_error_log */
88 + /* protect the whole function because of the static buffer (outbuf) */
91 /* FIXME get current thread id */
92 #ifdef FEATURE_PTHREAD
93 this_thread = (long)pthread_self();
98 - outc = sprintf(outbuf, "Privoxy(%05ld) Error: ", this_thread);
99 + outc = sprintf(outbuf, "Privoxy(%08lx) Error: ", this_thread);
101 case LOG_LEVEL_FATAL:
102 - outc = sprintf(outbuf, "Privoxy(%05ld) Fatal error: ", this_thread);
103 + outc = sprintf(outbuf, "Privoxy(%08lx) Fatal error: ", this_thread);
106 - outc = sprintf(outbuf, "Privoxy(%05ld) Request: ", this_thread);
107 + outc = sprintf(outbuf, "Privoxy(%08lx) Request: ", this_thread);
109 case LOG_LEVEL_CONNECT:
110 - outc = sprintf(outbuf, "Privoxy(%05ld) Connect: ", this_thread);
111 + outc = sprintf(outbuf, "Privoxy(%08lx) Connect: ", this_thread);
114 - outc = sprintf(outbuf, "Privoxy(%05ld) Writing: ", this_thread);
115 + outc = sprintf(outbuf, "Privoxy(%08lx) Writing: ", this_thread);
117 case LOG_LEVEL_HEADER:
118 - outc = sprintf(outbuf, "Privoxy(%05ld) Header: ", this_thread);
119 + outc = sprintf(outbuf, "Privoxy(%08lx) Header: ", this_thread);
122 - outc = sprintf(outbuf, "Privoxy(%05ld) Info: ", this_thread);
123 + outc = sprintf(outbuf, "Privoxy(%08lx) Info: ", this_thread);
125 case LOG_LEVEL_RE_FILTER:
126 - outc = sprintf(outbuf, "Privoxy(%05ld) Re-Filter: ", this_thread);
127 + outc = sprintf(outbuf, "Privoxy(%08lx) Re-Filter: ", this_thread);
129 #ifdef FEATURE_FORCE_LOAD
130 case LOG_LEVEL_FORCE:
131 - outc = sprintf(outbuf, "Privoxy(%05ld) Force: ", this_thread);
132 + outc = sprintf(outbuf, "Privoxy(%08lx) Force: ", this_thread);
134 #endif /* def FEATURE_FORCE_LOAD */
135 #ifdef FEATURE_FAST_REDIRECTS
136 case LOG_LEVEL_REDIRECTS:
137 - outc = sprintf(outbuf, "Privoxy(%05ld) Redirect: ", this_thread);
138 + outc = sprintf(outbuf, "Privoxy(%08lx) Redirect: ", this_thread);
140 #endif /* def FEATURE_FAST_REDIRECTS */
141 case LOG_LEVEL_DEANIMATE:
142 - outc = sprintf(outbuf, "Privoxy(%05ld) Gif-Deanimate: ", this_thread);
143 + outc = sprintf(outbuf, "Privoxy(%08lx) Gif-Deanimate: ", this_thread);
146 outbuf = outbuf_save;
147 @@ -523,14 +556,14 @@
149 #ifdef FEATURE_KILL_POPUPS
150 case LOG_LEVEL_POPUPS:
151 - outc = sprintf(outbuf, "Privoxy(%05ld) Kill-Popups: ", this_thread);
152 + outc = sprintf(outbuf, "Privoxy(%08lx) Kill-Popups: ", this_thread);
154 #endif /* def FEATURE_KILL_POPUPS */
156 - outc = sprintf(outbuf, "Privoxy(%05ld) CGI: ", this_thread);
157 + outc = sprintf(outbuf, "Privoxy(%08lx) CGI: ", this_thread);
160 - outc = sprintf(outbuf, "Privoxy(%05ld) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
161 + outc = sprintf(outbuf, "Privoxy(%08lx) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
165 @@ -605,16 +638,14 @@
169 - sprintf(outbuf, "Privoxy(%ld) Error: log_error(): Bad format string:\n"
170 + sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
172 "Exiting.", this_thread, fmt);
173 - /* FIXME RACE HAZARD: should start critical section error_log_use here */
178 fputs(outbuf, logfp);
179 - /* FIXME RACE HAZARD: should end critical section error_log_use here */
183 @@ -768,16 +799,15 @@
187 - sprintf(outbuf, "Privoxy(%ld) Error: log_error(): Bad format string:\n"
188 + sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
190 "Exiting.", this_thread, fmt);
191 - /* FIXME RACE HAZARD: should start critical section error_log_use here */
196 fputs(outbuf_save, logfp);
197 - /* FIXME RACE HAZARD: should end critical section error_log_use here */
199 fatal_error(outbuf_save);
206 - /* FIXME RACE HAZARD: should start critical section error_log_use here */
208 /* deal with glibc stupidity - it won't let you initialize logfp */
215 - /* FIXME RACE HAZARD: should end critical section error_log_use here */
218 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
219 /* Write to display */
220 diff -urNad privoxy-dpatch~/jcc.c privoxy-dpatch/jcc.c
221 --- privoxy-dpatch~/jcc.c 2006-02-05 16:17:43.000000000 +0100
222 +++ privoxy-dpatch/jcc.c 2006-02-05 16:18:06.000000000 +0100
224 pthread_mutex_t gethostbyaddr_mutex;
225 pthread_mutex_t gethostbyname_mutex;
226 #endif /* def OSX_DARWIN */
227 +#ifdef FEATURE_PTHREAD
228 +pthread_mutex_t log_mutex;
229 +pthread_mutex_t log_init_mutex;
230 +#endif /* FEATURE_PTHREAD */
232 #if defined(unix) || defined(__EMX__)
233 const char *basedir = NULL;
234 @@ -1923,7 +1927,10 @@
235 pthread_mutex_init(&gethostbyaddr_mutex,0);
236 pthread_mutex_init(&gethostbyname_mutex,0);
237 #endif /* def OSX_DARWIN */
239 +#ifdef FEATURE_PTHREAD
240 + pthread_mutex_init(&log_mutex,0);
241 + pthread_mutex_init(&log_init_mutex,0);
242 +#endif /* FEATURE_PTHREAD */
244 * Unix signal handling
246 diff -urNad privoxy-dpatch~/jcc.h privoxy-dpatch/jcc.h
247 --- privoxy-dpatch~/jcc.h 2006-02-05 16:17:43.000000000 +0100
248 +++ privoxy-dpatch/jcc.h 2006-02-05 16:18:06.000000000 +0100
250 extern pthread_mutex_t gethostbyaddr_mutex;
251 extern pthread_mutex_t gethostbyname_mutex;
252 #endif /* def OSX_DARWIN */
253 +#ifdef FEATURE_PTHREAD
254 +extern pthread_mutex_t log_mutex;
255 +extern pthread_mutex_t log_init_mutex;
256 +#endif /* FEATURE_PTHREAD */