>From b619b08ca4d78940e769b5df57768d43cf081f33 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 24 Dec 2020 11:38:48 -0800 Subject: [PATCH 08/10] linkat: use eloop-threshold * lib/linkat.c: Include eloop-threshold.h. Do not include sys/param.h. (MAXSYMLINKS): Remove. (link_follow, linkat_follow): Use __eloop_threshold instead of MAXSYMLINKS. * m4/linkat.m4 (gl_FUNC_LINKAT): Omit sys/param.h check. * modules/linkat (Depends-on): Add eloop-threshold. Sort. --- ChangeLog | 9 +++++++++ lib/linkat.c | 16 +++------------- m4/linkat.m4 | 3 +-- modules/linkat | 11 ++++++----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index edca84874..7b1bcd8ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2020-12-24 Paul Eggert + linkat: use eloop-threshold + * lib/linkat.c: Include eloop-threshold.h. + Do not include sys/param.h. + (MAXSYMLINKS): Remove. + (link_follow, linkat_follow): Use __eloop_threshold instead + of MAXSYMLINKS. + * m4/linkat.m4 (gl_FUNC_LINKAT): Omit sys/param.h check. + * modules/linkat (Depends-on): Add eloop-threshold. Sort. + canonicalize-lgpl: use eloop-threshold * lib/canonicalize-lgpl.c [!_LIBC]: Include eloop-threshold.h. (MAXSYMLINKS, __eloop_threshold): Remove. diff --git a/lib/linkat.c b/lib/linkat.c index 13313e9d1..6fc963537 100644 --- a/lib/linkat.c +++ b/lib/linkat.c @@ -29,20 +29,10 @@ #include "areadlink.h" #include "dirname.h" +#include "eloop-threshold.h" #include "filenamecat.h" #include "openat-priv.h" -#if HAVE_SYS_PARAM_H -# include -#endif -#ifndef MAXSYMLINKS -# ifdef SYMLOOP_MAX -# define MAXSYMLINKS SYMLOOP_MAX -# else -# define MAXSYMLINKS 20 -# endif -#endif - #if !HAVE_LINKAT || LINKAT_SYMLINK_NOTSUP /* Create a link. If FILE1 is a symlink, either create a hardlink to @@ -105,7 +95,7 @@ link_follow (char const *file1, char const *file2) char *name = (char *) file1; char *target; int result; - int i = MAXSYMLINKS; + int i = __eloop_threshold (); /* Using realpath or canonicalize_file_name is too heavy-handed: we don't need an absolute name, and we don't need to resolve @@ -231,7 +221,7 @@ linkat_follow (int fd1, char const *file1, int fd2, char const *file2) char *name = (char *) file1; char *target; int result; - int i = MAXSYMLINKS; + int i = __eloop_threshold (); /* There is no realpathat. */ while (i-- && (target = areadlinkat (fd1, name))) diff --git a/m4/linkat.m4 b/m4/linkat.m4 index e9b3d8266..a4e61c332 100644 --- a/m4/linkat.m4 +++ b/m4/linkat.m4 @@ -1,4 +1,4 @@ -# serial 13 +# serial 14 # See if we need to provide linkat replacement. dnl Copyright (C) 2009-2020 Free Software Foundation, Inc. @@ -16,7 +16,6 @@ AC_DEFUN([gl_FUNC_LINKAT], AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_CHECK_FUNCS_ONCE([linkat symlink]) - AC_CHECK_HEADERS_ONCE([sys/param.h]) if test $ac_cv_func_linkat = no; then HAVE_LINKAT=0 else diff --git a/modules/linkat b/modules/linkat index e6f70ffa4..1fb4f8ff4 100644 --- a/modules/linkat +++ b/modules/linkat @@ -9,20 +9,21 @@ m4/linkat.m4 Depends-on: unistd extensions +areadlink [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] +at-internal [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] dirname-lgpl [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] +eloop-threshold [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] errno [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] fcntl-h [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] filenamecat-lgpl [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] -link-follow [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] -areadlink [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] -at-internal [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] filename [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] fstat [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] getcwd-lgpl [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] -openat-h [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] -openat-die [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] +link-follow [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] link [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] lstat [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] +openat-die [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] +openat-h [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] same-inode [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] save-cwd [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] stat [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] -- 2.27.0