gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22776 - in libmicrohttpd: . src/daemon src/include src/tes


From: gnunet
Subject: [GNUnet-SVN] r22776 - in libmicrohttpd: . src/daemon src/include src/testcurl/https
Date: Thu, 19 Jul 2012 17:31:39 +0200

Author: grothoff
Date: 2012-07-19 17:31:39 +0200 (Thu, 19 Jul 2012)
New Revision: 22776

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/daemon/connection.c
   libmicrohttpd/src/daemon/daemon.c
   libmicrohttpd/src/daemon/internal.h
   libmicrohttpd/src/include/microhttpd.h
   libmicrohttpd/src/testcurl/https/mhds_session_info_test.c
Log:
-additional code cleanup

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2012-07-19 15:30:01 UTC (rev 22775)
+++ libmicrohttpd/ChangeLog     2012-07-19 15:31:39 UTC (rev 22776)
@@ -1,3 +1,9 @@
+Thu Jul 19 11:34:50 CEST 2012
+       Consistently use 'panic' function instead of ever directly
+       calling 'abort ()'.  Eliminating unused mutex in SSL mode.
+       Removing check in testcases that fails depending on which
+       version of gnuTLS is involved. -CG
+
 Tue Jul 17 23:50:43 CEST 2012
        Stylistic code clean up.  Allowing lookup up of trailing values
        without keys using "MHD_lookup_connection_value" with a key of NULL

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2012-07-19 15:30:01 UTC (rev 
22775)
+++ libmicrohttpd/src/daemon/connection.c       2012-07-19 15:31:39 UTC (rev 
22776)
@@ -2382,10 +2382,7 @@
          daemon = connection->daemon;
          if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n");
-#endif
-             abort();
+             MHD_PANIC ("Failed to acquire cleanup mutex\n");
            }
          DLL_remove (daemon->connections_head,
                      daemon->connections_tail,
@@ -2395,10 +2392,7 @@
                      connection);
          if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to release cleanup mutex\n");
-#endif
-             abort();
+             MHD_PANIC ("Failed to release cleanup mutex\n");
            }
          return MHD_NO;
         default:

Modified: libmicrohttpd/src/daemon/daemon.c
===================================================================
--- libmicrohttpd/src/daemon/daemon.c   2012-07-19 15:30:01 UTC (rev 22775)
+++ libmicrohttpd/src/daemon/daemon.c   2012-07-19 15:31:39 UTC (rev 22776)
@@ -83,14 +83,24 @@
 
 
 /**
- * Default implementation of the panic function
+ * Default implementation of the panic function,
+ * prints an error message and aborts.
+ *
+ * @param cls unused
+ * @param file name of the file with the problem
+ * @param line line number with the problem
+ * @param msg error message with details
  */
 static void 
-mhd_panic_std(void *cls,
-             const char *file,
-             unsigned int line,
-             const char *reason)
+mhd_panic_std (void *cls,
+              const char *file,
+              unsigned int line,
+              const char *reason)
 {
+#if HAVE_MESSAGES
+  fprintf (stderr, "Fatal error in GNU libmicrohttpd %s:%u: %s\n",
+          file, line, reason);
+#endif
   abort ();
 }
 
@@ -166,10 +176,7 @@
 {
   if (0 != pthread_mutex_lock(&daemon->per_ip_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to acquire IP connection limit mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to acquire IP connection limit mutex\n");
     }
 }
 
@@ -184,10 +191,7 @@
 {
   if (0 != pthread_mutex_unlock(&daemon->per_ip_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to release IP connection limit mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to release IP connection limit mutex\n");
     }
 }
 
@@ -347,21 +351,13 @@
     {      
       /* Something's wrong if we couldn't find an IP address
        * that was previously added */
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon,
-                "Failed to find previously-added IP address\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to find previously-added IP address\n");
     }
   found_key = (struct MHD_IPCount *) *nodep;
   /* Validate existing count for IP address */
   if (0 == found_key->count)
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon,
-                "Previously-added IP address had 0 count\n");
-#endif
-      abort();
+      MHD_PANIC ("Previously-added IP address had 0 count\n");
     }
   /* Remove the node entirely if count reduces to 0 */
   if (0 == --found_key->count)
