gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r9466 - in libmicrohttpd: . doc src/daemon src/include


From: gnunet
Subject: [GNUnet-SVN] r9466 - in libmicrohttpd: . doc src/daemon src/include
Date: Thu, 12 Nov 2009 08:27:11 -0700

Author: grothoff
Date: 2009-11-12 08:27:11 -0700 (Thu, 12 Nov 2009)
New Revision: 9466

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/doc/microhttpd.texi
   libmicrohttpd/src/daemon/connection.c
   libmicrohttpd/src/daemon/daemon.c
   libmicrohttpd/src/daemon/internal.h
   libmicrohttpd/src/include/microhttpd.h
Log:
cleaning up and documenting panic callback

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2009-11-12 11:55:45 UTC (rev 9465)
+++ libmicrohttpd/ChangeLog     2009-11-12 15:27:11 UTC (rev 9466)
@@ -1,3 +1,8 @@
+Thu Nov 12 16:19:14 CET 2009
+       Adding support for setting a custom error handler for
+       fatal errors (previously, the implementation always
+       called 'abort' in these cases). -CG/ND
+       
 Wed Nov 11 12:54:16 CET 2009
        Adding support for poll (alternative to select allowing
        for more than FD_SETSIZE parallel connections). -JM

Modified: libmicrohttpd/doc/microhttpd.texi
===================================================================
--- libmicrohttpd/doc/microhttpd.texi   2009-11-12 11:55:45 UTC (rev 9465)
+++ libmicrohttpd/doc/microhttpd.texi   2009-11-12 15:27:11 UTC (rev 9466)
@@ -778,7 +778,17 @@
 @node microhttpd-init
 @chapter Starting and stopping the server
 
address@hidden {void} MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
+Set a handler for fatal errors.
 
address@hidden @var
address@hidden cb 
+function to call if MHD encounteres a fatal internal error.  If no handler was 
set explicitly, MHD will call @code{abort}.
+
address@hidden cls
+closure argument for cb; the other arguments are the name of the source file, 
line number and a string describing the nature of the fatal error (which can be 
NULL)
address@hidden table
+
 @deftypefun {struct MHD_Daemon *} MHD_start_daemon (unsigned int flags, 
unsigned short port, MHD_AcceptPolicyCallback apc, void *apc_cls, 
MHD_AccessHandlerCallback dh, void *dh_cls, ...)
 Start a webserver on the given port.
 

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2009-11-12 11:55:45 UTC (rev 
9465)
+++ libmicrohttpd/src/daemon/connection.c       2009-11-12 15:27:11 UTC (rev 
9466)
@@ -341,7 +341,13 @@
                                 connection->response_write_position));
   if ((ret == 0) &&
       (0 != (connection->daemon->options & MHD_USE_SELECT_INTERNALLY)))
-    mhd_panic (mhd_panic_cls, __FILE__, __LINE__, "API violation");
+    mhd_panic (mhd_panic_cls, __FILE__, __LINE__, 
+#if HAVE_MESSAGES
+              "API violation"
+#else
+              NULL
+#endif
+              );
   if (ret == -1)
     {
       /* either error or http 1.0 transfer, close
@@ -1283,7 +1289,13 @@
           return;
         }
       if (processed > used)
-        mhd_panic (mhd_panic_cls, __FILE__, __LINE__, "API violation");
+        mhd_panic (mhd_panic_cls, __FILE__, __LINE__, 
+#if HAVE_MESSAGES
+                  "API violation"
+#else
+                  NULL
+#endif
+                  );
       if (processed != 0)
         instant_retry = MHD_NO; /* client did not process everything */
       used -= processed;

Modified: libmicrohttpd/src/daemon/daemon.c
===================================================================
--- libmicrohttpd/src/daemon/daemon.c   2009-11-12 11:55:45 UTC (rev 9465)
+++ libmicrohttpd/src/daemon/daemon.c   2009-11-12 15:27:11 UTC (rev 9466)
@@ -80,15 +80,24 @@
 /**
  * Default implementation of the panic function
  */
-void mhd_panic_std(void *cls,
-                   const char *file,
-                   unsigned int line,
-                   const char *reason)
+static void 
+mhd_panic_std(void *cls,
+             const char *file,
+             unsigned int line,
+             const char *reason)
 {
   abort ();
 }
 
+
+/**
+ * Handler for fatal errors.
+ */
 MHD_PanicCallback mhd_panic;
+
+/**
+ * Closure argument for "mhd_panic".
+ */
 void *mhd_panic_cls;
 
 /**
@@ -483,8 +492,6 @@
   struct MHD_Pollfd mp;
   struct pollfd p;
 
-  if (con == NULL)
-    mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
   timeout = con->daemon->connection_timeout;
   while ((!con->daemon->shutdown) && (con->socket_fd != -1)) {
       now = time (NULL);
@@ -636,10 +643,6 @@
   static int on = 1;
 #endif
 
-#if HAVE_INET6
-  if (sizeof (struct sockaddr) > sizeof (struct sockaddr_in6))
-    mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);     /* fatal, serious 
error */
-#endif
   addrlen = sizeof (addrstorage);
   memset (addr, 0, sizeof (addrstorage));
 
@@ -773,7 +776,19 @@
                     "Failed to setup TLS credentials: unknown credential type 
%d\n",
                     connection->daemon->cred_type);
 #endif
