Fix problem with variable declarations in the Slackware section. Thanks to higuita.
[privoxy.git] / jcc.c
diff --git a/jcc.c b/jcc.c
index 370ef7f..911c505 100644 (file)
--- 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.107 2006/11/13 19:05:51 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -33,6 +33,20 @@ 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.107  2006/11/13 19:05:51  fabiankeil
+ *    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.
+ *
+ *    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 +804,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__)
@@ -852,7 +867,10 @@ static void sig_handler(int the_signal)
       case SIGINT:
          log_error(LOG_LEVEL_INFO, "exiting by signal %d .. bye", the_signal);
 #if defined(unix)
-         unlink(pidfile);
+         if(pidfile)
+         {
+            unlink(pidfile);
+         }
 #endif /* unix */
          exit(the_signal);
          break;
@@ -1232,9 +1250,6 @@ static void chat(struct client_state *csp)
        /* We may not forward the request by rfc2616 sect 14.31 */
        (NULL != (rsp = direct_response(csp)))
 
-       /* or a CGI call was detected and answered */
-       || (NULL != (rsp = dispatch_cgi(csp)))
-
        /* or we are enabled and... */
        || (IS_ENABLED_AND (
 
@@ -1246,12 +1261,19 @@ static void chat(struct client_state *csp)
           || ( NULL != (rsp = trust_url(csp)))
 #endif /* def FEATURE_TRUST */
 
-          /* ..or a fast redirect kicked in */
-#ifdef FEATURE_FAST_REDIRECTS
+          /* ..or a redirect kicked in */
           || ( NULL != (rsp = redirect_url(csp)))
-#endif /* def FEATURE_FAST_REDIRECTS */
           ))
-      )
+
+       /*
+        * .. or a CGI call was detected and answered.
+        *
+        * This check comes last to give the user the power
+        * to deny acces to some (or all) of the cgi pages.
+        */
+       || (NULL != (rsp = dispatch_cgi(csp)))
+
+                )
    {
       /* Write the answer to the client */
       if (write_socket(csp->cfd, rsp->head, rsp->head_length)
@@ -2071,21 +2093,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