From 55e8233438b3c13294109df502a9b220a9a3f4f5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 9 Apr 2026 09:19:25 -0700 Subject: [PATCH] tar: ENFILE is like EMFILE * src/create.c (open_failure_recover): * src/misc.c (fdbase_opendir): Treat ENFILE like EMFILE. --- src/create.c | 7 ++++--- src/misc.c | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/create.c b/src/create.c index 71f183a5..bf9f9838 100644 --- a/src/create.c +++ b/src/create.c @@ -1230,7 +1230,7 @@ ensure_slash (char **pstr) /* If we just ran out of file descriptors, release a file descriptor in the directory chain somewhere leading from DIR->parent->parent up through the root. Return true if successful, false (preserving - errno == EMFILE) otherwise. + errno) otherwise. Do not release DIR's file descriptor, or DIR's parent, as other code assumes that they work. On some operating systems, another @@ -1241,7 +1241,8 @@ ensure_slash (char **pstr) static bool open_failure_recover (struct tar_stat_info const *dir) { - if (errno == EMFILE && dir && dir->parent) + int err = errno; + if ((err == EMFILE || err == ENFILE) && dir && dir->parent) { struct tar_stat_info *p; for (p = dir->parent->parent; p; p = p->parent) @@ -1250,7 +1251,7 @@ open_failure_recover (struct tar_stat_info const *dir) tar_stat_close (p); return true; } - errno = EMFILE; + errno = err; } return false; diff --git a/src/misc.c b/src/misc.c index ee5dcdca..e7b13719 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1238,13 +1238,13 @@ fdbase_opendir (char const *file_name, bool alternate) if (subfd < 0) { /* Keep the old directory cached and report open failure, - unless EMFILE means it's possible that falling + unless EMFILE/ENFILE means it's possible that falling through to close the old directory would mean we could successfully retry from the chdir_fd level. When reporting failure, there is no need to null-terminate the old directory, since the code does not assume null termination. */ - if (errno != EMFILE) + if (errno != EMFILE && errno != ENFILE) return (struct fdbase) { .fd = BADFD, .base = base }; } else