Make assert_failed() print the failed condition
PATCH 1/1 Make assert_failed() print the failed condition
Easy change to make logging output more useful.
--- src/openvpn/error.c | 4 ++-- src/openvpn/error.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-)
src/openvpn/error.c +2 -2
@@ -394,9 +394,9 @@ dont_mute (unsigned int flags) }void -assert_failed (const char *filename,int line) +assert_failed (const char *filename,int line,const char *condition) { -msg (M_FATAL ,"Assertion failed at %s:%d" , filename, line); +msg (M_FATAL ,"Assertion failed at %s:%d (%s)" , filename, line, condition);_exit (1 ); }
src/openvpn/error.h +3 -2
@@ -211,9 +211,10 @@ const char *msg_flags_string (const unsigned int flags, struct gc_arena *gc);FILE *msg_fp (const unsigned int flags);/* Fatal logic errors */ -#define ASSERT (x) do { if (!(x)) assert_failed(__FILE__, __LINE__); } while (false) +#define ASSERT (x) do { if (!(x)) assert_failed(__FILE__, __LINE__, #x); } while (false) -void assert_failed (const char *filename,int line) __attribute__((__noreturn__)); +void assert_failed (const char *filename,int line,const char *condition) + __attribute__((__noreturn__));#ifdef ENABLE_DEBUG void crash (void );/* force a segfault (debugging only) */
Signature · 1 line
2.5.0
Quoted 2 lines · Steffan Karger
Easy change to make logging output more useful.
ACK. BUt I think if we keep the minimal build option, this should be disabled int that option since the extra strings will increase code size.
Arne
PATCH v2 1/1 Make assert_failed() print the failed condition
Easy change to make logging output more useful.
v2: don't print the failed condition if ENABLE_SMALL is defined.
--- src/openvpn/error.c | 7 +++++-- src/openvpn/error.h | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-)
src/openvpn/error.c +5 -2
@@ -394,9 +394,12 @@ dont_mute (unsigned int flags) }void -assert_failed (const char *filename,int line) +assert_failed (const char *filename,int line,const char *condition) { -msg (M_FATAL ,"Assertion failed at %s:%d" , filename, line); +if (condition) +msg (M_FATAL ,"Assertion failed at %s:%d (%s)" , filename, line, condition); +else +msg (M_FATAL ,"Assertion failed at %s:%d" , filename, line);_exit (1 ); }
src/openvpn/error.h +7 -2
@@ -211,9 +211,14 @@ const char *msg_flags_string (const unsigned int flags, struct gc_arena *gc);FILE *msg_fp (const unsigned int flags);/* Fatal logic errors */ -#define ASSERT (x) do { if (!(x)) assert_failed(__FILE__, __LINE__); } while (false) +#ifndef ENABLE_SMALL +#define ASSERT (x) do { if (!(x)) assert_failed(__FILE__, __LINE__, #x); } while (false) +#else +#define ASSERT (x) do { if (!(x)) assert_failed(__FILE__, __LINE__, NULL); } while (false) +#endif -void assert_failed (const char *filename,int line) __attribute__((__noreturn__)); +void assert_failed (const char *filename,int line,const char *condition) + __attribute__((__noreturn__));#ifdef ENABLE_DEBUG void crash (void );/* force a segfault (debugging only) */
Signature · 1 line
2.5.0
ACK (Arne's ACK for v2 taken from IRC, did not make it to the list yet).
Your patch has been applied to the master and release/2.3 branch.
commit 9b36bd40d393620cce83392f4a56392ba391fb7c (master) commit 87e555aea146ec69007ff25ce66e63ad94ae9f7d (release/2.3)
Author: Steffan Karger Date: Sun Dec 20 11:44:09 2015 +0100
Make assert_failed() print the failed condition
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10862
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Quoted 4 lines · Steffan Karger
Easy change to make logging output more useful.
v2: don't print the failed condition if
ENABLE_SMALLis defined.
ACK. Thanks.
Arne