cfgfile: use log for error messages
authorStephen Hemminger <stephen@networkplumber.org>
Thu, 18 Jul 2019 17:18:11 +0000 (10:18 -0700)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 18 Jul 2019 22:47:50 +0000 (00:47 +0200)
In general, DPDK libraries to not print error messages to
stdout because that is often redirected to /dev/null for daemons.
This patch changes cfgfile library to use RTE_LOG with its
own type.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/Makefile
lib/librte_cfgfile/Makefile
lib/librte_cfgfile/rte_cfgfile.c

index bdb8a67..41c463d 100644 (file)
@@ -19,6 +19,7 @@ DEPDIRS-librte_mbuf := librte_eal librte_mempool
 DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DEPDIRS-librte_timer := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
+DEPDIRS-librte_cfgfile := librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
 DEPDIRS-librte_cmdline := librte_eal librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev
index d951256..2c7115f 100644 (file)
@@ -11,6 +11,7 @@ LIB = librte_cfgfile.a
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -I$(SRCDIR)/../librte_eal/common/include
+LDLIBS += -lrte_eal
 
 EXPORT_MAP := rte_cfgfile_version.map
 
index 1ef2985..3884151 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <rte_string_fns.h>
 #include <rte_common.h>
+#include <rte_log.h>
 
 #include "rte_cfgfile.h"
 
@@ -26,6 +27,12 @@ struct rte_cfgfile {
        struct rte_cfgfile_section *sections;
 };
 
+static int cfgfile_logtype;
+
+#define CFG_LOG(level, fmt, args...)                                   \
+       rte_log(RTE_LOG_ ## level, cfgfile_logtype, "%s(): " fmt "\n",  \
+               __func__, ## args)
+
 /** when we resize a file structure, how many extra entries
  * for new sections do we add in */
 #define CFG_ALLOC_SECTION_BATCH 8
@@ -128,7 +135,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params)
        unsigned int i;
 
        if (!params) {
-               printf("Error - missing cfgfile parameters\n");
+               CFG_LOG(ERR, "missing cfgfile parameters\n");
                return -EINVAL;
        }
 
@@ -141,7 +148,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params)
        }
 
        if (valid_comment == 0) {
-               printf("Error - invalid comment characters %c\n",
+               CFG_LOG(ERR, "invalid comment characters %c\n",
                       params->comment_character);
                return -ENOTSUP;
        }
@@ -178,7 +185,7 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
                size_t len = strnlen(buffer, sizeof(buffer));
                lineno++;
                if ((len >= sizeof(buffer) - 1) && (buffer[len-1] != '\n')) {
-                       printf("Error line %d - no \\n found on string. "
+                       CFG_LOG(ERR, " line %d - no \\n found on string. "
                                        "Check if line too long\n", lineno);
                        goto error1;
                }
@@ -198,8 +205,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
                        /* section heading line */
                        char *end = memchr(buffer, ']', len);
                        if (end == NULL) {
-                               printf("Error line %d - no terminating ']'"
-                                       "character found\n", lineno);
+                               CFG_LOG(ERR,
+                                       "line %d - no terminating ']' character found\n",
+                                       lineno);
                                goto error1;
                        }
                        *end = '\0';
@@ -213,8 +221,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
                        split[0] = buffer;
                        split[1] = memchr(buffer, '=', len);
                        if (split[1] == NULL) {
-                               printf("Error line %d - no '='"
-                                       "character found\n", lineno);
+                               CFG_LOG(ERR,
+                                       "line %d - no '=' character found\n",
+                                       lineno);
                                goto error1;
                        }
                        *split[1] = '\0';
@@ -236,8 +245,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
 
                        if (!(flags & CFG_FLAG_EMPTY_VALUES) &&
                                        (*split[1] == '\0')) {
-                               printf("Error at line %d - cannot use empty "
-                                                       "values\n", lineno);
+                               CFG_LOG(ERR,
+                                       "line %d - cannot use empty values\n",
+                                       lineno);
                                goto error1;
                        }
 
@@ -397,7 +407,8 @@ int rte_cfgfile_set_entry(struct rte_cfgfile *cfg, const char *sectionname,
                                sizeof(curr_section->entries[i].value));
                        return 0;
                }
-       printf("Error - entry name doesn't exist\n");
+
+       CFG_LOG(ERR, "entry name doesn't exist\n");
        return -EINVAL;
 }
 
@@ -552,3 +563,10 @@ rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
 {
        return rte_cfgfile_get_entry(cfg, sectionname, entryname) != NULL;
 }
+
+RTE_INIT(cfgfile_init)
+{
+       cfgfile_logtype = rte_log_register("lib.cfgfile");
+       if (cfgfile_logtype >= 0)
+               rte_log_set_level(cfgfile_logtype, RTE_LOG_INFO);
+}