FreeBSD has <sys/auxv.h> but not getauxval, so clarify ifdeffery
to reflect this. This doesn’t fix any bugs (since FreeBSD also
has issetugid) but makes things clearer.
* Makefile, NEWS: Update to match new behavior and fix a few
old typos.
* localtime.c: Move the <sys/auv.h> code to be closer together.
(HAVE_SYS_AUXV_H) [!HAVE_ISSETUGID]: New macro.
* private.h (HAVE_GETAUXVAL): Remove.
All uses replaced by HAVE_SYS_AUXV_H.
---
Makefile | 12 ++++++------
NEWS | 9 +++++----
localtime.c | 25 +++++++++++++++++++------
private.h | 13 -------------
4 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/Makefile b/Makefile
index 3b259c80..0fe8a9f8 100644
--- a/Makefile
+++ b/Makefile
@@ -246,7 +246,6 @@ LDLIBS=
# -DHAVE_DIRECT_H if mkdir needs <direct.h> (MS-Windows)
# -DHAVE_FCHMOD=0 if your system lacks the fchmod function
# -DHAVE__GENERIC=0 if _Generic does not work*
-# -DHAVE_GETAUXVAL=1 if getauxval works, 0 otherwise (default is guessed)
# -DHAVE_GETEUID=0 if gete?[ug]id do not work
# -DHAVE_GETRANDOM if getrandom works (e.g., GNU/Linux),
# -DHAVE_GETRANDOM=0 to avoid using getrandom
@@ -258,7 +257,9 @@ LDLIBS=
# ctime_r and asctime_r incompatibly with POSIX.1-2017 and earlier
# (Solaris when _POSIX_PTHREAD_SEMANTICS is not defined).
# -DHAVE_INTTYPES_H=0 if <inttypes.h> does not work*+
-# -DHAVE_ISSETUID=1 if issetugid works, 0 otherwise (default is guessed)
+# -DHAVE_ISSETUGID=1 if issetugid works, 0 otherwise (default is guessed)
+# If 0, you may also use -DHAVE_SYS_AUXV_H=1 if <sys/auxv.h> works,
+# 0 otherwise (default is guessed).
# -DHAVE_LINK=0 if your system lacks a link function
# -DHAVE_LOCALTIME_R=0 if your system lacks a localtime_r function
# -DHAVE_LOCALTIME_RZ=0 if you do not want zdump to use localtime_rz
@@ -268,8 +269,8 @@ LDLIBS=
# -DHAVE_POSIX_DECLS=0 if your system's include files do not declare
# variables like 'tzname' required by POSIX
# -DHAVE_PWD_H=0 if your system lacks pwd.h, grp.h and corresponding functions
-# The following additional options may be needed:
-# -Dgid_t=T, -Duid_t=T to define gid_t, uid_t to be type T
+# If 0, you may also need -Dgid_t=G -Duid_t=U
+# to define gid_t and uid_t to be types G and U.
# -DHAVE_SETENV=0 if your system lacks the setenv function
# -DHAVE_SETMODE=[01] if your system lacks or has the setmode and getmode
# functions (default is guessed)
@@ -285,8 +286,7 @@ LDLIBS=
# -DHAVE_STRUCT_TIMESPEC=0 if your system lacks struct timespec+
# -DHAVE_SYMLINK=0 if your system lacks the symlink function
# -DHAVE_SYS_STAT_H=0 if <sys/stat.h> does not work*
-# The following additional option may be needed:
-# -Dmode_t=T to define mode_t to be type T
+# If 0, you may also need -Dmode_t=M to define mode_t to be type M.
# -DHAVE_TZSET=0 if your system lacks a tzset function
# -DHAVE_UNISTD_H=0 if <unistd.h> does not work*
# -DHAVE_UTMPX_H=0 if <utmpx.h> does not work*
diff --git a/NEWS b/NEWS
index 37ac9fba..64d32bf3 100644
--- a/NEWS
+++ b/NEWS
@@ -44,12 +44,13 @@ Unreleased, experimental changes
no less caution than TZ strings taken from the environment, as
the old undocumented behavior would have been hard to explain.
tzset etc. no longer use the 'access' system call to check access;
- instead they now use the system calls issetuid, getauxval,
+ instead they now use the system calls issetugid, getauxval,
getresuid/getresgid, and geteuid/getegid/getuid/getgid (whichever
first works) to test whether a program is privileged.
- Compile with -DHAVE_ISSETUID=[01], -DHAVE_GETAUXVAL=[01],
- -DHAVE_GETRESUID=[01], and -DHAVE_GETEUID=[01] to enable or
- disable these system calls' use.
+ Compile with -DHAVE_SYS_AUXV_H=[01] to enable or disable
+ <sys/auxv.h> which (if it defines AT_SECURE) enables getauxval,
+ and compile with -DHAVE_ISSETUGID=[01], -DHAVE_GETRESUID=[01], and
+ -DHAVE_GETEUID=[01] to enable or disable the other calls' use.
The new CFLAGS option -DTZ_CHANGE_INTERVAL=N makes tzset etc.
check for TZif file changes if the in-memory data are N seconds
diff --git a/localtime.c b/localtime.c
index a8c442dd..f2d35813 100644
--- a/localtime.c
+++ b/localtime.c
@@ -19,10 +19,6 @@
#include "tzfile.h"
#include <fcntl.h>
-#if HAVE_GETAUXVAL && !HAVE_ISSETUGID
-# include <sys/auxv.h>
-#endif
-
#if HAVE_SYS_STAT_H
# include <sys/stat.h>
# ifndef S_ISREG
@@ -366,12 +362,29 @@ static int openat(int dd, char const *path, int oflag) {
unreachable (); }
# define O_SEARCH 0
#endif
-/* Return 1 if the process is privileged, 0 otherwise. */
#if !HAVE_ISSETUGID
+
+# if !defined HAVE_SYS_AUXV_H && defined __has_include
+# if __has_include(<sys/auxv.h>)
+# define HAVE_SYS_AUXV_H 1
+# endif
+# endif
+# ifndef HAVE_SYS_AUXV_H
+# if defined __GLIBC__ && 2 < __GLIBC__ + (19 <= __GLIBC_MINOR__)
+# define HAVE_SYS_AUXV_H 1
+# else
+# define HAVE_SYS_AUXV_H 0
+# endif
+# endif
+# if HAVE_SYS_AUXV_H
+# include <sys/auxv.h>
+# endif
+
+/* Return 1 if the process is privileged, 0 otherwise. */
static int
issetugid(void)
{
-# if HAVE_GETAUXVAL && defined AT_SECURE
+# if HAVE_SYS_AUXV_H && defined AT_SECURE
unsigned long val;
errno = 0;
val = getauxval(AT_SECURE);
diff --git a/private.h b/private.h
index 8d3d6404..4daa4864 100644
--- a/private.h
+++ b/private.h
@@ -294,19 +294,6 @@ extern int optind;
# endif
#endif
-#if !defined HAVE_GETAUXVAL && defined __has_include
-# if __has_include(<sys/auxv.h>)
-# define HAVE_GETAUXVAL 1
-# endif
-#endif
-#ifndef HAVE_GETAUXVAL
-# if defined __GLIBC__ && 2 < __GLIBC__ + (19 <= __GLIBC_MINOR__)
-# define HAVE_GETAUXVAL 1
-# else
-# define HAVE_GETAUXVAL 0
-# endif
-#endif
-
#ifndef HAVE_ISSETUGID
# if (defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
|| (defined __linux__ && !defined __GLIBC__) /* Android, musl, etc. */ \
--
2.51.0