@@ -377,9 +373,6 @@
 
 
 #if HTTPS_SUPPORT
-static pthread_mutex_t MHD_gnutls_init_mutex;
-
-
 /**
  * Callback for receiving data from the socket.
  *
@@ -1035,13 +1028,7 @@
           MHD_ip_limit_del (daemon, addr, addrlen);
           free (connection->addr);
           free (connection);
-          mhd_panic (mhd_panic_cls, __FILE__, __LINE__, 
-#if HAVE_MESSAGES
-                    "Unknown credential type"
-#else
-                    NULL
-#endif
-                    );
+          MHD_PANIC ("Unknown credential type");
          return MHD_NO;
         }
       gnutls_transport_set_ptr (connection->tls_session,
@@ -1061,20 +1048,14 @@
 
   if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to acquire cleanup mutex\n");
     }
   DLL_insert (daemon->connections_head,
              daemon->connections_tail,
              connection);
   if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to release cleanup mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to release cleanup mutex\n");
     }
 
   /* attempt to create handler thread */
@@ -1093,20 +1074,14 @@
           MHD_ip_limit_del (daemon, addr, addrlen);
          if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n");
-#endif
-             abort();
+             MHD_PANIC ("Failed to acquire cleanup mutex\n");
            }
          DLL_remove (daemon->connections_head,
                      daemon->connections_tail,
                      connection);
          if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to release cleanup mutex\n");
-#endif
-             abort();
+             MHD_PANIC ("Failed to release cleanup mutex\n");
            }
           free (connection->addr);
           free (connection);
@@ -1222,10 +1197,7 @@
 
   if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to acquire cleanup mutex\n");
     }
   while (NULL != (pos = daemon->cleanup_head))
     {
@@ -1237,11 +1209,7 @@
        { 
          if (0 != (rc = pthread_join (pos->pid, &unused)))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to join a thread: %s\n",
-                       STRERROR (rc));
-#endif
-             abort();
+             MHD_PANIC ("Failed to join a thread\n");
            }
        }
       MHD_pool_destroy (pos->pool);
@@ -1264,10 +1232,7 @@
     }
   if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to release cleanup mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to release cleanup mutex\n");
     }
 }
 
@@ -2179,21 +2144,6 @@
 #if HTTPS_SUPPORT
   if (0 != (options & MHD_USE_SSL))
     {
-      /* lock MHD_gnutls_global mutex since it uses reference counting */
-      if (0 != pthread_mutex_lock (&MHD_gnutls_init_mutex))
-       {
-#if HAVE_MESSAGES
-         MHD_DLOG (daemon, "Failed to acquire gnutls mutex\n");
-#endif
-          mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
-       }
-      if (0 != pthread_mutex_unlock (&MHD_gnutls_init_mutex))
-       {
-#if HAVE_MESSAGES
-         MHD_DLOG (daemon, "Failed to release gnutls mutex\n");
-#endif
-         mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
-       }
       daemon->cred_type = GNUTLS_CRD_CERTIFICATE;
     }
 #endif
@@ -2220,7 +2170,7 @@
                    "Specified value for NC_SIZE too large\n");
 #endif
 #if HTTPS_SUPPORT
-         if (options & MHD_USE_SSL)
+         if (0 != (options & MHD_USE_SSL))
            gnutls_priority_deinit (daemon->priority_cache);
 #endif
          free (daemon);
@@ -2228,21 +2178,21 @@
        }
       daemon->nnc = malloc (daemon->nonce_nc_size * sizeof(struct 
MHD_NonceNc));
       if (NULL == daemon->nnc)
