All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Patterson <cjp256@gmail.com>
To: xen-devel@lists.xen.org
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 <pattersonc@ainfosec.com>,
	jbeulich@suse.com
Subject: [[PATCH v2 1/2] libfsimage: replace deprecated readdir_r() with readdir()
Date: Wed,  1 Jun 2016 14:19:37 -0400	[thread overview]
Message-ID: <1464805178-8989-1-git-send-email-cjp256@gmail.com> (raw)

From: Chris Patterson <pattersonc@ainfosec.com>

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 <pattersonc@ainfosec.com>
---
 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);
 }
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

             reply	other threads:[~2016-06-01 18:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-01 18:19 Chris Patterson [this message]
2016-06-01 18:19 ` [[PATCH v2 2/2] libxl: replace deprecated readdir_r() with readdir() Chris Patterson
2016-06-02 10:11   ` Ian Jackson
2016-06-02 13:17     ` Chris Patterson
2016-06-02 16:13       ` Ian Jackson
2016-06-02 18:51         ` Chris Patterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1464805178-8989-1-git-send-email-cjp256@gmail.com \
    --to=cjp256@gmail.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=pattersonc@ainfosec.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.