From d9ab2562dfeadc4f1d2bcae73e9fae62208eaa8e Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 13 Nov 2006 19:05:51 +0000 Subject: [PATCH] Make pthread mutex locking more generic. Instead of checking for OSX and OpenBSD, check for FEATURE_PTHREAD and use mutex locking unless there is an _r function available. Better safe than sorry. Fixes "./configure --disable-pthread" and should result in less threading-related problems on pthread-using platforms, but it still doesn't fix BR#1122404. --- cgi.c | 16 +++++++++------ configure.in | 9 +++++--- errlog.c | 14 ++++++------- jbsockets.c | 14 ++++++++----- jcc.c | 58 +++++++++++++++++++++++++++++++--------------------- jcc.h | 22 +++++++++++++++----- parsers.c | 19 +++++++++-------- 7 files changed, 95 insertions(+), 57 deletions(-) diff --git a/cgi.c b/cgi.c index dd325955..da9d0870 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.77 2006/09/21 15:17:23 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.78 2006/09/21 19:22:07 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -38,6 +38,11 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.77 2006/09/21 15:17:23 fabiankeil Exp $"; * * Revisions : * $Log: cgi.c,v $ + * Revision 1.78 2006/09/21 19:22:07 fabiankeil + * Use CGI_PREFIX to check the referrer. + * The check for "http://config.privoxy.org/" fails + * if the user modified CGI_SITE_2_HOST. + * * Revision 1.77 2006/09/21 15:17:23 fabiankeil * Adjusted headers for Privoxy's cgi responses: * Don't set Last-Modified, Expires and Cache-Control @@ -513,7 +518,6 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.77 2006/09/21 15:17:23 fabiankeil Exp $"; #include "loadcfg.h" /* loadcfg.h is for global_toggle_state only */ #ifdef FEATURE_PTHREAD -#include #include "jcc.h" /* jcc.h is for mutex semaphore globals only */ #endif /* def FEATURE_PTHREAD */ @@ -1688,7 +1692,7 @@ void get_http_time(int time_offset, char *buf) struct tm *t; time_t current_time; -#if defined(HAVE_GMTIME_R) && !defined(OSX_DARWIN) +#if defined(HAVE_GMTIME_R) /* * Declare dummy up here (instead of inside get/set gmt block) so it * doesn't go out of scope before it's potentially used in snprintf later. @@ -1706,12 +1710,12 @@ void get_http_time(int time_offset, char *buf) /* get and save the gmt */ { -#ifdef OSX_DARWIN +#if HAVE_GMTIME_R + t = gmtime_r(¤t_time, &dummy); +#elif FEATURE_PTHREAD pthread_mutex_lock(&gmtime_mutex); t = gmtime(¤t_time); pthread_mutex_unlock(&gmtime_mutex); -#elif HAVE_GMTIME_R - t = gmtime_r(¤t_time, &dummy); #else t = gmtime(¤t_time); #endif diff --git a/configure.in b/configure.in index d6d5b715..c2b1ed44 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. dnl -dnl $Id: configure.in,v 1.92 2006/08/17 17:09:49 fabiankeil Exp $ +dnl $Id: configure.in,v 1.93 2006/09/22 01:26:20 hal9 Exp $ dnl dnl Written by and Copyright (C) 2001 - 2004 the SourceForge dnl Privoxy team. http://www.privoxy.org/ @@ -28,6 +28,9 @@ dnl or write to the Free Software Foundation, Inc., 59 dnl Temple Place - Suite 330, Boston, MA 02111-1307, USA. dnl dnl $Log: configure.in,v $ +dnl Revision 1.93 2006/09/22 01:26:20 hal9 +dnl Set version to 3.0.5 BETA for hopefully release this weekend. +dnl dnl Revision 1.92 2006/08/17 17:09:49 fabiankeil dnl Added check for timegm(). dnl @@ -444,7 +447,7 @@ dnl ================================================================= dnl AutoConf Initialization dnl ================================================================= -AC_REVISION($Revision: 1.92 $) +AC_REVISION($Revision: 1.93 $) AC_INIT(jcc.c) if test ! -f config.h.in; then @@ -1109,7 +1112,7 @@ AC_FUNC_SETPGRP AC_TYPE_SIGNAL dnl uncommenting does not work for swa. suse linux dnl AC_FUNC_STAT -AC_CHECK_FUNCS([atexit getcwd gethostbyaddr gethostbyname inet_ntoa localtime_r memchr memmove memset random regcomp select setlocale socket strchr strdup strerror strftime strptime strstr strtoul timegm]) +AC_CHECK_FUNCS([atexit getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r inet_ntoa localtime_r memchr memmove memset random regcomp select setlocale socket strchr strdup strerror strftime strptime strstr strtoul timegm]) dnl ================================================================= diff --git a/errlog.c b/errlog.c index 7fc78a38..01843ddd 100644 --- a/errlog.c +++ b/errlog.c @@ -1,4 +1,4 @@ -const char errlog_rcs[] = "$Id: errlog.c,v 1.44 2006/08/18 16:03:16 david__schmidt Exp $"; +const char errlog_rcs[] = "$Id: errlog.c,v 1.45 2006/08/21 11:15:54 david__schmidt Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $ @@ -33,6 +33,9 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.44 2006/08/18 16:03:16 david__schmi * * Revisions : * $Log: errlog.c,v $ + * Revision 1.45 2006/08/21 11:15:54 david__schmidt + * MS Visual C++ build updates + * * Revision 1.44 2006/08/18 16:03:16 david__schmidt * Tweak for OS/2 build happiness. * @@ -261,9 +264,6 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.44 2006/08/18 16:03:16 david__schmi #include #include -#ifdef FEATURE_PTHREAD -#include -#endif /* def FEATURE_PTHREAD */ #ifdef _WIN32 #ifndef STRICT @@ -526,7 +526,7 @@ void log_error(int loglevel, char *fmt, ...) time (&now); #ifdef HAVE_LOCALTIME_R tm_now = *localtime_r(&now, &tm_now); -#elif OSX_DARWIN +#elif FEATURE_PTHREAD pthread_mutex_lock(&localtime_mutex); tm_now = *localtime (&now); pthread_mutex_unlock(&localtime_mutex); @@ -791,7 +791,7 @@ void log_error(int loglevel, char *fmt, ...) time (&now); #ifdef HAVE_GMTIME_R gmt = *gmtime_r(&now, &gmt); -#elif OSX_DARWIN +#elif FEATURE_PTHREAD pthread_mutex_lock(&gmtime_mutex); gmt = *gmtime(&now); pthread_mutex_unlock(&gmtime_mutex); @@ -800,7 +800,7 @@ void log_error(int loglevel, char *fmt, ...) #endif #ifdef HAVE_LOCALTIME_R tm_now = localtime_r(&now, &dummy); -#elif OSX_DARWIN +#elif FEATURE_PTHREAD pthread_mutex_lock(&localtime_mutex); tm_now = localtime (&now); pthread_mutex_unlock(&localtime_mutex); diff --git a/jbsockets.c b/jbsockets.c index 0b7d8df1..1d43ebae 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.39 2006/08/03 02:46:41 david__schmidt Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.40 2006/09/02 15:36:42 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -35,6 +35,10 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.39 2006/08/03 02:46:41 david_ * * Revisions : * $Log: jbsockets.c,v $ + * Revision 1.40 2006/09/02 15:36:42 fabiankeil + * Follow the OpenBSD port's lead and protect the resolve + * functions on OpenBSD as well. + * * Revision 1.39 2006/08/03 02:46:41 david__schmidt * Incorporate Fabian Keil's patch work: http://www.fabiankeil.de/sourcecode/privoxy/ * @@ -263,10 +267,10 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.39 2006/08/03 02:46:41 david_ #include "project.h" -#if defined(OSX_DARWIN) || defined(__OpenBSD__) +#ifdef FEATURE_PTHREAD #include "jcc.h" /* jcc.h is for mutex semaphores only */ -#endif /* defined(OSX_DARWIN) || defined(__OpenBSD__) */ +#endif /* def FEATURE_PTHREAD */ #include "jbsockets.h" #include "filters.h" @@ -748,7 +752,7 @@ int accept_connection(struct client_state * csp, jb_socket fd) { host = NULL; } -#elif defined(OSX_DARWIN) || defined(__OpenBSD__) +#elif FEATURE_PTHREAD pthread_mutex_lock(&gethostbyaddr_mutex); host = gethostbyaddr((const char *)&server.sin_addr, sizeof(server.sin_addr), AF_INET); @@ -833,7 +837,7 @@ unsigned long resolve_hostname_to_ip(const char *host) { hostp = NULL; } -#elif defined(OSX_DARWIN) || defined(__OpenBSD__) +#elif FEATURE_PTHREAD pthread_mutex_lock(&gethostbyname_mutex); while ( NULL == (hostp = gethostbyname(host)) && (h_errno == TRY_AGAIN) && (dns_retries++ < 10) ) diff --git a/jcc.c b/jcc.c index 370ef7fd..73cdbcbb 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.105 2006/11/06 14:26:02 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.106 2006/11/06 19:58:23 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,10 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.105 2006/11/06 14:26:02 fabiankeil Exp $" * * Revisions : * $Log: jcc.c,v $ + * Revision 1.106 2006/11/06 19:58:23 fabiankeil + * Move pthread.h inclusion from jcc.c to jcc.h. + * Fixes build on x86-freebsd1 (FreeBSD 5.4-RELEASE). + * * Revision 1.105 2006/11/06 14:26:02 fabiankeil * Don't exit after receiving the second SIGHUP on Solaris. * @@ -790,24 +794,25 @@ static int32 server_thread(void *data); #define sleep(N) DosSleep(((N) * 100)) #endif -#if defined(OSX_DARWIN) || defined(__OpenBSD__) -#ifdef OSX_DARWIN -/* - * Hit OSX over the head with a hammer. Protect all *_r functions. - */ +#ifdef FEATURE_PTHREAD +pthread_mutex_t log_mutex; +pthread_mutex_t log_init_mutex; + +#ifndef HAVE_GMTIME_R pthread_mutex_t gmtime_mutex; +#endif /* ndef HAVE_GMTIME_R */ + +#ifndef HAVE_LOCALTIME_R pthread_mutex_t localtime_mutex; -#endif /* def OSX_DARWIN */ -/* - * Protect only the resolve functions for OpenBSD. - */ +#endif /* ndef HAVE_GMTIME_R */ + +#ifndef HAVE_GETHOSTBYADDR_R pthread_mutex_t gethostbyaddr_mutex; -pthread_mutex_t gethostbyname_mutex; -#endif /* defined(OSX_DARWIN) || defined(__OpenBSD__) */ +#endif /* ndef HAVE_GETHOSTBYADDR_R */ -#ifdef FEATURE_PTHREAD -pthread_mutex_t log_mutex; -pthread_mutex_t log_init_mutex; +#ifndef HAVE_GETHOSTBYNAME_R +pthread_mutex_t gethostbyname_mutex; +#endif /* ndef HAVE_GETHOSTBYNAME_R */ #endif /* FEATURE_PTHREAD */ #if defined(unix) || defined(__EMX__) @@ -2071,21 +2076,28 @@ int main(int argc, const char *argv[]) InitWin32(); #endif -#if defined(OSX_DARWIN) || defined(__OpenBSD__) +#ifdef FEATURE_PTHREAD /* * Prepare global mutex semaphores */ -#ifdef OSX_DARWIN + pthread_mutex_init(&log_mutex,0); + pthread_mutex_init(&log_init_mutex,0); + +#ifndef HAVE_GMTIME_R pthread_mutex_init(&gmtime_mutex,0); +#endif /* ndef HAVE_GMTIME_R */ + +#ifndef HAVE_LOCALTIME_R pthread_mutex_init(&localtime_mutex,0); -#endif /* def OSX_DARWIN */ +#endif /* ndef HAVE_GMTIME_R */ + +#ifndef HAVE_GETHOSTBYADDR_R pthread_mutex_init(&gethostbyaddr_mutex,0); - pthread_mutex_init(&gethostbyname_mutex,0); -#endif /* defined(OSX_DARWIN) || defined(__OpenBSD__) */ +#endif /* ndef HAVE_GETHOSTBYADDR_R */ -#ifdef FEATURE_PTHREAD - pthread_mutex_init(&log_mutex,0); - pthread_mutex_init(&log_init_mutex,0); +#ifndef HAVE_GETHOSTBYNAME_R + pthread_mutex_init(&gethostbyname_mutex,0); +#endif /* ndef HAVE_GETHOSTBYNAME_R */ #endif /* FEATURE_PTHREAD */ #ifdef HAVE_RANDOM diff --git a/jcc.h b/jcc.h index 5b49ff98..a4eb214f 100644 --- a/jcc.h +++ b/jcc.h @@ -1,6 +1,6 @@ #ifndef JCC_H_INCLUDED #define JCC_H_INCLUDED -#define JCC_H_VERSION "$Id: jcc.h,v 1.16 2006/09/02 15:36:42 fabiankeil Exp $" +#define JCC_H_VERSION "$Id: jcc.h,v 1.17 2006/11/06 19:58:23 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.h,v $ @@ -35,6 +35,10 @@ * * Revisions : * $Log: jcc.h,v $ + * Revision 1.17 2006/11/06 19:58:23 fabiankeil + * Move pthread.h inclusion from jcc.c to jcc.h. + * Fixes build on x86-freebsd1 (FreeBSD 5.4-RELEASE). + * * Revision 1.16 2006/09/02 15:36:42 fabiankeil * Follow the OpenBSD port's lead and protect the resolve * functions on OpenBSD as well. @@ -151,14 +155,22 @@ extern int g_terminate; #include extern pthread_mutex_t log_mutex; extern pthread_mutex_t log_init_mutex; -#if defined(OSX_DARWIN) || defined(__OpenBSD__) -#ifdef OSX_DARWIN + +#ifndef HAVE_GMTIME_R extern pthread_mutex_t gmtime_mutex; +#endif /* ndef HAVE_GMTIME_R */ + +#ifndef HAVE_LOCALTIME_R extern pthread_mutex_t localtime_mutex; -#endif /* def OSX_DARWIN */ +#endif /* ndef HAVE_GMTIME_R */ + +#ifndef HAVE_GETHOSTBYADDR_R extern pthread_mutex_t gethostbyaddr_mutex; +#endif /* ndef HAVE_GETHOSTBYADDR_R */ + +#ifndef HAVE_GETHOSTBYNAME_R extern pthread_mutex_t gethostbyname_mutex; -#endif /* defined(OSX_DARWIN) || defined(__OpenBSD__) */ +#endif /* ndef HAVE_GETHOSTBYNAME_R */ #endif /* FEATURE_PTHREAD */ /* Functions */ diff --git a/parsers.c b/parsers.c index f4e67ade..d56fde8b 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.73 2006/09/23 13:26:38 roro Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.74 2006/10/02 16:59:12 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -40,6 +40,10 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.73 2006/09/23 13:26:38 roro Exp $ * * Revisions : * $Log: parsers.c,v $ + * Revision 1.74 2006/10/02 16:59:12 fabiankeil + * The special header "X-Filter: No" now disables + * header filtering as well. + * * Revision 1.73 2006/09/23 13:26:38 roro * Replace TABs by spaces in source code. * @@ -535,11 +539,10 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.73 2006/09/23 13:26:38 roro Exp $ #include "project.h" -#ifdef OSX_DARWIN -#include +#ifdef FEATURE_PTHREAD #include "jcc.h" /* jcc.h is for mutex semapores only */ -#endif /* def OSX_DARWIN */ +#endif /* def FEATURE_PTHREAD */ #include "list.h" #include "parsers.h" #include "encode.h" @@ -1576,7 +1579,7 @@ jb_err server_last_modified(struct client_state *csp, char **header) now = time(NULL); #ifdef HAVE_GMTIME_R timeptr = gmtime_r(&now, &gmt); -#elif OSX_DARWIN +#elif FEATURE_PTHREAD pthread_mutex_lock(&gmtime_mutex); timeptr = gmtime(&now); pthread_mutex_unlock(&gmtime_mutex); @@ -1597,7 +1600,7 @@ jb_err server_last_modified(struct client_state *csp, char **header) last_modified += rtime; #ifdef HAVE_GMTIME_R timeptr = gmtime_r(&last_modified, &gmt); -#elif OSX_DARWIN +#elif FEATURE_PTHREAD pthread_mutex_lock(&gmtime_mutex); timeptr = gmtime(&last_modified); pthread_mutex_unlock(&gmtime_mutex); @@ -2346,7 +2349,7 @@ jb_err client_if_modified_since(struct client_state *csp, char **header) tm += rtime * (negative ? -1 : 1); #ifdef HAVE_GMTIME_R timeptr = gmtime_r(&tm, &gmt); -#elif OSX_DARWIN +#elif FEATURE_PTHREAD pthread_mutex_lock(&gmtime_mutex); timeptr = gmtime(&tm); pthread_mutex_unlock(&gmtime_mutex); @@ -2775,7 +2778,7 @@ jb_err server_set_cookie(struct client_state *csp, char **header) time (&now); #ifdef HAVE_LOCALTIME_R tm_now = *localtime_r(&now, &tm_now); -#elif OSX_DARWIN +#elif FEATURE_PTHREAD pthread_mutex_lock(&localtime_mutex); tm_now = *localtime (&now); pthread_mutex_unlock(&localtime_mutex); -- 2.39.2