-           {
+       {
 #if HAVE_MESSAGES
-             MHD_DLOG (daemon,
-                       "Failed to allocate memory for nonce-nc map: %s\n",
-                       STRERROR (errno));
+         MHD_DLOG (daemon,
+                   "Failed to allocate memory for nonce-nc map: %s\n",
+                   STRERROR (errno));
 #endif
 #if HTTPS_SUPPORT
-             if (options & MHD_USE_SSL)
-               gnutls_priority_deinit (daemon->priority_cache);
+         if (0 != (options & MHD_USE_SSL))
+           gnutls_priority_deinit (daemon->priority_cache);
 #endif
-             free (daemon);
-             return NULL;
-           }
+         free (daemon);
+         return NULL;
+       }
     }
-
+  
   if (0 != pthread_mutex_init (&daemon->nnc_lock, NULL))
     {
 #if HAVE_MESSAGES
@@ -2250,7 +2200,7 @@
                "MHD failed to initialize nonce-nc mutex\n");
 #endif
 #if HTTPS_SUPPORT
-      if (options & MHD_USE_SSL)
+      if (0 != (options & MHD_USE_SSL))
        gnutls_priority_deinit (daemon->priority_cache);
 #endif
       free (daemon->nnc);
@@ -2616,20 +2566,14 @@
      traverse DLLs in peace... */
   if (0 != pthread_mutex_lock(&daemon->cleanup_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to acquire cleanup mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to acquire cleanup mutex\n");
     }
   for (pos = daemon->connections_head; NULL != pos; pos = pos->next)    
     SHUTDOWN (pos->socket_fd, 
              (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR);    
   if (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex))
     {
-#if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Failed to release cleanup mutex\n");
-#endif
-      abort();
+      MHD_PANIC ("Failed to release cleanup mutex\n");
     }
 
   /* now, collect threads */
@@ -2639,11 +2583,7 @@
        {
          if (0 != (rc = pthread_join (pos->pid, &unused)))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to join a thread: %s\n",
-                       STRERROR (rc));
-#endif
-             abort();
+             MHD_PANIC ("Failed to join a thread\n");
            }
          pos->thread_joined = MHD_YES;
        }
@@ -2695,7 +2635,8 @@
     }
   if (-1 != daemon->wpipe[1])
     {
-      WRITE (daemon->wpipe[1], "e", 1);
+      if (1 != WRITE (daemon->wpipe[1], "e", 1))
+       MHD_PANIC ("failed to signal shutdownn via pipe");
     }
 #ifdef HAVE_LISTEN_SHUTDOWN
   else
@@ -2719,11 +2660,7 @@
        {
          if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused)))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to join a thread: %s\n",
-                       STRERROR (rc));
-#endif
-             abort();
+             MHD_PANIC ("Failed to join a thread\n");
            }
          close_all_connections (&daemon->worker_pool[i]);
        }
@@ -2738,11 +2675,7 @@
        {
          if (0 != (rc = pthread_join (daemon->pid, &unused)))
            {
-#if HAVE_MESSAGES
-             MHD_DLOG (daemon, "Failed to join a thread: %s\n",
-                       STRERROR (rc));
-#endif
-             abort();
+             MHD_PANIC ("Failed to join a thread\n");
            }
        }
     }
@@ -2757,21 +2690,6 @@
       gnutls_priority_deinit (daemon->priority_cache);
       if (daemon->x509_cred)
         gnutls_certificate_free_credentials (daemon->x509_cred);
-      /* lock MHD_gnutls_global mutex since it uses reference counting */
-      if (0 != pthread_mutex_lock (&MHD_gnutls_init_mutex))
-       {
-#if HAVE_MESSAGES
-         MHD_DLOG (daemon, "Failed to acquire gnutls mutex\n");
-#endif
-         abort();
-       }
-      if (0 != pthread_mutex_unlock (&MHD_gnutls_init_mutex))
-       {
-#if HAVE_MESSAGES
-         MHD_DLOG (daemon, "Failed to release gnutls mutex\n");
-#endif
-         abort();
-       }
     }
 #endif
 
