[patch] nftw(): clarify dangling symlinks case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In the event that nftw() encounters a symbolic link which refers to a
nonexisting file, the "struct stat" info will not have been filled in
if FTW_PHYS is not specified (because stat() is used instead of
lstat()).  This patch clarifies the documentation and corrects the
sample code to reflect this.

Reported to Fedora in https://bugzilla.redhat.com/show_bug.cgi?id=1422736

patch is against today's git

diff --git a/man3/ftw.3 b/man3/ftw.3
index b421c00..7b54621 100644
--- a/man3/ftw.3
+++ b/man3/ftw.3
@@ -165,7 +165,9 @@ is a symbolic link, and \fBFTW_PHYS\fP was set in \fIflags\fP.
 .B FTW_SLN
 .I fpath
 is a symbolic link pointing to a nonexistent file.
-(This occurs only if \fBFTW_PHYS\fP is not set.)
+(This occurs only if \fBFTW_PHYS\fP is not set, and the data
+.I sb
+points to during this callback will not be defined.)
 .PP
 The fourth argument that
 .BR nftw ()
@@ -421,13 +423,17 @@ static int
 display_info(const char *fpath, const struct stat *sb,
              int tflag, struct FTW *ftwbuf)
 {
-    printf("%\-3s %2d %7jd   %\-40s %d %s\\n",
-        (tflag == FTW_D) ?   "d"   : (tflag == FTW_DNR) ? "dnr" :
-        (tflag == FTW_DP) ?  "dp"  : (tflag == FTW_F) ?   "f" :
-        (tflag == FTW_NS) ?  "ns"  : (tflag == FTW_SL) ?  "sl" :
-        (tflag == FTW_SLN) ? "sln" : "???",
-        ftwbuf\->level, (intmax_t) sb\->st_size,
-        fpath, ftwbuf\->base, fpath + ftwbuf\->base);
+    if (tflag == FTW_SLN)
+        printf("sln %2d \-------   %-40s %d %s\n",
+            ftwbuf\->level, fpath, ftwbuf\->base, fpath + ftwbuf\->base);
+    else
+        printf("%\-3s %2d %7jd   %\-40s %d %s\\n",
+            (tflag == FTW_D) ?   "d"   : (tflag == FTW_DNR) ? "dnr" :
+            (tflag == FTW_DP) ?  "dp"  : (tflag == FTW_F) ?   "f" :
+            (tflag == FTW_NS) ?  "ns"  : (tflag == FTW_SL) ?  "sl" :
+            "???",
+            ftwbuf\->level, (intmax_t) sb\->st_size,
+            fpath, ftwbuf\->base, fpath + ftwbuf\->base);
     return 0;           /* To tell nftw() to continue */
 }
 
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux