From patchwork Thu Aug 8 19:40:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Droneaud X-Patchwork-Id: 2841365 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7359A9F271 for ; Thu, 8 Aug 2013 19:53:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FFBA2035C for ; Thu, 8 Aug 2013 19:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7349B2034E for ; Thu, 8 Aug 2013 19:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966159Ab3HHTxD (ORCPT ); Thu, 8 Aug 2013 15:53:03 -0400 Received: from smtp23.services.sfr.fr ([93.17.128.22]:13312 "EHLO smtp23.services.sfr.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966063Ab3HHTwz (ORCPT ); Thu, 8 Aug 2013 15:52:55 -0400 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2316.sfr.fr (SMTP Server) with ESMTP id C3DBA700008A; Thu, 8 Aug 2013 21:42:26 +0200 (CEST) Received: from localhost.localdomain (187.20.90.92.rev.sfr.net [92.90.20.187]) by msfrf2316.sfr.fr (SMTP Server) with ESMTP id 01CDD700009A; Thu, 8 Aug 2013 21:42:18 +0200 (CEST) X-SFR-UUID: 20130808194223748.01CDD700009A@msfrf2316.sfr.fr Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id r78JgFKl003059; Thu, 8 Aug 2013 21:42:15 +0200 Received: (from ydroneaud@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id r78JgAaO003058; Thu, 8 Aug 2013 21:42:10 +0200 From: Yann Droneaud To: linux-rdma@vger.kernel.org Cc: Yann Droneaud Subject: [PATCH libibverbs v2 03/11] read_config(): open configuration directory with open() Date: Thu, 8 Aug 2013 21:40:46 +0200 Message-Id: <1481ee18014b5df0f80cf2d5196e1b6c3465600e.1375952089.git.ydroneaud@opteya.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Get a file descriptor pointing to the IBV_CONFIG_DIR, so that it could be used with fstatat() and openat() later. Use fdopendir()[1][2] after open()'ing the directory instead of opendir(). Compatibility note: - According to Gnulib, fdopendir() is not available on older systems. Links: - [1] fdopendir - [2] fdopendir(3) Signed-off-by: Yann Droneaud --- src/init.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/init.c b/src/init.c index e67469e..34150b5 100644 --- a/src/init.c +++ b/src/init.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -292,14 +293,23 @@ static void read_config_file(const char *path) static void read_config(void) { + int conf_dirfd; DIR *conf_dir; struct dirent *dent; char *path; - conf_dir = opendir(IBV_CONFIG_DIR); + conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_CLOEXEC); + if (conf_dirfd == -1) { + fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n", + IBV_CONFIG_DIR); + return; + } + + conf_dir = fdopendir(conf_dirfd); if (!conf_dir) { fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n", IBV_CONFIG_DIR); + close(conf_dirfd); return; }