@@ -2784,11 +2702,6 @@
 
   if (-1 != daemon->wpipe[1])
     {
-      char c;
-
-      /* just to be sure, remove the one char we 
-        wrote into the pipe */
-      (void) READ (daemon->wpipe[0], &c, 1);
       CLOSE (daemon->wpipe[0]);
       CLOSE (daemon->wpipe[1]);
     }
@@ -2830,8 +2743,8 @@
  * try to continue, this is never safe.
  *
  * The default implementation that is used if no panic function is set
- * simply calls "abort".  Alternative implementations might call
- * "exit" or other similar functions.
+ * simply prints an error message and calls "abort".  Alternative
+ * implementations might call "exit" or other similar functions.
  *
  * @param cb new error handler
  * @param cls passed to error handler
@@ -2884,8 +2797,6 @@
 #if HTTPS_SUPPORT
   gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
   gnutls_global_init ();
-  if (0 != pthread_mutex_init(&MHD_gnutls_init_mutex, NULL))
-    abort();
 #endif
 }
 
@@ -2895,8 +2806,6 @@
 {
 #if HTTPS_SUPPORT
   gnutls_global_deinit ();
-  if (0 != pthread_mutex_destroy(&MHD_gnutls_init_mutex))
-    mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
 #endif
 #ifdef WINDOWS
   plibc_shutdown ();

Modified: libmicrohttpd/src/daemon/internal.h
===================================================================
--- libmicrohttpd/src/daemon/internal.h 2012-07-19 15:30:01 UTC (rev 22775)
+++ libmicrohttpd/src/daemon/internal.h 2012-07-19 15:31:39 UTC (rev 22776)
@@ -60,7 +60,23 @@
  */
 extern void *mhd_panic_cls;
 
+#if HAVE_MESSAGES
 /**
+ * Trigger 'panic' action based on fatal errors.
+ * 
+ * @param error message (const char *)
+ */
+#define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg)
+#else
+/**
+ * Trigger 'panic' action based on fatal errors.
+ * 
+ * @param error message (const char *)
+ */
+#define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL)
+#endif
+
+/**
  * Events we care about with respect to poll/select
  * for file descriptors.
  */

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2012-07-19 15:30:01 UTC (rev 
22775)
+++ libmicrohttpd/src/include/microhttpd.h      2012-07-19 15:31:39 UTC (rev 
22776)
@@ -828,7 +828,9 @@
 
 
 /**
- * Callback for serious error condition. The default action is to abort().
+ * Callback for serious error condition. The default action is to print
+ * an error message and abort().
+ *
  * @param cls user specified value
  * @param file where the error occured
  * @param line where the error occured
@@ -1229,8 +1231,8 @@
  * try to continue, this is never safe.
  *
  * The default implementation that is used if no panic function is set
- * simply calls "abort".  Alternative implementations might call
- * "exit" or other similar functions.
+ * simply prints an error message and calls "abort".  Alternative
+ * implementations might call "exit" or other similar functions.
  *
  * @param cb new error handler
  * @param cls passed to error handler

Modified: libmicrohttpd/src/testcurl/https/mhds_session_info_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_session_info_test.c   2012-07-19 
15:30:01 UTC (rev 22775)
+++ libmicrohttpd/src/testcurl/https/mhds_session_info_test.c   2012-07-19 
15:31:39 UTC (rev 22776)
@@ -55,18 +55,6 @@
       return MHD_YES;
     }
 
-  /* assert actual connection cipher is the one negotiated */
-  if (GNUTLS_CIPHER_ARCFOUR_128 != 
-      (ret = MHD_get_connection_info
-       (connection,
-       MHD_CONNECTION_INFO_CIPHER_ALGO)->cipher_algorithm))
-    {
-      fprintf (stderr, "Error: requested cipher mismatch (wanted %d, got 
%d)\n",
-               GNUTLS_CIPHER_ARCFOUR_128,
-              ret);
-      return -1;
-    }
-
   if (GNUTLS_SSL3 != 
       (ret = MHD_get_connection_info
        (connection,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]