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


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

[RFC] Call lstat() before setting flags to FTW_SLN


POSIX.1-2008 doesn't describe this behavior explicitly in this case.
However, passing a stat buffer returned by a failed fstatat() doesn't
seem the correct behavior either.

Any comments?

---8<---

POSIX.1-2008 states the following for ftw():

    If the object is a symbolic link and stat() failed, it is unspecified
    whether ftw() passes FTW_SL or FTW_NS to the user-supplied function.

However, nftw() defines FTW_SLN, which is returned if "the object is a
symbolic link that does not name an existing file".

It also states:

    At each file it encounters, nftw() shall call the user-supplied function
    fn with four arguments:
    ...
    - The second argument is a pointer to the stat buffer containing
      information on the object, filled in as if fstatat(), stat(), or
      lstat() had been called to retrieve the information.

In the current implementation, when FTW_PHYS is not included and the object
is a symlink that doesn't name an existing file, the call to fstatat()
returns -1, flags is set to FTW_SLN and fn is called with a stat buffer
from a failed fstatat() call.

2017-02-24  Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>

	* io/ftw.c (process_entry): Call LXSTAT() if FXSTATAT() failed
	and the object is a symbolic link.
---
 io/ftw.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/io/ftw.c b/io/ftw.c
index 140a237..21ea8a7 100644
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -426,8 +426,6 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
 	result = -1;
       else if (data->flags & FTW_PHYS)
 	flag = FTW_NS;
-      else if (d_type == DT_LNK)
-	flag = FTW_SLN;
       else
 	{
 	  if (dir->streamfd != -1)
-- 
2.1.0


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