From: Paul Eggert Date: Mon, 13 Jan 2025 18:43:06 +0000 (-0800) Subject: ls: readdir errno fixes X-Git-Tag: v9.6~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0032e336e50c86186a01dbfa77364bc9c12235c1;p=thirdparty%2Fcoreutils.git ls: readdir errno fixes * src/ls.c (print_dir): Fix bug: file_failure can set errno to something other than EOVERFLOW but the code assumed it didn’t. Also, omit ENOENT bug workaround with glibc 2.3 and later, for consistency with Gnulib. --- diff --git a/src/ls.c b/src/ls.c index 50937071bf..a64ed57ab2 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3089,9 +3089,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) and when readdir simply finds that there are no more entries. */ errno = 0; next = readdir (dirp); - /* Some readdir()s do not absorb ENOENT (dir deleted but open). */ - if (errno == ENOENT) - errno = 0; if (next) { if (! file_ignored (next->d_name)) @@ -3122,14 +3119,21 @@ print_dir (char const *name, char const *realname, bool command_line_arg) } } } - else if (errno != 0) + else { + int err = errno; + if (err == 0) + break; + /* Some readdir()s do not absorb ENOENT (dir deleted but open). + This bug was fixed in glibc 2.3 (2002). */ +#if ! (2 < __GLIBC__ + (3 <= __GLIBC_MINOR__)) + if (err == ENOENT) + break; +#endif file_failure (command_line_arg, _("reading directory %s"), name); - if (errno != EOVERFLOW) + if (err != EOVERFLOW) break; } - else - break; /* When processing a very large directory, and since we've inhibited interrupts, this loop would take so long that ls would be annoyingly