layer of indirection before the pthread mutex functions.
-const char cgi_rcs[] = "$Id: cgi.c,v 1.111 2008/08/31 15:59:02 fabiankeil Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.112 2008/08/31 16:08:12 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgi.c,v $
*
* Revisions :
* $Log: cgi.c,v $
+ * Revision 1.112 2008/08/31 16:08:12 fabiankeil
+ * "View the request headers" isn't more equal than the other
+ * menu items and thus doesn't need a trailing dot either.
+ *
* Revision 1.111 2008/08/31 15:59:02 fabiankeil
* There's no reason to let remote toggling support depend
* on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't.
#if HAVE_GMTIME_R
t = gmtime_r(¤t_time, &dummy);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&gmtime_mutex);
+ privoxy_mutex_lock(&gmtime_mutex);
t = gmtime(¤t_time);
- pthread_mutex_unlock(&gmtime_mutex);
+ privoxy_mutex_unlock(&gmtime_mutex);
#else
t = gmtime(¤t_time);
#endif
#if HAVE_LOCALTIME_R
timeptr = localtime_r(¤t_time, &dummy);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&localtime_mutex);
+ privoxy_mutex_lock(&localtime_mutex);
timeptr = localtime(¤t_time);
- pthread_mutex_unlock(&localtime_mutex);
+ privoxy_mutex_unlock(&localtime_mutex);
#else
timeptr = localtime(¤t_time);
#endif
-const char errlog_rcs[] = "$Id: errlog.c,v 1.73 2008/08/04 19:06:55 fabiankeil Exp $";
+const char errlog_rcs[] = "$Id: errlog.c,v 1.74 2008/08/06 18:33:36 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
*
* Revisions :
* $Log: errlog.c,v $
+ * Revision 1.74 2008/08/06 18:33:36 fabiankeil
+ * If the "close fd first" workaround doesn't work,
+ * the fatal error message will be lost, so we better
+ * explain the consequences while we still can.
+ *
* Revision 1.73 2008/08/04 19:06:55 fabiankeil
* Add a lame workaround for the "can't open an already open
* logfile on OS/2" problem reported by Maynard in #2028842
#ifdef FEATURE_PTHREAD
static inline void lock_logfile(void)
{
- pthread_mutex_lock(&log_mutex);
+ privoxy_mutex_lock(&log_mutex);
}
static inline void unlock_logfile(void)
{
- pthread_mutex_unlock(&log_mutex);
+ privoxy_mutex_unlock(&log_mutex);
}
static inline void lock_loginit(void)
{
- pthread_mutex_lock(&log_init_mutex);
+ privoxy_mutex_lock(&log_init_mutex);
}
static inline void unlock_loginit(void)
{
- pthread_mutex_unlock(&log_init_mutex);
+ privoxy_mutex_unlock(&log_init_mutex);
}
#else /* ! FEATURE_PTHREAD */
/*
#ifdef HAVE_LOCALTIME_R
tm_now = *localtime_r(&now, &tm_now);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&localtime_mutex);
+ privoxy_mutex_lock(&localtime_mutex);
tm_now = *localtime(&now);
- pthread_mutex_unlock(&localtime_mutex);
+ privoxy_mutex_unlock(&localtime_mutex);
#else
tm_now = *localtime(&now);
#endif
#ifdef HAVE_GMTIME_R
gmt = *gmtime_r(&now, &gmt);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&gmtime_mutex);
+ privoxy_mutex_lock(&gmtime_mutex);
gmt = *gmtime(&now);
- pthread_mutex_unlock(&gmtime_mutex);
+ privoxy_mutex_unlock(&gmtime_mutex);
#else
gmt = *gmtime(&now);
#endif
#ifdef HAVE_LOCALTIME_R
tm_now = localtime_r(&now, &dummy);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&localtime_mutex);
+ privoxy_mutex_lock(&localtime_mutex);
tm_now = localtime(&now);
- pthread_mutex_unlock(&localtime_mutex);
+ privoxy_mutex_unlock(&localtime_mutex);
#else
tm_now = localtime(&now);
#endif
-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.46 2008/03/21 11:13:57 fabiankeil Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.47 2008/03/26 18:07:07 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
*
* Revisions :
* $Log: jbsockets.c,v $
+ * Revision 1.47 2008/03/26 18:07:07 fabiankeil
+ * Add hostname directive. Closes PR#1918189.
+ *
* Revision 1.46 2008/03/21 11:13:57 fabiankeil
* Only gather host information if it's actually needed.
* Also move the code out of accept_connection() so it's less likely
host = NULL;
}
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&resolver_mutex);
+ privoxy_mutex_lock(&resolver_mutex);
host = gethostbyaddr((const char *)&server.sin_addr,
sizeof(server.sin_addr), AF_INET);
- pthread_mutex_unlock(&resolver_mutex);
+ privoxy_mutex_unlock(&resolver_mutex);
#else
host = gethostbyaddr((const char *)&server.sin_addr,
sizeof(server.sin_addr), AF_INET);
hostp = NULL;
}
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&resolver_mutex);
+ privoxy_mutex_lock(&resolver_mutex);
while (NULL == (hostp = gethostbyname(host))
&& (h_errno == TRY_AGAIN) && (dns_retries++ < MAX_DNS_RETRIES))
{
"Timeout #%u while trying to resolve %s. Trying again.",
dns_retries, host);
}
- pthread_mutex_unlock(&resolver_mutex);
+ privoxy_mutex_unlock(&resolver_mutex);
#else
while (NULL == (hostp = gethostbyname(host))
&& (h_errno == TRY_AGAIN) && (dns_retries++ < MAX_DNS_RETRIES))
-const char jcc_rcs[] = "$Id: jcc.c,v 1.184 2008/08/22 15:34:45 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.185 2008/08/30 12:03:07 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.185 2008/08/30 12:03:07 fabiankeil
+ * Remove FEATURE_COOKIE_JAR.
+ *
* Revision 1.184 2008/08/22 15:34:45 fabiankeil
* - Silence LLVM/Clang complaint.
* - Make received_hup_signal static.
#endif
#ifdef FEATURE_PTHREAD
-pthread_mutex_t log_mutex;
-pthread_mutex_t log_init_mutex;
+/*
+ * XXX: Does the locking stuff really belong in this file?
+ */
+privoxy_mutex_t log_mutex;
+privoxy_mutex_t log_init_mutex;
#if !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R)
-pthread_mutex_t resolver_mutex;
+privoxy_mutex_t resolver_mutex;
#endif /* !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R) */
#ifndef HAVE_GMTIME_R
-pthread_mutex_t gmtime_mutex;
+privoxy_mutex_t gmtime_mutex;
#endif /* ndef HAVE_GMTIME_R */
#ifndef HAVE_LOCALTIME_R
-pthread_mutex_t localtime_mutex;
+privoxy_mutex_t localtime_mutex;
#endif /* ndef HAVE_GMTIME_R */
#ifndef HAVE_RANDOM
-pthread_mutex_t rand_mutex;
+privoxy_mutex_t rand_mutex;
#endif /* ndef HAVE_RANDOM */
#endif /* FEATURE_PTHREAD */
#endif /* #if !defined(_WIN32) || defined(_WIN_CONSOLE) */
+#ifdef FEATURE_PTHREAD
+/*********************************************************************
+ *
+ * Function : privoxy_mutex_lock
+ *
+ * Description : Locks a mutex using pthread_mutex_lock.
+ *
+ * Parameters :
+ * 1 : mutex = The mutex to lock.
+ *
+ * Returns : Void, exits in case of errors.
+ *
+ *********************************************************************/
+void privoxy_mutex_lock(privoxy_mutex_t *mutex)
+{
+ int err = pthread_mutex_lock(mutex);
+ if (err)
+ {
+ if (mutex != &log_mutex)
+ {
+ log_error(LOG_LEVEL_FATAL,
+ "Mutex locking failed: %s.\n", strerror(err));
+ }
+ exit(1);
+ }
+}
+
+
+/*********************************************************************
+ *
+ * Function : privoxy_mutex_unlock
+ *
+ * Description : Unlocks a mutex using pthread_mutex_unlock.
+ *
+ * Parameters :
+ * 1 : mutex = The mutex to unlock.
+ *
+ * Returns : Void, exits in case of errors.
+ *
+ *********************************************************************/
+void privoxy_mutex_unlock(privoxy_mutex_t *mutex)
+{
+ int err = pthread_mutex_unlock(mutex);
+ if (err)
+ {
+ if (mutex != &log_mutex)
+ {
+ log_error(LOG_LEVEL_FATAL,
+ "Mutex unlocking failed: %s.\n", strerror(err));
+ }
+ exit(1);
+ }
+}
+
+
+/*********************************************************************
+ *
+ * Function : privoxy_mutex_init
+ *
+ * Description : Prepares a mutex using pthread_mutex_init.
+ *
+ * Parameters :
+ * 1 : mutex = The mutex to initialize.
+ *
+ * Returns : Void, exits in case of errors.
+ *
+ *********************************************************************/
+static void privoxy_mutex_init(privoxy_mutex_t *mutex)
+{
+ int err = pthread_mutex_init(mutex, 0);
+ if (err)
+ {
+ printf("Fatal error. Mutex initialization failed: %s.\n",
+ strerror(err));
+ exit(1);
+ }
+}
+#endif /* def FEATURE_PTHREAD */
+
+
/*********************************************************************
*
* Function : initialize_mutexes
*********************************************************************/
static void initialize_mutexes(void)
{
- int err = 0;
-
#ifdef FEATURE_PTHREAD
/*
* Prepare global mutex semaphores
*/
- err = pthread_mutex_init(&log_mutex, 0);
+ privoxy_mutex_init(&log_mutex);
- if (!err) err = pthread_mutex_init(&log_init_mutex, 0);
+ privoxy_mutex_init(&log_init_mutex);
/*
* XXX: The assumptions below are a bit naive
* thread safe.
*/
#if !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R)
- if (!err) err = pthread_mutex_init(&resolver_mutex, 0);
+ privoxy_mutex_init(&resolver_mutex);
#endif /* !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R) */
/*
* XXX: should we use a single mutex for
* localtime() and gmtime() as well?
*/
#ifndef HAVE_GMTIME_R
- if (!err) err = pthread_mutex_init(&gmtime_mutex, 0);
+ privoxy_mutex_init(&gmtime_mutex);
#endif /* ndef HAVE_GMTIME_R */
#ifndef HAVE_LOCALTIME_R
- if (!err) err = pthread_mutex_init(&localtime_mutex, 0);
+ privoxy_mutex_init(&localtime_mutex);
#endif /* ndef HAVE_GMTIME_R */
#ifndef HAVE_RANDOM
- if (!err) err = pthread_mutex_init(&rand_mutex, 0);
+ privoxy_mutex_init(&rand_mutex);
#endif /* ndef HAVE_RANDOM */
#endif /* FEATURE_PTHREAD */
* TODO: mutex support for mingw32 would be swell.
*/
- if (err)
- {
- printf("Fatal error. Mutex initialization failed: %s.\n",
- strerror(err));
- exit(1);
- }
-
- return;
}
#ifndef JCC_H_INCLUDED
#define JCC_H_INCLUDED
-#define JCC_H_VERSION "$Id: jcc.h,v 1.21 2007/04/22 13:18:06 fabiankeil Exp $"
+#define JCC_H_VERSION "$Id: jcc.h,v 1.22 2007/06/01 18:16:36 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.h,v $
*
* Revisions :
* $Log: jcc.h,v $
+ * Revision 1.22 2007/06/01 18:16:36 fabiankeil
+ * Use the same mutex for gethostbyname() and gethostbyaddr() to prevent
+ * deadlocks and crashes on OpenBSD and possibly other OS with neither
+ * gethostbyname_r() nor gethostaddr_r(). Closes BR#1729174.
+ * Thanks to Ralf Horstmann for report and solution.
+ *
* Revision 1.21 2007/04/22 13:18:06 fabiankeil
* Keep the HTTP snippets local.
*
#ifdef FEATURE_PTHREAD
#include <pthread.h>
-extern pthread_mutex_t log_mutex;
-extern pthread_mutex_t log_init_mutex;
+
+typedef pthread_mutex_t privoxy_mutex_t;
+
+extern void privoxy_mutex_lock(privoxy_mutex_t *mutex);
+extern void privoxy_mutex_unlock(privoxy_mutex_t *mutex);
+
+extern privoxy_mutex_t log_mutex;
+extern privoxy_mutex_t log_init_mutex;
#ifndef HAVE_GMTIME_R
-extern pthread_mutex_t gmtime_mutex;
+extern privoxy_mutex_t gmtime_mutex;
#endif /* ndef HAVE_GMTIME_R */
#ifndef HAVE_LOCALTIME_R
-extern pthread_mutex_t localtime_mutex;
+extern privoxy_mutex_t localtime_mutex;
#endif /* ndef HAVE_GMTIME_R */
#if !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R)
-extern pthread_mutex_t resolver_mutex;
+extern privoxy_mutex_t resolver_mutex;
#endif /* !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R) */
#ifndef HAVE_RANDOM
-extern pthread_mutex_t rand_mutex;
+extern privoxy_mutex_t rand_mutex;
#endif /* ndef HAVE_RANDOM */
#endif /* FEATURE_PTHREAD */
-const char miscutil_rcs[] = "$Id: miscutil.c,v 1.57 2008/03/24 15:29:51 fabiankeil Exp $";
+const char miscutil_rcs[] = "$Id: miscutil.c,v 1.58 2008/04/17 14:53:30 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $
*
* Revisions :
* $Log: miscutil.c,v $
+ * Revision 1.58 2008/04/17 14:53:30 fabiankeil
+ * Move simplematch() into urlmatch.c as it's only
+ * used to match (old-school) domain patterns.
+ *
* Revision 1.57 2008/03/24 15:29:51 fabiankeil
* Pet gcc43.
*
#ifdef HAVE_RANDOM
number = random() % range + 1;
#elif defined(FEATURE_PTHREAD)
- pthread_mutex_lock(&rand_mutex);
+ privoxy_mutex_lock(&rand_mutex);
number = rand() % (long int)(range + 1);
- pthread_mutex_unlock(&rand_mutex);
+ privoxy_mutex_unlock(&rand_mutex);
#else
#ifdef _WIN32
/*
-const char parsers_rcs[] = "$Id: parsers.c,v 1.137 2008/05/30 15:50:08 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.138 2008/08/30 12:03:07 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.138 2008/08/30 12:03:07 fabiankeil
+ * Remove FEATURE_COOKIE_JAR.
+ *
* Revision 1.137 2008/05/30 15:50:08 fabiankeil
* Remove questionable micro-optimizations
* whose usefulness has never been measured.
#ifdef HAVE_GMTIME_R
timeptr = gmtime_r(&now, &gmt);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&gmtime_mutex);
+ privoxy_mutex_lock(&gmtime_mutex);
timeptr = gmtime(&now);
- pthread_mutex_unlock(&gmtime_mutex);
+ privoxy_mutex_unlock(&gmtime_mutex);
#else
timeptr = gmtime(&now);
#endif
#ifdef HAVE_GMTIME_R
timeptr = gmtime_r(&last_modified, &gmt);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&gmtime_mutex);
+ privoxy_mutex_lock(&gmtime_mutex);
timeptr = gmtime(&last_modified);
- pthread_mutex_unlock(&gmtime_mutex);
+ privoxy_mutex_unlock(&gmtime_mutex);
#else
timeptr = gmtime(&last_modified);
#endif
#ifdef HAVE_GMTIME_R
timeptr = gmtime_r(&tm, &gmt);
#elif FEATURE_PTHREAD
- pthread_mutex_lock(&gmtime_mutex);
+ privoxy_mutex_lock(&gmtime_mutex);
timeptr = gmtime(&tm);
- pthread_mutex_unlock(&gmtime_mutex);
+ privoxy_mutex_unlock(&gmtime_mutex);
#else
timeptr = gmtime(&tm);
#endif