From: Paul Eggert Date: Mon, 1 Apr 2024 04:12:38 +0000 (-0600) Subject: getcwd: port better to buggy file systems X-Git-Tag: v1.0~195 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d96e86fe0a2a6b84f94f94b81aa3edaefc5edc6e;p=gnulib.git getcwd: port better to buggy file systems * m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): Time out after 5 seconds. --- diff --git a/ChangeLog b/ChangeLog index 6a2b024832..d6afda967e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-04-01 Paul Eggert + + getcwd: port better to buggy file systems + * m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): + Time out after 5 seconds. + 2024-03-31 Collin Funk gnulib-tool.py: Add missing quotation mark to reminder. diff --git a/m4/getcwd-path-max.m4 b/m4/getcwd-path-max.m4 index d30e75af60..424ad7714f 100644 --- a/m4/getcwd-path-max.m4 +++ b/m4/getcwd-path-max.m4 @@ -1,4 +1,4 @@ -# serial 25 +# serial 26 # Check for several getcwd bugs with long file names. # If so, arrange to compile the wrapper function. @@ -15,7 +15,7 @@ AC_DEFUN([gl_FUNC_GETCWD_PATH_MAX], [ - AC_CHECK_DECLS_ONCE([getcwd]) + AC_CHECK_DECLS_ONCE([getcwd, alarm]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_CHECK_HEADERS_ONCE([unistd.h]) @@ -35,6 +35,9 @@ AC_DEFUN([gl_FUNC_GETCWD_PATH_MAX], #else # include #endif +#if HAVE_DECL_ALARM +# include +#endif #include #include #include @@ -90,16 +93,30 @@ main () #else char buf[PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1) + DIR_NAME_SIZE + BUF_SLOP]; - char *cwd = getcwd (buf, PATH_MAX); + char *cwd; size_t initial_cwd_len; size_t cwd_len; - int fail = 0; - size_t n_chdirs = 0; - + int fail; + size_t n_chdirs; + +# if HAVE_DECL_ALARM + /* This test makes some buggy getcwd implementations take a long time, e.g. + on NAS devices + + and in sandboxed environments . + Give up after 5 seconds; a getcwd slower than that isn't worth using + anyway. */ + signal (SIGALRM, SIG_DFL); + alarm (5); +# endif + + cwd = getcwd (buf, PATH_MAX); if (cwd == NULL) exit (10); cwd_len = initial_cwd_len = strlen (cwd); + fail = 0; + n_chdirs = 0; while (1) {