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 BAED9A04B3; Fri, 8 Nov 2019 11:24:06 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E878F1C19C; Fri, 8 Nov 2019 11:22:01 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 535581C12B for ; Fri, 8 Nov 2019 11:21:54 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xA8AFsTk006980; Fri, 8 Nov 2019 02:21:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=C+L7Qmkj7Fln0xikmUICqREKSDSrfrf7J7a5HQFDFjY=; b=ENlz8/PcKNFM8nu4o+Q9G7QBCaSVcn3kZ6u2E8Q585kUK2/25ZF3WlzZE79vioJS6LaW Q5cBbGg51dUBJuSt+n8NDYqRs5v/KtPCVsx2XcGf/B2frsZoooRSfAKrwOQ+qkfuyJzC gL4JGWMY7LKUkQ3Gt/REAwfInPdVsYR0IXEslV654XzASlVUIiEWiAj9hM7fylxeLjFm ATb22fV6yGCNlumWyXa35oxUfCD1m74vMg1/Yk62K80Rz8YQd14Wi1VNoA+g7INwMKlb ZLM4fxCa4L6cnY2M+0qFuBcaG6w4io876CtY0UsuIHWZeMCbBhW5FfOJAYIO/fvr06R7 ag== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2w4fq6whw7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 08 Nov 2019 02:21:53 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 8 Nov 2019 02:21:52 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 8 Nov 2019 02:21:52 -0800 Received: from kk-box-0.marvell.com (unknown [10.95.130.41]) by maili.marvell.com (Postfix) with ESMTP id E48DE3F703F; Fri, 8 Nov 2019 02:21:50 -0800 (PST) From: To: , , CC: Krzysztof Kanas Date: Fri, 8 Nov 2019 11:21:35 +0100 Message-ID: <20191108102135.7249-4-kkanas@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191108102135.7249-1-kkanas@marvell.com> References: <20191108102135.7249-1-kkanas@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-08_02:2019-11-07,2019-11-08 signatures=0 Subject: [dpdk-dev] [PATCH v3 3/3] test: fix FreeBSD file closing function 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" From: Krzysztof Kanas The FreeBSD was iterating over non existing procfs entries, where sysctl could give same information. Signed-off-by: Krzysztof Kanas --- app/test/process.h | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/app/test/process.h b/app/test/process.h index 34afac5a1f39..77bf11316355 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -16,6 +16,13 @@ #include /* strlcpy */ +#ifdef RTE_EXEC_ENV_FREEBSD +#include +#include +#include +#include +#endif + #ifdef RTE_EXEC_ENV_FREEBSD #define self "curproc" #define exe "file" @@ -34,7 +41,49 @@ extern uint16_t flag_for_send_pkts; /* close all open file descriptors, check /proc/self/fd to only * call close on open fds. Exclude fds 0, 1 and 2 */ -#ifdef RTE_EXEC_ENV_LINUX +#ifdef RTE_EXEC_ENV_FREEBSD +static inline void +close_files(void) +{ + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_FILEDESC }; + size_t sysctl_len; + void *oldp; + int ret; + + mib[3] = getpid(); + ret = sysctl(mib, 4, NULL, &sysctl_len, NULL, 0); + if (ret < 0) { + rte_panic("Error sysctl failed %d %d %s\n", ret, errno, + strerror(errno)); + return; + } + oldp = malloc(sysctl_len); + if (!oldp) { + rte_panic("Error malloc failed\n"); + return; + } + ret = sysctl(mib, 4, oldp, &sysctl_len, NULL, 0); + if (ret < 0) { + ret = errno; + free(oldp); + rte_panic("Error sysctl failed %d %d %s\n", ret, errno, + strerror(errno)); + } + char *curr = oldp, *end = (char *)oldp + sysctl_len; + struct kinfo_file *kf_info; + while (curr < end) { + kf_info = (struct kinfo_file *)curr; + if (kf_info->kf_fd <= 2) { + curr += kf_info->kf_structsize; + continue; + } + close(kf_info->kf_fd); + curr += kf_info->kf_structsize; + } + free(oldp); +} + +#else static inline void close_files(void) { -- 2.21.0