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 12:55:46PM -0400, Christos Zoulas:
> On Aug 13,  9:54am, heas%shrubbery.net@localhost (john heasley) wrote:
> -- Subject: Re: bin/43751: ls -L returns wrong exit code
> 
> | rather than print the file & error?  ie: only the error.  as below.
> 
> It is better to set errno and use warn, rather than warnx and strerror.
> 

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 17:11:37 -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)) {
+                       errno = ENOENT;
+                       warnx("cannot access %s", cur->fts_name);
+                       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