This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix ftw


Hi!

If dir->streamfd != -1 and
FXSTATAT (_STAT_VER, dir->streamfd, name, &st, 0);
fails with EACCESS or ENOENT, then ftw is supposed to
find out if that is because of a dead symlink or for some
other reason.  If d_type is DT_LNK, then no further
work is needed, however otherwise we were calling LXSTAT.
But name in this case is relative to dir->streamfd, not absolute
or relative to current working directory, so it tells us something
different from what we are looking for.
The following patch fixes it (tested on s390x where ftwtest failed
because of this).

2006-03-02  Jakub Jelinek  <jakub@redhat.com>

	* io/ftw.c (process_entry): If dir->streamfd != -1,
	use FXSTATAT rather than LXSTAT to find if unstatable
	file is a dead symlink.

--- libc/io/ftw.c.jj	2006-02-12 16:40:36.000000000 -0500
+++ libc/io/ftw.c	2006-03-02 10:37:41.000000000 -0500
@@ -419,13 +419,22 @@ process_entry (struct ftw_data *data, st
     {
       if (errno != EACCES && errno != ENOENT)
 	result = -1;
-      else if (!(data->flags & FTW_PHYS)
-	       && (d_type == DT_LNK
-		   || (LXSTAT (_STAT_VER, name, &st) == 0
-		       && S_ISLNK (st.st_mode))))
+      else if (data->flags & FTW_PHYS)
+	flag = FTW_NS;
+      else if (d_type == DT_LNK)
 	flag = FTW_SLN;
       else
-	flag = FTW_NS;
+	{
+	  if (dir->streamfd != -1)
+	    statres = FXSTATAT (_STAT_VER, dir->streamfd, name, &st,
+				AT_SYMLINK_NOFOLLOW);
+	  else
+	    statres = LXSTAT (_STAT_VER, name, &st);
+	  if (statres == 0 && S_ISLNK (st.st_mode))
+	    flag = FTW_SLN;
+	  else
+	    flag = FTW_NS;
+	}
     }
   else
     {

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]