mesh: Helper packet print should depend on debug setting
authorInga Stotland <inga.stotland@intel.com>
Sun, 31 May 2020 04:41:24 +0000 (21:41 -0700)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 18 Dec 2020 05:40:30 +0000 (11:10 +0530)
This changes the utility function print_packet() to check if
daemon is running in debug mode.

Change-Id: Ib23f995a3e89297ad239a4a3557bb6b7600b47ed
Signed-off-by: anuj.bhumiya <anuj.bhumiya@samsung.com>
mesh/main.c
mesh/util.c
mesh/util.h

index aecb8bf..e90f5c4 100644 (file)
@@ -36,6 +36,7 @@
 #include "mesh/crypto.h"
 #include "mesh/dbus.h"
 #include "mesh/mesh-io.h"
+#include "mesh/util.h"
 
 static const char *config_dir;
 static const char *mesh_conf_fname;
@@ -225,7 +226,7 @@ int main(int argc, char *argv[])
                        detached = false;
                        break;
                case 'd':
-                       l_debug_enable("*");
+                       enable_debug();
                        break;
                case 'c':
                        config_dir = optarg;
index f4bc461..f9b46d4 100644 (file)
 
 #include "mesh/util.h"
 
+static bool debug_enabled;
+
 void print_packet(const char *label, const void *data, uint16_t size)
 {
        struct timeval pkt_time;
 
+       if (!debug_enabled)
+               return;
+
        gettimeofday(&pkt_time, NULL);
 
        if (size > 0) {
@@ -153,3 +158,9 @@ void del_path(const char *path)
 {
        nftw(path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
 }
+
+void enable_debug(void)
+{
+       debug_enabled = true;
+       l_debug_enable("*");
+}
index 092d330..93c2d86 100644 (file)
@@ -24,3 +24,4 @@ size_t hex2str(uint8_t *in, size_t in_len, char *out, size_t out_len);
 void print_packet(const char *label, const void *data, uint16_t size);
 int create_dir(const char *dir_name);
 void del_path(const char *path);
+void enable_debug(void);