From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D0CFC04AB4 for ; Thu, 16 May 2019 05:41:22 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 350C420848 for ; Thu, 16 May 2019 05:41:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 350C420848 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CCC025920; Thu, 16 May 2019 07:41:20 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id B113D4CA6 for ; Thu, 16 May 2019 07:41:19 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 May 2019 22:41:18 -0700 X-ExtLoop1: 1 Received: from skx-pink.jf.intel.com ([10.54.80.236]) by orsmga003.jf.intel.com with ESMTP; 15 May 2019 22:41:18 -0700 From: Mesut Ali Ergin To: olivier.matz@6wind.com Cc: dev@dpdk.org, Mesut Ali Ergin Date: Wed, 15 May 2019 22:41:07 -0700 Message-Id: <1557985267-280205-1-git-send-email-mesut.a.ergin@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] kvargs: trim spaces at the beginning and end of key and values 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" When arguments delimited with RTE_KVARGS_PAIRS_DELIM happen to have spaces before and after the delimiter, the rte_kvargs_process() can not match them to the intended key. For example, the first argument below triggers the support-multi-driver handler as expected, but the second one silently fails to do so. -w '84:00.0,support-multi-driver=1' -w '84:00.0, support-multi-driver=1' Signed-off-by: Mesut Ali Ergin --- lib/librte_kvargs/rte_kvargs.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index f7030c6..1f45bc6 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -10,6 +10,32 @@ #include "rte_kvargs.h" + +/* trim leading and trailing spaces */ +static char * +trim_space(char *str) +{ + char *start, *end; + + for (start = str; *start; start++) { + if (!isspace((unsigned char) start[0])) + break; + } + + for (end = start + strlen(start); end > start + 1; end--) { + if (!isspace((unsigned char) end[-1])) + break; + } + + *end = 0; + + /* Shift from "start" to the beginning of the string */ + if (start > str) + memmove(str, start, (end - start) + 1); + + return str; +} + /* * Receive a string with a list of arguments following the pattern * key=value,key=value,... and insert them into the list. @@ -38,8 +64,10 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) if (i >= RTE_KVARGS_MAX) return -1; - kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2); - kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2); + kvlist->pairs[i].key = trim_space(strtok_r(str, + RTE_KVARGS_KV_DELIM, &ctx2)); + kvlist->pairs[i].value = trim_space(strtok_r(NULL, + RTE_KVARGS_KV_DELIM, &ctx2)); if (kvlist->pairs[i].key == NULL || kvlist->pairs[i].value == NULL) return -1; -- 2.7.4