From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 63A29A0471 for ; Thu, 18 Jul 2019 02:48:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F12C45B3C; Thu, 18 Jul 2019 02:48:34 +0200 (CEST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by dpdk.org (Postfix) with ESMTP id 312F13977 for ; Thu, 18 Jul 2019 02:48:31 +0200 (CEST) Received: by mail-pl1-f180.google.com with SMTP id k8so12910524plt.3 for ; Wed, 17 Jul 2019 17:48:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BWDc2KzXp1C4MJaBxyKhqZjuIf1Ds8kSxISbqBiAlUo=; b=ygsO4C2TIPzKfytCJVOkI01IMF1/vQUjhkO7jD6iiu/Jlbbsm9OSSGk98ge1n7/oc4 0Ygl3WQzt9Fsb0skMpe1ccevZOdj2/i6X4/vKTSpSRS21c6L4ilF/TCgfUVmia6AjBAo OSYbp6SqutdNYxDGsJgu734fSY27GZxEntT84CAfIzOIO40uTRd53+BnvOV20c4pYdVK TRM89b33HwkgQQpWz9Rqm7/3jfJHCqvGubx4O2v1OJcxK48nJTcc04x13bJOyWmXPuyv hJKJDIKt3MePSaZv9VBk/wdLGZafvELAPNcSVJYx4PGoqq0rnvrJsQNScMyi/ZBOc/Nc OZMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BWDc2KzXp1C4MJaBxyKhqZjuIf1Ds8kSxISbqBiAlUo=; b=SB4eXI0gq4/VyKnG5uCpPv2nUfdHodI9wne/mzqfs0YAYsQRPT3gV/F81rf2U/q/Pd zkNFzCfIwMJsDRL+RKCYyz1/fykTYWUhYTLDHiB9MVzXI7YFendh5XavRaSzb9EGMYgc QvWyG7MMy0URjKacS7DO9DfoYVggRgbSU1qlT2l0D6Tls/NLozCaGSg7XQcYRVONpBqd XjxYqg/CL7zqyyGSCMJA+9738AoXMQu8Q0j19RqIcIVUhu4ssGiNcgxJkgxzvXrsUkBF hSpUqI79Hl9/temMQak1Y1nJz9HV+PaWtkhToczTShcRscfuEzS3NnQDpbx/anzPM58d SH0g== X-Gm-Message-State: APjAAAX3hHYjl2WpvfR4IMibmOcdYAS741bL+lYiHi1P+bJhnsdZ35hx cI3NIQqUPp42pLu2rJKKu5jXEjDk X-Google-Smtp-Source: APXvYqzdW2seK6XuMr6bJ5+khXd0JU03s4IjbVvIsRpXRfG8FC9l2LBtUwaNNcShId5xxVCEF0qBbA== X-Received: by 2002:a17:902:684:: with SMTP id 4mr47068302plh.138.1563410909926; Wed, 17 Jul 2019 17:48:29 -0700 (PDT) Received: from xps13.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 131sm30459808pfx.57.2019.07.17.17.48.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 17:48:27 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Wed, 17 Jul 2019 17:48:21 -0700 Message-Id: <20190718004822.25431-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190718004822.25431-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> <20190718004822.25431-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2 2/3] cfgfile: use RTE_LOG for errors X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- lib/librte_cfgfile/Makefile | 1 + lib/librte_cfgfile/rte_cfgfile.c | 38 +++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/librte_cfgfile/Makefile b/lib/librte_cfgfile/Makefile index d9512565e559..4fc711778699 100644 --- a/lib/librte_cfgfile/Makefile +++ b/lib/librte_cfgfile/Makefile @@ -11,6 +11,7 @@ LIB = librte_cfgfile.a CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) CFLAGS += -I$(SRCDIR)/../librte_eal/common/include +LDFLAGS += -lrte_log EXPORT_MAP := rte_cfgfile_version.map diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 1ef298592fa5..388415147930 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -9,6 +9,7 @@ #include #include #include +#include #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); +} -- 2.17.1