From patchwork Thu Jul 18 17:18:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56735 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1D39D4C94; Thu, 18 Jul 2019 19:18:26 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 09D7F231E for ; Thu, 18 Jul 2019 19:18:18 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id p184so12916693pfp.7 for ; Thu, 18 Jul 2019 10:18:18 -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=tMQ3l7eSh2IG5E3ZjmkQhbshkvLKRygnPBc/DveCeQk=; b=Tk/6BlUa6AWXm1T+Wxc7kJfnV69w9pQ8rtP6Giw2ZcseKCzPU7o6uy2cUu5Ngge6Ki EfyALPZNnOFkKetUPGyWqtTniqUG4ekV0drMuh7aIb7syZNPchmKXv3Gza3YI8JPsvJI JriW8BKPf9bCYJ4Noi9sd1Oe0HW/B/MV5eF1Kl9urwux+ah7eSVT14wNRE1VfykOe8cP fQWtcnjo3m/pr1GWgaTxllkEZfyishvPJLaTu4WPJHQJdESBMWX6bMBGdnxQFE2CAZNv U/XwdaHZ2ZXvgLjBLXKGtyWF2/QnxYpqDI/QBJ8nCrVabtD1hhtq7aSWMRnyfn34+q8E Hznw== 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=tMQ3l7eSh2IG5E3ZjmkQhbshkvLKRygnPBc/DveCeQk=; b=akOQY5CVt6xGcaZr9nIFtl67U4EmNQmt/T7XvN0EGaQ+bJzaG/sr7RzZf+yQApAfvW MhyqKrwmYXHtph5hL8Zt9k3B1PahVw59hLQzX4E+S2uRFJT93YhvYuPLsIOu/XTudy/j pSm8cNmoh/j+H8hoOQmxETJkBYMmlhPyNzEP1vTw2GRvIKSJcsQjtVUShf9c0uQxQnKa unDOTdmoQMmzz0CN+qXwYs8JYf4uLCZsfoatFwQZEAf+YKP8QHdzu1SXtjMviqm+2odX Pakd4Zn/VZc9M7zQKkcDoJcDAWT0ETbVU6jiwUEVe9/Y1QZP/IBmiuTJ5c0rZIucmcpu TYFQ== X-Gm-Message-State: APjAAAVxBg3jOWUY/DMpqA6SXTK+aMWxc6JuJHMiSYY31VDtlBIP6Lqq FgrazZyajTNukqfaAgGxcwCYWgAX X-Google-Smtp-Source: APXvYqyQSjGWtOzYEQtoa1mKc5pr3HL9GgBupDcJlWQ22mDZUm+n9T7D7D1YXVzb9GL9i7NtVmdYUA== X-Received: by 2002:a63:6ec6:: with SMTP id j189mr50033703pgc.168.1563470297824; Thu, 18 Jul 2019 10:18:17 -0700 (PDT) Received: from localhost.localdomain ([67.23.203.6]) by smtp.gmail.com with ESMTPSA id 137sm36038021pfz.112.2019.07.18.10.18.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 10:18:16 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 18 Jul 2019 10:18:11 -0700 Message-Id: <20190718171812.3209-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190718171812.3209-1-stephen@networkplumber.org> References: <20190716172741.21399-1-stephen@networkplumber.org> <20190718171812.3209-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v3 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/Makefile | 1 + lib/librte_cfgfile/rte_cfgfile.c | 38 +++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index bdb8a67e2d9d..41c463d92139 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -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 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); +}