summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2024-04-22 08:51:58 +0200
committerThomas Haller <thaller@redhat.com>2024-04-22 10:30:03 +0200
commite592dd89f1d6a6613b2ca37434ad568da0998b19 (patch)
treed8cce3d8771f1ea644bef3c6abf7fd4b097c31e8
parent5873497482022167393f3e193d187340df4acf99 (diff)
downloadlibnl-e592dd89f1d6a6613b2ca37434ad568da0998b19.tar.gz
build: always define NL_DEBUG
Checking conditional defines with #ifdef is error prone because we don't get a compiler warning when the define wrongly is missing. Instead, always define it to either 0 or 1. The benefit is also that now we can use NL_DEBUG in C (not only in the preprocessor).
-rw-r--r--configure.ac9
-rw-r--r--include/nl-aux-core/nl-core.h2
-rw-r--r--lib/cache_mngr.c4
-rw-r--r--lib/route/neigh.c2
-rw-r--r--lib/route/route_obj.c4
-rw-r--r--lib/utils.c2
6 files changed, 13 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index bc8b3908..cce0ad0b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,10 +110,13 @@ fi
AM_CONDITIONAL([ENABLE_STATIC], [test "$enable_static" != "no"])
AC_ARG_ENABLE([debug],
- AS_HELP_STRING([--disable-debug], [Do not include debugging statements]),
- [enable_debug="$enableval"], [enable_debug="yes"])
-if test "x$enable_debug" = "xyes"; then
+ AS_HELP_STRING([--disable-debug], [Do not include debugging statements]),
+ [enable_debug="$enableval"], [enable_debug="yes"])
+if test "$enable_debug" = "yes"; then
AC_DEFINE([NL_DEBUG], [1], [Define to 1 to enable debugging])
+else
+ enable_debug=no
+ AC_DEFINE([NL_DEBUG], [0], [Define to 1 to enable debugging])
fi
AC_CONFIG_SUBDIRS([doc])
diff --git a/include/nl-aux-core/nl-core.h b/include/nl-aux-core/nl-core.h
index 5b34bcb0..c6bdbebb 100644
--- a/include/nl-aux-core/nl-core.h
+++ b/include/nl-aux-core/nl-core.h
@@ -5,7 +5,7 @@
#include "base/nl-base-utils.h"
-#ifdef NL_DEBUG
+#if NL_DEBUG
#define NL_DBG(LVL, FMT, ARG...) \
do { \
if (LVL <= nl_debug) { \
diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c
index f16882f7..0caf10d1 100644
--- a/lib/cache_mngr.c
+++ b/lib/cache_mngr.c
@@ -58,7 +58,7 @@ static int include_cb(struct nl_object *obj, struct nl_parser_param *p)
struct nl_cache_ops *ops = ca->ca_cache->c_ops;
NL_DBG(2, "Including object %p into cache %p\n", obj, ca->ca_cache);
-#ifdef NL_DEBUG
+#if NL_DEBUG
if (nl_debug >= 4)
nl_object_dump(obj, &nl_debug_dp);
#endif
@@ -93,7 +93,7 @@ static int event_input(struct nl_msg *msg, void *arg)
NL_DBG(2, "Cache manager %p, handling new message %p as event\n",
mngr, msg);
-#ifdef NL_DEBUG
+#if NL_DEBUG
if (nl_debug >= 4)
nl_msg_dump(msg, stderr);
#endif
diff --git a/lib/route/neigh.c b/lib/route/neigh.c
index 91500244..1f19fed0 100644
--- a/lib/route/neigh.c
+++ b/lib/route/neigh.c
@@ -242,7 +242,7 @@ static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey,
uint16_t n_vlan;
char n_addr[0];
} _nl_packed *nkey;
-#ifdef NL_DEBUG
+#if NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
#endif
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
index ce68259c..488cff5b 100644
--- a/lib/route/route_obj.c
+++ b/lib/route/route_obj.c
@@ -345,7 +345,7 @@ static void route_keygen(struct nl_object *obj, uint32_t *hashkey,
uint32_t rt_prio;
char rt_addr[0];
} _nl_packed *rkey = NULL;
-#ifdef NL_DEBUG
+#if NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
#endif
@@ -502,7 +502,7 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
struct rtnl_route *old_route = (struct rtnl_route *) old_obj;
struct rtnl_nexthop *new_nh;
int action = new_obj->ce_msgtype;
-#ifdef NL_DEBUG
+#if NL_DEBUG
char buf[INET6_ADDRSTRLEN+5];
#endif
diff --git a/lib/utils.c b/lib/utils.c
index 4f5fd1aa..2363c027 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -52,7 +52,7 @@
int nl_debug = 0;
/** @cond SKIP */
-#ifdef NL_DEBUG
+#if NL_DEBUG
struct nl_dump_params nl_debug_dp = {
.dp_type = NL_DUMP_DETAILS,
};