Blame sysdeps/generic/eloop-threshold.h

Packit Service 82fcde
/* Threshold at which to diagnose ELOOP.  Generic version.
Packit Service 82fcde
   Copyright (C) 2012-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef _ELOOP_THRESHOLD_H
Packit Service 82fcde
#define _ELOOP_THRESHOLD_H      1
Packit Service 82fcde
Packit Service 82fcde
#include <limits.h>
Packit Service 82fcde
#include <sys/param.h>
Packit Service 82fcde
Packit Service 82fcde
/* POSIX specifies SYMLOOP_MAX as the "Maximum number of symbolic
Packit Service 82fcde
   links that can be reliably traversed in the resolution of a
Packit Service 82fcde
   pathname in the absence of a loop."  This makes it a minimum that
Packit Service 82fcde
   we should certainly accept.  But it leaves open the possibility
Packit Service 82fcde
   that more might sometimes work--just not "reliably".
Packit Service 82fcde
Packit Service 82fcde
   For example, Linux implements a complex policy whereby there is a
Packit Service 82fcde
   small limit on the number of direct symlink traversals (a symlink
Packit Service 82fcde
   to a symlink to a symlink), but larger limit on the total number of
Packit Service 82fcde
   symlink traversals overall.  Hence the SYMLOOP_MAX number should be
Packit Service 82fcde
   the small one, but the limit library functions enforce on users
Packit Service 82fcde
   should be the larger one.
Packit Service 82fcde
Packit Service 82fcde
   So, we use the larger of the reported SYMLOOP_MAX (if any) and our
Packit Service 82fcde
   own constant MIN_ELOOP_THRESHOLD, below.  This constant should be
Packit Service 82fcde
   large enough that it never rules out a file name and directory tree
Packit Service 82fcde
   that the underlying system (i.e. calls to 'open' et al) would
Packit Service 82fcde
   resolve successfully.  It should be small enough that actual loops
Packit Service 82fcde
   are detected without a huge number of iterations.  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef MIN_ELOOP_THRESHOLD
Packit Service 82fcde
# define MIN_ELOOP_THRESHOLD    40
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
/* Return the maximum number of symlink traversals to permit
Packit Service 82fcde
   before diagnosing ELOOP.  */
Packit Service 82fcde
static inline unsigned int __attribute__ ((const))
Packit Service 82fcde
__eloop_threshold (void)
Packit Service 82fcde
{
Packit Service 82fcde
#ifdef SYMLOOP_MAX
Packit Service 82fcde
  const int symloop_max = SYMLOOP_MAX;
Packit Service 82fcde
#else
Packit Service 82fcde
  /* The function is marked 'const' even though we use memory and
Packit Service 82fcde
     call a function, because sysconf is required to return the
Packit Service 82fcde
     same value in every call and so it must always be safe to
Packit Service 82fcde
     call __eloop_threshold exactly once and reuse the value.  */
Packit Service 82fcde
  static long int sysconf_symloop_max;
Packit Service 82fcde
  if (sysconf_symloop_max == 0)
Packit Service 82fcde
    sysconf_symloop_max = __sysconf (_SC_SYMLOOP_MAX);
Packit Service 82fcde
  const unsigned int symloop_max = (sysconf_symloop_max <= 0
Packit Service 82fcde
                                    ? _POSIX_SYMLOOP_MAX
Packit Service 82fcde
                                    : sysconf_symloop_max);
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
  return MAX (symloop_max, MIN_ELOOP_THRESHOLD);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#endif  /* eloop-threshold.h */