svn commit: r217966 - head/sbin/hastd
Pawel Jakub Dawidek
pjd at FreeBSD.org
Thu Jan 27 19:28:30 UTC 2011
Author: pjd
Date: Thu Jan 27 19:28:29 2011
New Revision: 217966
URL: http://svn.freebsd.org/changeset/base/217966
Log:
Extend pjdlog_verify() to support the following additional macros:
PJDLOG_RVERIFY() - always check expression and on false log the given message
and exit.
PJDLOG_RASSERT() - check expression when NDEBUG is not defined and on false log
given message and exit.
PJDLOG_ABORT() - log the given message and exit.
MFC after: 1 week
Modified:
head/sbin/hastd/pjdlog.c
head/sbin/hastd/pjdlog.h
Modified: head/sbin/hastd/pjdlog.c
==============================================================================
--- head/sbin/hastd/pjdlog.c Thu Jan 27 19:24:07 2011 (r217965)
+++ head/sbin/hastd/pjdlog.c Thu Jan 27 19:28:29 2011 (r217966)
@@ -440,15 +440,38 @@ pjdlog_exitx(int exitcode, const char *f
*/
void
pjdlog_verify(const char *func, const char *file, int line,
- const char *failedexpr)
+ const char *failedexpr, const char *fmt, ...)
{
+ va_list ap;
- if (func == NULL) {
- pjdlog_critical("Assertion failed: (%s), file %s, line %d.",
- failedexpr, file, line);
+ assert(pjdlog_initialized);
+
+ /*
+ * When there is no message we pass __func__ as 'fmt'.
+ * It would be cleaner to pass NULL or "", but gcc generates a warning
+ * for both of those.
+ */
+ if (fmt != func) {
+ va_start(ap, fmt);
+ pjdlogv_critical(fmt, ap);
+ va_end(ap);
+ }
+ if (failedexpr == NULL) {
+ if (func == NULL) {
+ pjdlog_critical("Aborted at file %s, line %d.", file,
+ line);
+ } else {
+ pjdlog_critical("Aborted at function %s, file %s, line %d.",
+ func, file, line);
+ }
} else {
- pjdlog_critical("Assertion failed: (%s), function %s, file %s, line %d.",
- failedexpr, func, file, line);
+ if (func == NULL) {
+ pjdlog_critical("Assertion failed: (%s), file %s, line %d.",
+ failedexpr, file, line);
+ } else {
+ pjdlog_critical("Assertion failed: (%s), function %s, file %s, line %d.",
+ failedexpr, func, file, line);
+ }
}
abort();
}
Modified: head/sbin/hastd/pjdlog.h
==============================================================================
--- head/sbin/hastd/pjdlog.h Thu Jan 27 19:24:07 2011 (r217965)
+++ head/sbin/hastd/pjdlog.h Thu Jan 27 19:28:29 2011 (r217966)
@@ -90,16 +90,28 @@ void pjdlog_exitx(int exitcode, const ch
void pjdlogv_exitx(int exitcode, const char *fmt, va_list ap) __printflike(2, 0) __dead2;
void pjdlog_verify(const char *func, const char *file, int line,
- const char *failedexpr);
+ const char *failedexpr, const char *fmt, ...) __printflike(5, 6);
#define PJDLOG_VERIFY(expr) do { \
- if (!(expr)) \
- pjdlog_verify(__func__, __FILE__, __LINE__, #expr); \
+ if (!(expr)) { \
+ pjdlog_verify(__func__, __FILE__, __LINE__, #expr, \
+ __func__); \
+ } \
} while (0)
+#define PJDLOG_RVERIFY(expr, ...) do { \
+ if (!(expr)) { \
+ pjdlog_verify(__func__, __FILE__, __LINE__, #expr, \
+ __VA_ARGS__); \
+ } \
+} while (0)
+#define PJDLOG_ABORT(...) pjdlog_verify(__func__, __FILE__, \
+ __LINE__, NULL, __VA_ARGS__)
#ifdef NDEBUG
#define PJDLOG_ASSERT(expr) do { } while (0)
+#define PJDLOG_RASSERT(...) do { } while (0)
#else
#define PJDLOG_ASSERT(expr) PJDLOG_VERIFY(expr)
+#define PJDLOG_RASSERT(...) PJDLOG_RVERIFY(__VA_ARGS__)
#endif
#endif /* !_PJDLOG_H_ */
More information about the svn-src-head
mailing list