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



Fri, Aug 13, 2010 at 02:45:01AM +0000, Valeriy E. Ushakov:
>  Shouldn't this check be in display()?

rather than print the file & error?  ie: only the error.  as below.

>  You don't have to readlink(), the error is reported for the link name,
>  not the target name.

thats fine too.

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 16:52:01 -0000
@@ -68,7 +68,7 @@
 #include "ls.h"
 #include "extern.h"
 
-static void     display(FTSENT *, FTSENT *);
+static void     display(FTSENT *, FTSENT *, int);
 static int      mastercmp(const FTSENT **, const FTSENT **);
 static void     traverse(int, char **, int);
 
@@ -397,7 +397,7 @@
            fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
                err(EXIT_FAILURE, NULL);
 
-       display(NULL, fts_children(ftsp, 0));
+       display(NULL, fts_children(ftsp, 0), options);
        if (f_listdir) {
                (void)fts_close(ftsp);
                return;
@@ -437,7 +437,7 @@
                        }
 
                        chp = fts_children(ftsp, ch_options);
-                       display(p, chp);
+                       display(p, chp, options);
 
                        if (!f_recursive && chp != NULL)
                                (void)fts_set(ftsp, p, FTS_SKIP);
@@ -456,7 +456,7 @@
  * points to the parent directory of the display list.
  */
 static void
-display(FTSENT *p, FTSENT *list)
+display(FTSENT *p, FTSENT *list, int options)
 {
        struct stat *sp;
        DISPLAY d;
@@ -501,6 +501,13 @@
                        rval = EXIT_FAILURE;
                        continue;
                }
+               if (cur->fts_info == FTS_SLNONE && (options & FTS_LOGICAL)) {
+                       warnx("cannot access %s: %s", cur->fts_name,
+                           strerror(ENOENT));
+                       cur->fts_number = NO_PRINT;
+                       rval = EXIT_FAILURE;
+                       continue;
+               }
 
                /*
                 * P is NULL if list is the argv list, to which different rules



Home | Main Index | Thread Index | Old Index