don't exit if stat fails; could reasonably happen under NFS
[unix-history] / usr / src / bin / ls / ls.c
index 76ad226..e5ea3b1 100644 (file)
@@ -5,7 +5,7 @@
  * This code is derived from software contributed to Berkeley by
  * Michael Fischbein.
  *
  * This code is derived from software contributed to Berkeley by
  * Michael Fischbein.
  *
-%sccs.include.redist.c%
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ls.c       5.38 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c       5.40 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -414,11 +414,14 @@ tabdir(lp, s_stats, s_names)
                                nomem();
                }
                if (f_needstat && lstat(dp->d_name, &stats[cnt].lstat)) {
                                nomem();
                }
                if (f_needstat && lstat(dp->d_name, &stats[cnt].lstat)) {
+                       /*
+                        * don't exit -- this could be an NFS mount that has
+                        * gone away.  Flush stdout so the messages line up.
+                        */
+                       (void)fflush(stdout);
                        (void)fprintf(stderr, "ls: %s: %s\n",
                            dp->d_name, strerror(errno));
                        (void)fprintf(stderr, "ls: %s: %s\n",
                            dp->d_name, strerror(errno));
-                       if (errno == ENOENT)
-                               continue;
-                       exit(1);
+                       continue;
                }
                stats[cnt].name = names;
 
                }
                stats[cnt].name = names;