From patchwork Wed Jun 1 18:19:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Patterson X-Patchwork-Id: 9147961 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19779607D8 for ; Wed, 1 Jun 2016 18:23:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D3F12040D for ; Wed, 1 Jun 2016 18:23:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01A2326E04; Wed, 1 Jun 2016 18:23:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E6926265F9 for ; Wed, 1 Jun 2016 18:23:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b8AlU-0001hy-40; Wed, 01 Jun 2016 18:21:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b8AlS-0001hb-Bt for xen-devel@lists.xen.org; Wed, 01 Jun 2016 18:21:10 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 05/41-06513-5972F475; Wed, 01 Jun 2016 18:21:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42K5GHrASXeKun+ 4wfHDWhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0b3te2MBTMkKvr3r2NvYGwQ6WLk4hASmMAo 0Xf6HBOIwyJwiUXiyvsPrCCOhMA7FompLQvYuhg5gZwYifV/zjND2FUSbQv2MIHYQgLyEn8PT GGEGDWRSeL383tARRwcbAIaEqduuIDUiAhIS1z7fBmshlngLaNE943z7CAJYYEgiZWP/oMNZR FQlZizfRFYL6+AvcT8vdEQu+Qkzh//yTyBkW8BI8MqRo3i1KKy1CJdQ1O9pKLM9IyS3MTMHF1 DA2O93NTi4sT01JzEpGK95PzcTYzAUGEAgh2Ma7Z7HmKU5GBSEuXdKOwfLsSXlJ9SmZFYnBFf VJqTWnyIUYaDQ0mCN1oNKCdYlJqeWpGWmQMMWpi0BAePkgjvFJA0b3FBYm5xZjpE6hSjMceW3 9fWMnFsm3pvLZMQS15+XqqUOK8JSKkASGlGaR7cIFg0XWKUlRLmZQQ6TYinILUoN7MEVf4Voz gHo5IwbwbIFJ7MvBK4fa+ATmECOiU+wwfklJJEhJRUA2OmwJeTFr6NK0Kig0/WaxZ//nwz6mD iYoljW7qstBim/VlTuu3m2fNWjCU6BvMMK9rM99W+PnjT5Pqt822GuY0GgWpR+05sk4tZNIf9 NPe0260HDhU93lmj9tWr63rDeRHjXQvd1JfO8llYwRquPZ2d9ew+iY/3Kko2PX+6nFUgPb/i8 vKzerOUWIozEg21mIuKEwFNCKs3oQIAAA== X-Env-Sender: cjp256@gmail.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1464805267!43287510!1 X-Originating-IP: [209.85.192.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55054 invoked from network); 1 Jun 2016 18:21:08 -0000 Received: from mail-qg0-f66.google.com (HELO mail-qg0-f66.google.com) (209.85.192.66) by server-14.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Jun 2016 18:21:08 -0000 Received: by mail-qg0-f66.google.com with SMTP id z67so7262012qgz.1 for ; Wed, 01 Jun 2016 11:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=o2Smgn/3BfVhyxZ/oqH83GTGXwGqdJjJiKu9mQzflpM=; b=tdOYUpEAkXxJD8lK6BS5EyUMj5l/QQDd1dVIg92gmYSQB8h3I7MwyZVSb+bilu2RIS LaQ+/bSFulutQSjxRIkFTtuqjSfSjZfqzphSIaws4JxCHYF7uIZwZgnF9GnijLN8m8Bn am0LJxf+K/XdSt2TfDrDT9CCW3ACQb1Ht6vXormbTFJFzb4qXEfVBaG7Sl9HnXOCWkAZ w+IYf6aT58zIpc+yMvU9nZ6pXxDKtaQ0v+1/AujnuzM3byAZxy/FzfJPLOvSU5MkMF6s X7qtQHi1OE12inFjNVPumSykMXApZr/jUYLcy26ADi4E2g6MeAHnZRf7sJTLFNZKdf8p 8DZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=o2Smgn/3BfVhyxZ/oqH83GTGXwGqdJjJiKu9mQzflpM=; b=e+u5rJ7Fdztx63xLZnYVNjrBy+G8ptU8a45Mdor6IWoYHOBwKTXxNo2cdQRm2ARxHY 1cSBmX4E64LvQmYBaI1tlp/VkJgy54/AbenM16ISvnbghIz1yllZhhGBuHgiecqptEKI NnCQhnPOxGACY8F/NP3m3nXCdppjRbeHgfIx9BBN5Vq/B/7/Lc8NQ448CR/ce8CViJhv 9y8TVF/GeIppQz0KRaLQexDvQ8PTskcvRmKegRHDV87clbCIBreoaDhWwhW1mwg2q5Mx 67q461dXcEsRGuZzDpU0Ht/4zlu9kwzf6aFsKvUiYDxiEc8lSFJQdzyLabTwAJztSF9R ux4A== X-Gm-Message-State: ALyK8tKbDCtXp/d/NB8TqG3wG/Ui6F6yzUHsS5dgh8Z9PJ1f26onJ8lpTtMTPsU7QKrxHg== X-Received: by 10.140.140.200 with SMTP id 191mr39591608qhm.0.1464805267377; Wed, 01 Jun 2016 11:21:07 -0700 (PDT) Received: from roost.members.linode.com (chrispatterson.net. [66.175.209.160]) by smtp.gmail.com with ESMTPSA id s84sm10788280qhc.13.2016.06.01.11.21.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Jun 2016 11:21:06 -0700 (PDT) From: Chris Patterson To: xen-devel@lists.xen.org Date: Wed, 1 Jun 2016 14:19:37 -0400 Message-Id: <1464805178-8989-1-git-send-email-cjp256@gmail.com> X-Mailer: git-send-email 2.1.4 Cc: sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, Chris Patterson , jbeulich@suse.com Subject: [Xen-devel] [[PATCH v2 1/2] libfsimage: replace deprecated readdir_r() with readdir() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Patterson Replace the usage of readdir_r() with readdir() to address a compilation error under glibc due to the deprecation of readdir_r for their next release (2.24) [1, 2]. --- From the GNU libc manual [3]: " It is expected that future versions of POSIX will obsolete readdir_r and mandate the level of thread safety for readdir which is provided by the GNU C Library and other implementations today. " There is a filed bug in the Austin Group Defect Tracker [4] in which 'dalias' proposes (in comment 0001632) that: " I would like to propose an alternate solution. For readdir, replace the text: "The readdir() function need not be thread-safe." with: "If multiple threads call the readdir() function with the same directory stream argument and without synchronization to preclude simultaneous access, then the behavior is undefined." With this change, the clunky readdir_r function is no longer needed or useful, and should probably be deprecated. As the only reasonable way to meet the implementation requirements for readdir is to have the dirent buffer in the DIR structure, this change should not require any change to existing implementations. " [1] https://sourceware.org/ml/libc-alpha/2016-02/msg00093.html [2] https://sourceware.org/bugzilla/show_bug.cgi?id=19056 [3] https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html [4] http://austingroupbugs.net/view.php?id=696 -- v2: - Additional detail in commit message - Cleanup additional related (no longer used) code Signed-off-by: Chris Patterson --- tools/libfsimage/common/fsimage_plugin.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tools/libfsimage/common/fsimage_plugin.c b/tools/libfsimage/common/fsimage_plugin.c index 3fa06c7..5ab8d93 100644 --- a/tools/libfsimage/common/fsimage_plugin.c +++ b/tools/libfsimage/common/fsimage_plugin.c @@ -122,8 +122,7 @@ fail: static int load_plugins(void) { const char *fsdir = getenv("FSIMAGE_FSDIR"); - struct dirent *dp = NULL; - struct dirent *dpp; + struct dirent *de; DIR *dir = NULL; char *tmp = NULL; size_t name_max; @@ -139,22 +138,17 @@ static int load_plugins(void) if ((tmp = malloc(name_max + 1)) == NULL) goto fail; - if ((dp = malloc(sizeof (struct dirent) + name_max + 1)) == NULL) - goto fail; - if ((dir = opendir(fsdir)) == NULL) goto fail; - bzero(dp, sizeof (struct dirent) + name_max + 1); - - while (readdir_r(dir, dp, &dpp) == 0 && dpp != NULL) { - if (strcmp(dpp->d_name, ".") == 0) + while ((de = readdir(dir)) != NULL) { + if (strcmp(de->d_name, ".") == 0) continue; - if (strcmp(dpp->d_name, "..") == 0) + if (strcmp(de->d_name, "..") == 0) continue; (void) snprintf(tmp, name_max, "%s/%s/fsimage.so", fsdir, - dpp->d_name); + de->d_name); if (init_plugin(tmp) != 0) goto fail; @@ -167,7 +161,6 @@ fail: if (dir != NULL) (void) closedir(dir); free(tmp); - free(dp); errno = err; return (ret); }