From owner-svn-src-all@FreeBSD.ORG Thu Aug 5 18:26:38 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 80509106566B; Thu, 5 Aug 2010 18:26:38 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 549878FC0A; Thu, 5 Aug 2010 18:26:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o75IQc3t069289; Thu, 5 Aug 2010 18:26:38 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o75IQceK069286; Thu, 5 Aug 2010 18:26:38 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201008051826.o75IQceK069286@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Thu, 5 Aug 2010 18:26:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210875 - head/sbin/hastd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Aug 2010 18:26:38 -0000 Author: pjd Date: Thu Aug 5 18:26:38 2010 New Revision: 210875 URL: http://svn.freebsd.org/changeset/base/210875 Log: Problem with assertion is that it logs on stderr. Add two macros: PJDLOG_ASSERT() and PJDLOG_VERIFY() that will check the given condition and log the problem where appropriate. The difference between those two is that PJDLOG_VERIFY() always work and PJDLOG_ASSERT() can be turned off by defining NDEBUG. MFC after: 1 month Modified: head/sbin/hastd/pjdlog.c head/sbin/hastd/pjdlog.h Modified: head/sbin/hastd/pjdlog.c ============================================================================== --- head/sbin/hastd/pjdlog.c Thu Aug 5 18:26:03 2010 (r210874) +++ head/sbin/hastd/pjdlog.c Thu Aug 5 18:26:38 2010 (r210875) @@ -365,3 +365,23 @@ pjdlog_exitx(int exitcode, const char *f /* NOTREACHED */ va_end(ap); } + +/* + * Log assertion and exit. + */ +void +pjdlog_verify(const char *func, const char *file, int line, + const char *failedexpr) +{ + + 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(); + /* NOTREACHED */ +} + Modified: head/sbin/hastd/pjdlog.h ============================================================================== --- head/sbin/hastd/pjdlog.h Thu Aug 5 18:26:03 2010 (r210874) +++ head/sbin/hastd/pjdlog.h Thu Aug 5 18:26:38 2010 (r210875) @@ -85,4 +85,17 @@ void pjdlogv_exit(int exitcode, const ch void pjdlog_exitx(int exitcode, const char *fmt, ...) __printflike(2, 3) __dead2; 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) __dead2; + +#define PJDLOG_VERIFY(expr) do { \ + if (!(expr)) \ + pjdlog_verify(__func__, __FILE__, __LINE__, #expr); \ +} while (0) +#ifdef NDEBUG +#define PJDLOG_ASSERT(expr) do { } while (0) +#else +#define PJDLOG_ASSERT(expr) PJDLOG_VERIFY(expr) +#endif + #endif /* !_PJDLOG_H_ */