NetBSD-Bugs archive

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

Re: bin/43751: ls -L returns wrong exit code



Thu, Aug 12, 2010 at 08:50:04PM +0000, Valeriy E. Ushakov:
>  I don't think this is recent.  NetBSD 1.6 behaves the same way.

Crap, you are right.  my 4.99 test had the FQPN, as you noted.

>  Basically, we use -L only to select FTS_LOGICAL instead of
>  FTS_PHYSICAL.  printing code doesn't know whether -L was specified.
>  For links with non-existent targets fts_children(3) returns the link
>  info (as it would for FTS_PHYSICAL) and printing code just happily
>  prints it.

Does it need to?  something like this is a quick fix.

Index: ls.c
===================================================================
RCS file: /cvsroot/src/bin/ls/ls.c,v
retrieving revision 1.67
diff -d -u -d -u -r1.67 ls.c
--- ls.c        8 Jul 2010 20:43:34 -0000       1.67
+++ ls.c        13 Aug 2010 00:52:59 -0000
@@ -389,6 +389,7 @@
 static void
 traverse(int argc, char *argv[], int options)
 {
+       char path[MAXPATHLEN + 1];
        FTS *ftsp;
        FTSENT *p, *chp;
        int ch_options, error;
@@ -442,6 +443,13 @@
                        if (!f_recursive && chp != NULL)
                                (void)fts_set(ftsp, p, FTS_SKIP);
                        break;
+               case FTS_SLNONE:
+                       if (options & FTS_LOGICAL) {
+                           readlink(p->fts_path, path, sizeof(path) - 1);
+                           errno = ENOENT;
+                           warn("cannot access %s", path, p->fts_name);
+                           rval = EXIT_FAILURE;
+                       }
                }
        error = errno;
        (void)fts_close(ftsp);



Home | Main Index | Thread Index | Old Index