All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] nftw(): clarify dangling symlinks case
@ 2017-02-22  1:06 DJ Delorie
       [not found] ` <xnshn7hw5i.fsf-wMSG6MF8/zxB8dkWVU3nKAC/G2K4zDHf@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: DJ Delorie @ 2017-02-22  1:06 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w
  Cc: linux-man-u79uwXL29TY76Z2rM5mHXA, codonell-H+wXaHxf7aLQT0dZR+AlfA


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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-24 17:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-22  1:06 [patch] nftw(): clarify dangling symlinks case DJ Delorie
     [not found] ` <xnshn7hw5i.fsf-wMSG6MF8/zxB8dkWVU3nKAC/G2K4zDHf@public.gmane.org>
2017-02-22 17:11   ` Carlos O'Donell
     [not found]     ` <23f174b0-5a52-213b-6fd8-4026c2b8fcc3-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-02-24  8:58       ` Michael Kerrisk (man-pages)
     [not found]         ` <CAKgNAki6wMCLRNZzFM975NviY-fd6gDNBTLvWZKSA2hdtb3AYA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-24 13:10           ` Carlos O'Donell
     [not found]             ` <4b58684c-b026-a541-8774-a0858c10ccb9-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-02-24 17:41               ` Michael Kerrisk (man-pages)

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.