From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0040.outbound.protection.outlook.com [104.47.40.40]) by dpdk.org (Postfix) with ESMTP id 811F33989 for ; Thu, 1 Sep 2016 06:42:21 +0200 (CEST) Received: from BN3PR0301CA0045.namprd03.prod.outlook.com (10.160.152.141) by BY2PR0301MB2007.namprd03.prod.outlook.com (10.163.196.29) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 1 Sep 2016 04:42:20 +0000 Received: from BL2FFO11FD056.protection.gbl (2a01:111:f400:7c09::106) by BN3PR0301CA0045.outlook.office365.com (2a01:111:e400:401e::13) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9 via Frontend Transport; Thu, 1 Sep 2016 04:42:19 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD056.mail.protection.outlook.com (10.173.161.184) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.587.6 via Frontend Transport; Thu, 1 Sep 2016 04:42:19 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u814g8R0029498; Wed, 31 Aug 2016 21:42:17 -0700 From: Shreyansh Jain To: , CC: , Shreyansh Jain Date: Thu, 1 Sep 2016 10:11:52 +0530 Message-ID: <1472704915-13112-3-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472704915-13112-1-git-send-email-shreyansh.jain@nxp.com> References: <1472704915-13112-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131171785402048090; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(92566002)(626004)(50226002)(81166006)(5660300001)(8936002)(586003)(305945005)(5003940100001)(11100500001)(104016004)(77096005)(2950100001)(68736007)(81156014)(87936001)(47776003)(8666005)(19580405001)(19580395003)(8676002)(4326007)(2906002)(7846002)(356003)(106466001)(229853001)(33646002)(86362001)(48376002)(5001770100001)(97736004)(36756003)(189998001)(105606002)(50466002)(50986999)(85426001)(69596002)(76176999)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB2007; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD056; 1:WfxFy8oRwnQ51AIB18+RMNRlvU6Fo96UDQniKUfAerrBP1S+ijRMJiSa2nmPE38w3DtFr/MtSls8yOc15EBeaqAq9ehIbTzZFMEx6lfpSlH7L+gaWGTIhflkNJ7zBh7m6oI4gnkp8df4T3GnnIarPBf0Q4dGu9qXr4NcGHkbkm62zTj2Avz3fV8XmLQIEKMgHHG6zZb1XYjS2KrwkZvjZM0ZKRC8iYG1377OXqE4GqLnoxcftJeFzbBePbnY+n+6nrer14Ucdjg/HAr0jthWAU/Ed2KZAOQTatxb1L6MNODPi4XJm7BgAICsalLp+vNOnKcp0DwsF9tB3PIM5EHppuukfeCI5nFr/LM02IKoa3hd5NdQ/csnXlMxokNjLkgVEyE1lumirajkgao6ctOgdTxGVpoJJeuBbc1UtKwKf1Q7WCggIrZ2IBHOcE+rivsUYo0cnWdv3sUazSvF46qsDKfxr7A06lmu6xSLwNEjh8Ww/47zkdzmr9n4/VUJDe9UEvaBxIl9C9yP0OhWjYt4a6O6/xDpgP46XCeMkHEuL3ERujltKTkU3AkawF4XILDe40UROM4p9WzpUp/6+wuCNjxwKgaMltQo8LQHJR1lcNeECDSfxVVQCy+XTUrjxrB1G6DL9I0Wv7xnaXN7lplxIIYYKIoXMk9SyeV898RMCBRv7AUCpo/v0M2sIeiO2gy+7qgg227Yhpjn9uYOTaUL4kFYQdemzI/loE1Fua4MGAE= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: a24881ad-8357-4157-fcfb-08d3d2225be5 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB2007; 2:m8VOwNGvmXKT9sLybaHyp6xgwFNdIv/dAb/Hc7q53ZpQ/pOuf2incKlGD+yvoyKlnmzLB89z66oggBdBNwm7Kj1xCd9czjFjbhfPBvx1JpoTXLPmgrewGPg4Bj6/ldbPhQzQzEdASi2guBWRee9KFF0DKS5hqkwmZqyDv1PP/TnPQi9BGSmsPh/laxXS8xKo; 3:Egcuo8psinmYJuorFCGO24mWZMzptOU9aXVAjVE8YZ+Y+T86/A2Jc40xR/PE0xxEgNYTIlVXcSilUeDAPsBCCFnVVK3Csmqt6/TlgEX15uDzqD2xvWACjkDBsKs77SEMIbQ3UjoirwLB01jn5/T0abV13YvXClSR+CT0j672GxrNNr5zxpKpmr8WhP5st73uH83tddWI8PMDJjrFZ5CmcWayMEAVIF9KB/YT8PE0Ias=; 25:be9tSg9UW8Zgm93NMZhtS3pbh7p8WCG1NreDpLvdni7nwFZryIm76EhZVTpxMp8WZEcp5MmsCVAmTGtuHMvlQm7+zf1/2dUQfHEQ/MQyCxzMNiP22HPNifHn45twb6JEslSt6QHjNpok/3hun82bBkv8X0EyGLnUFzhZqs5JVryi+b4y4SOa8hzvrch2nJlJX9h1vfXMcDWCDgo1nJ+6NPBh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MUdbJIxp9cGtclWPsPptsJLufmODHMiWvrM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(13015025)(13017025)(13024025)(13023025)(13018025)(10201501046)(3002001)(6055026); SRVR:BY2PR0301MB2007; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB2007; X-Forefront-PRVS: 0052308DC6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB2007; 23:xFuWL2IdJNx3e99IjI2FRbeJ0+k5c3WgcWkgwRD?= =?us-ascii?Q?H4XUOna1msvP+rkMph4JgkltD6SVKwp+cadKtuKCHnxlzyP9CnjIcKgRjbOq?= =?us-ascii?Q?LY5uKlq1Zm1hITGquWZX7u+r+vMG3DpKykGpSj7f9yqGbCvZV+Xjj9ve99Fj?= =?us-ascii?Q?i8gdW4jWX98NYapxNJQOiVZfcNoII64/FxpRxYLt5JPnxeiSTycloknWM0d+?= =?us-ascii?Q?X936wfOaEvVlj+mWqWeS21h9J+Am5P9KS3hC5treLvzbtMLLnmztK5NPFqpv?= =?us-ascii?Q?gtZbISMJLc64fgl0BS2o5/+GDy+CaWmqmh/OdzQfvHyODIP04PhVsIcbKzK9?= =?us-ascii?Q?4uOhwFT2sMDq2bwYi3bf+t5Rgj3Q26sakibAwf3mWsS0db4GD/9B/YZ9bBZz?= =?us-ascii?Q?zhquzsFFYke8l+w5uKxRDWCP+JtgJJEgbrOiLuBtErtYdxPJFTJAQg4s9LKo?= =?us-ascii?Q?X2qAJPUTVaGc9aYMbQYgVSEtlFGEMjYM/oRt2z/A4BXQxc0XXbMuEQNUwKhN?= =?us-ascii?Q?1KplmBMWjAfvoyXRNmSujhu78VdDh9Sj5hIRnsRGKKX8BQ0cgoF4bWiV1nN0?= =?us-ascii?Q?3g0mMJAbaTX6jlGc7mGPyq79SO/S0YMqDUevq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AX0I8NhTnbMovFJasu3PWvsPvricT1fdq2IEion96sUZ2vrH9jF+n+I15bRju5yQ2w8yGpc7109ao7/LW04k5Cg94bCdizsT4Gu0pfaACqPGqn0FmP3wL+ksiMeZhOWEF8FJAeJgCy1N+MN/Z/7tlKsK9JMCS7s6nuvtM=; 24:B8X/wQJ6m81GIYrJOOAQ6iahPNPZJ5I9xabSezO58xkkIZY2dRmv4rjp26eNGkxqLW3rckKK/DAw5RVZR88TaKwqXRnfPYYcDBuSSFpWcrs=; 7:LzA1aeZtkbzffrLh4Y2xhOZFEL7Ig3O+k7FK2capFcsMumLC6pov62FpvbblLJ38ippImaluNv1LMx7nDjQvJVrivwQE7jc1fJEAa5maoVaDUvqwMtwv41ty1O0D0/29Bd1DpYbMlnsJqgu+g/dfjda05HPPPyS04l4LZtTcylhxWyLdnaaS9TBgBW1Lw2pAy7MA0BNspbJEHC3+4YZ1oTwYv3I0uFp8xg5AokEfN6hMneXD0w43FQBKQmlvN18x SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2016 04:42:19.9708 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB2007 Subject: [dpdk-dev] [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2016 04:42:22 -0000 From: Jan Viktorin From: Jan Viktorin The eal_parse_sysfs_value function accepts a filename however, such interface introduces race-conditions to the code. Introduce the variant of this function that accepts an already opened file instead of a filename. Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain --- lib/librte_eal/common/eal_filesystem.h | 5 +++++ lib/librte_eal/linuxapp/eal/eal.c | 36 +++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h index fdb4a70..7875454 100644 --- a/lib/librte_eal/common/eal_filesystem.h +++ b/lib/librte_eal/common/eal_filesystem.h @@ -43,6 +43,7 @@ /** Path of rte config file. */ #define RUNTIME_CONFIG_FMT "%s/.%s_config" +#include #include #include #include @@ -115,4 +116,8 @@ eal_get_hugefile_temp_path(char *buffer, size_t buflen, const char *hugedir, int * Used to read information from files on /sys */ int eal_parse_sysfs_value(const char *filename, unsigned long *val); +/** Function to read a single numeric value from a file on the filesystem. + * Used to read information from files on /sys */ +int eal_parse_sysfs_valuef(FILE *f, unsigned long *val); + #endif /* EAL_FILESYSTEM_H */ diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index d5b81a3..f912e4e 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -126,13 +126,30 @@ rte_eal_get_configuration(void) return &rte_config; } +int +eal_parse_sysfs_valuef(FILE *f, unsigned long *val) +{ + char buf[BUFSIZ]; + char *end = NULL; + + RTE_VERIFY(f != NULL); + + if (fgets(buf, sizeof(buf), f) == NULL) + return -1; + + *val = strtoul(buf, &end, 0); + if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) + return -2; + + return 0; +} + /* parse a sysfs (or other) file containing one integer value */ int eal_parse_sysfs_value(const char *filename, unsigned long *val) { + int ret; FILE *f; - char buf[BUFSIZ]; - char *end = NULL; if ((f = fopen(filename, "r")) == NULL) { RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n", @@ -140,21 +157,18 @@ eal_parse_sysfs_value(const char *filename, unsigned long *val) return -1; } - if (fgets(buf, sizeof(buf), f) == NULL) { + ret = eal_parse_sysfs_valuef(f, val); + if (ret == -1) { RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n", - __func__, filename); - fclose(f); - return -1; + __func__, filename); } - *val = strtoul(buf, &end, 0); - if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) { + else if (ret < 0) { RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n", __func__, filename); - fclose(f); - return -1; } + fclose(f); - return 0; + return ret; } -- 2.7.4