]> granicus.if.org Git - libnl/commitdiff
nl: Print file:line:func in debugging messages and provide --disable-debug to disable...
authorThomas Graf <tgraf@suug.ch>
Tue, 2 Apr 2013 09:39:30 +0000 (11:39 +0200)
committerThomas Graf <tgraf@suug.ch>
Tue, 2 Apr 2013 09:39:30 +0000 (11:39 +0200)
Compiling libnl with --disable-debug will result in the ignorance
of the 'NLDBG' environment variable.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
configure.ac
include/netlink-private/netlink.h
lib/route/neigh.c
lib/route/route_obj.c
lib/utils.c

index 744e34ed8ea01492bc04dc416b2c200b0d6c0f74..bd1f3ac918a32beb011e2448da56f5a28f003f4b 100644 (file)
@@ -92,6 +92,11 @@ AC_ARG_ENABLE([pthreads],
        [enable_pthreads="$enableval"], [enable_pthreads="yes"])
 AM_CONDITIONAL([DISABLE_PTHREADS], [test "$enable_pthreads" = "no"])
 
+AC_ARG_ENABLE([debug],
+       AS_HELP_STRING([--disable-debug], [Do not include debugging statements]),
+       [enable_debug="$enableval"], [enable_debug="yes"])
+AM_CONDITIONAL([ENABLE_DEBUG], [test "$enable_debug" = "no" ])
+
 AC_CHECK_LIB([m], [pow], [], AC_MSG_ERROR([libm is required]))
 
 if test "x$enable_pthreads" = "xno"; then
@@ -100,6 +105,10 @@ else
     AC_CHECK_LIB([pthread], [pthread_mutex_lock], [], AC_MSG_ERROR([libpthread is required]))
 fi
 
+if test "x$enable_debug" = "xyes"; then
+    AC_DEFINE([NL_DEBUG], [1], [Define to 1 to enable debugging])
+fi
+
 AC_CONFIG_SUBDIRS([doc])
 
 AC_CONFIG_FILES([
index 6ae6d179a8e6ee1d62c336ae395a25528b88892b..2e511bf1815aa6a2e0c6d908f3ad103d565c762b 100644 (file)
@@ -80,24 +80,29 @@ struct trans_list {
        struct nl_list_head list;
 };
 
-#define NL_DEBUG       1
-
-#define NL_DBG(LVL,FMT,ARG...) \
-       do {    \
-               if (LVL <= nl_debug) \
-                       fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \
+#ifdef NL_DEBUG
+#define NL_DBG(LVL,FMT,ARG...)                                         \
+       do {                                                            \
+               if (LVL <= nl_debug)                                    \
+                       fprintf(stderr,                                 \
+                               "DBG<" #LVL ">%20s:%-4u %s: " FMT,      \
+                               __FILE__, __LINE__,                     \
+                               __PRETTY_FUNCTION__, ##ARG);            \
        } while (0)
+#else /* NL_DEBUG */
+#define NL_DBG(LVL,FMT,ARG...) do { } while(0)
+#endif /* NL_DEBUG */
 
 #define BUG()                                                          \
        do {                                                            \
-               NL_DBG(1, "BUG: %s:%d\n",                               \
-                       __FILE__, __LINE__);                            \
+               fprintf(stderr, "BUG at file position %s:%d:%s\n",      \
+                       __FILE__, __LINE__, __PRETTY_FUNCTION__);       \
                assert(0);                                              \
        } while (0)
 
 #define APPBUG(msg)                                                    \
        do {                                                            \
-               NL_DBG(1, "APPLICATION BUG: %s:%d:%s: %s\n",            \
+               fprintf(stderr, "APPLICATION BUG: %s:%d:%s: %s\n",      \
                        __FILE__, __LINE__, __PRETTY_FUNCTION__, msg);  \
                assert(0);                                              \
        } while(0)
index 288bb857d16c0689fc98fca847440bf2d724e8c1..ad26b4d0eca3acd6947380132a027ac228864afb 100644 (file)
@@ -211,7 +211,9 @@ static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey,
                uint32_t        n_ifindex;
                char            n_addr[0];
        } __attribute__((packed)) *nkey;
+#ifdef NL_DEBUG
        char buf[INET6_ADDRSTRLEN+5];
+#endif
 
        if (neigh->n_family == AF_BRIDGE) {
                if (neigh->n_lladdr)
index 795047fbdf486bccb4dcc9fbfa5f780fa1f733d5..f2de523e37be5613ca3d8634ef7e22e6871a46d1 100644 (file)
@@ -307,7 +307,9 @@ static void route_keygen(struct nl_object *obj, uint32_t *hashkey,
                uint32_t        rt_prio;
                char            rt_addr[0];
        } __attribute__((packed)) *rkey;
+#ifdef NL_DEBUG
        char buf[INET6_ADDRSTRLEN+5];
+#endif
 
        if (route->rt_dst)
                addr = route->rt_dst;
@@ -449,8 +451,10 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
        struct rtnl_route *new_route = (struct rtnl_route *) new_obj;
        struct rtnl_route *old_route = (struct rtnl_route *) old_obj;
        struct rtnl_nexthop *new_nh;
-       char buf[INET6_ADDRSTRLEN+5];
        int action = new_obj->ce_msgtype;
+#ifdef NL_DEBUG
+       char buf[INET6_ADDRSTRLEN+5];
+#endif
 
        /*
         * ipv6 ECMP route notifications from the kernel come as
index 3bfa60441b75c493efffc578af31b52eae7d437f..3012fea9d59f62ddb3a754ec2c2a2a84b83dcbeb 100644 (file)
@@ -49,6 +49,7 @@
 int nl_debug = 0;
 
 /** @cond SKIP */
+#ifdef NL_DEBUG
 struct nl_dump_params nl_debug_dp = {
        .dp_type = NL_DUMP_DETAILS,
 };
@@ -65,6 +66,7 @@ static void __init nl_debug_init(void)
 
        nl_debug_dp.dp_fd = stderr;
 }
+#endif
 
 int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *))
 {