-          mhd_panic (mhd_panic_cls, __FILE__, __LINE__, "Unknown credential 
type");
+          SHUTDOWN (s, SHUT_RDWR);
+          CLOSE (s);
+          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
+                    );
+         return MHD_NO;
         }
       MHD__gnutls_transport_set_ptr (connection->tls_session,
                                      (MHD_gnutls_transport_ptr_t) connection);
@@ -932,8 +947,6 @@
 
   timeout.tv_sec = 0;
   timeout.tv_usec = 0;
-  if (daemon == NULL)
-    mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
   if (daemon->shutdown == MHD_YES)
     return MHD_NO;
   FD_ZERO (&rs);
@@ -1186,7 +1199,7 @@
 #if HAVE_MESSAGES
          MHD_DLOG (retVal, "Failed to aquire gnutls mutex\n");
 #endif
-         abort();
+          mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
        }
       MHD__gnutls_global_init ();
       if (0 != pthread_mutex_unlock (&MHD_gnutls_init_mutex))
@@ -1194,7 +1207,7 @@
 #if HAVE_MESSAGES
          MHD_DLOG (retVal, "Failed to release gnutls mutex\n");
 #endif
-         abort();
+         mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
        }
       /* set default priorities */
       MHD_tls_set_default_priority (&retVal->priority_cache, "", NULL);
@@ -1276,7 +1289,8 @@
                        opt);
             }
 #endif
-          mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
+         free (retVal);
+         return NULL;
         }
     }
 
@@ -1712,7 +1726,17 @@
 }
 
 /**
- * Sets the global error handler to a different implementation
+ * Sets the global error handler to a different implementation.  "cb"
+ * will only be called in the case of typically fatal, serious
+ * internal consistency issues.  These issues should only arise in the
+ * case of serious memory corruption or similar problems with the
+ * architecture.  While "cb" is allowed to return and MHD will then
+ * 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.
+ *
  * @param cb new error handler
  * @param cls passed to error handler
  */
@@ -1759,7 +1783,7 @@
  */
 void ATTRIBUTE_CONSTRUCTOR MHD_init ()
 {
-  mhd_panic = mhd_panic_std;
+  mhd_panic = &mhd_panic_std;
   mhd_panic_cls = NULL;
 
 #ifndef WINDOWS

Modified: libmicrohttpd/src/daemon/internal.h
===================================================================
--- libmicrohttpd/src/daemon/internal.h 2009-11-12 11:55:45 UTC (rev 9465)
+++ libmicrohttpd/src/daemon/internal.h 2009-11-12 15:27:11 UTC (rev 9466)
@@ -46,7 +46,7 @@
 #define MHD_BUF_INC_SIZE 2048
 
 /**
- * Error handler
+ * Handler for fatal errors.
  */
 extern MHD_PanicCallback mhd_panic;
 

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2009-11-12 11:55:45 UTC (rev 
9465)
+++ libmicrohttpd/src/include/microhttpd.h      2009-11-12 15:27:11 UTC (rev 
9466)
@@ -972,7 +972,17 @@
                           const char *key, const char *value);
 
 /**
- * Sets the global error handler to a different implementation
+ * Sets the global error handler to a different implementation.  "cb"
+ * will only be called in the case of typically fatal, serious
+ * internal consistency issues.  These issues should only arise in the
+ * case of serious memory corruption or similar problems with the
+ * architecture.  While "cb" is allowed to return and MHD will then
+ * 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.
+ *
  * @param cb new error handler
  * @param cls passed to error handler
  */





reply via email to

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