added gnutls backend and moved backend code into new files
[ircu2.10.12-pk.git] / include / ircd_log.h
index 20f0a25dcecde0d5fc25c4b348472a77f83cd8bd..48d63a87ed3572f5f9d737a066767629e9c22c7c 100644 (file)
 #include <stdarg.h>        /* va_list */
 #define INCLUDED_stdarg_h
 #endif
+#ifndef INCLUDED_stdlib_h
+#include <stdlib.h> /* abort */
+#define INCLUDED_stdlib_h
+#endif
 
 struct Client;
 
@@ -59,8 +63,8 @@ enum LogSys {
   LS_OPER,       /**< Users becoming operators. */
   LS_RESOLVER,   /**< DNS resolver errors. */
   LS_SOCKET,     /**< Unexpected socket operation errors. */
+  LS_IAUTH,      /**< IAuth status. */
   LS_DEBUG,      /**< Debug messages. */
-  LS_OLDLOG,     /**< Old logging messages (no longer used). */
   LS_LAST_SYSTEM /**< Count of valid LogSys values. */
 };
 
@@ -107,4 +111,47 @@ extern void log_feature_unmark(void);
 extern int log_feature_mark(int flag);
 extern void log_feature_report(struct Client *to, int flag);
 
+extern int log_inassert;
+
 #endif /* INCLUDED_ircd_log_h */
+
+/* The rest of this file implements our own custom version of assert.
+ * This version will log the assertion failure using the LS_SYSTEM log
+ * stream, thus putting the assertion failure message into a useful
+ * place, rather than elsewhere, as is currently the case...
+ */
+
+/* We've been included twice; clean up before creating assert() again */
+#ifdef _ircd_log_assert
+# undef _ircd_log_assert
+# undef assert
+#endif
+
+/* gcc has a nice way of hinting that an expression is expected to
+ * produce a specific result, which can improve optimization.
+ * Unfortunately, all the world's not gcc (at least, not yet), and not
+ * all gcc's support it.  I don't know exactly when it appeared, but
+ * it does appear to be in all versions from 3 and up.  So, we'll
+ * create a dummy define if (we think) this version of gcc doesn't
+ * have it...
+ */
+#ifndef _log_builtin_expect
+# define _log_builtin_expect
+# if __GNUC__ < 3
+#  define __builtin_expect(expr, expect)       (expr)
+# endif
+#endif
+
+/* let's try not to clash with the system assert()... */
+#ifndef assert
+# ifdef NDEBUG
+#  define assert(expr) ((void)0)
+# else
+#  define assert(expr)                                                       \
+  ((void)(__builtin_expect(!!(expr), 1) ? 0 :                                \
+         (__builtin_expect(log_inassert, 0) ? (abort(), 0) :                 \
+          ((log_inassert = 1), /* inhibit looping in assert() */             \
+           log_write(LS_SYSTEM, L_CRIT, 0, "Assertion failure at %s:%d: "    \
+                     "\"%s\"", __FILE__, __LINE__, #expr), abort(), 0))))
+# endif
+#endif