aboutsummaryrefslogtreecommitdiff
path: root/lib/util.h
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2013-01-16 16:03:03 -0800
committerBen Pfaff <blp@nicira.com>2013-01-16 16:03:03 -0800
commit4749f73d12c844b318af7f45cf45e1acac9f7c08 (patch)
tree8b052885968f7cc6f0f281f1dee0a704b1ec4477 /lib/util.h
parent167744623897a67ef3fd13bcaf44a84d3641fe68 (diff)
util: Introduce ovs_assert macro.
An occasionally significant problem with the standard "assert" macro is that it writes the failure message to stderr. In our daemons, stderr is generally redirected to /dev/null. It's more useful to write the failure message to the log, which is what the new ovs_assert macro introduced in this patch does. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
Diffstat (limited to 'lib/util.h')
-rw-r--r--lib/util.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/util.h b/lib/util.h
index 70f36919..b944ec79 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -62,6 +62,17 @@
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0)
#endif
+/* Like the standard assert macro, except:
+ *
+ * - Writes the failure message to the log.
+ *
+ * - Not affected by NDEBUG. */
+#define ovs_assert(CONDITION) \
+ if (!OVS_LIKELY(CONDITION)) { \
+ ovs_assert_failure(SOURCE_LOCATOR, __func__, #CONDITION); \
+ }
+void ovs_assert_failure(const char *, const char *, const char *) NO_RETURN;
+
/* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes
* anything other than an outermost "const" or "volatile" qualifier.
*