[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [obfsproxy/master] Abort, not exit, on obfs_assert failure



commit e493fffaacda5e1f6e02aa21ff850361c2789332
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Feb 10 11:47:13 2012 -0500

    Abort, not exit, on obfs_assert failure
---
 src/util.c |   13 +++++++++++++
 src/util.h |   20 ++++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/util.c b/src/util.c
index 000bf85..70bd9b4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -567,6 +567,19 @@ log_error(const char *format, ...)
   exit(1);
 }
 
+/** Public function for logging an error message then aborting. */
+void
+log_error_abort(const char *format, ...)
+{
+  va_list ap;
+  va_start(ap,format);
+
+  logv(LOG_SEV_ERR, format, ap);
+
+  va_end(ap);
+  abort();
+}
+
 /** Public function for logging a warning. */
 void
 log_warn(const char *format, ...)
diff --git a/src/util.h b/src/util.h
index a8588c2..91f7585 100644
--- a/src/util.h
+++ b/src/util.h
@@ -156,6 +156,10 @@ void close_obfsproxy_logfile(void);
 void log_error(const char *format, ...)
   ATTR_PRINTF_1 ATTR_NORETURN;
 
+/** Fatal errors: the program cannot continue and will abort */
+void log_error_abort(const char *format, ...)
+  ATTR_PRINTF_1 ATTR_NORETURN;
+
 /** Warn-level severity: for messages that only appear when something
     has gone wrong. */
 void log_warn(const char *format, ...)
@@ -176,16 +180,16 @@ void log_debug_raw(const char *format, va_list ap);
 /** Assertion checking.  We don't ever compile assertions out, and we
     want precise control over the error messages, so we use our own
     assertion macros. */
-#define obfs_assert(expr)                               \
-  do {                                                  \
-    if (!(expr))                                        \
-      log_error("assertion failure at %s:%d: %s",       \
-                __FILE__, __LINE__, #expr);             \
+#define obfs_assert(expr)                                     \
+  do {                                                        \
+    if (!(expr))                                              \
+      log_error_abort("assertion failure at %s:%d: %s",       \
+                      __FILE__, __LINE__, #expr);             \
   } while (0)
 
-#define obfs_abort()                                    \
-  do {                                                  \
-    log_error("aborted at %s:%d", __FILE__, __LINE__);  \
+#define obfs_abort()                                            \
+  do {                                                          \
+    log_error_abort("aborted at %s:%d", __FILE__, __LINE__);    \
   } while (0)
 
 #endif

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits