Skip to content

Commit faed4bd

Browse files
committed
Clarify <sys/auxv.h> vs getauxval
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.
1 parent 11681aa commit faed4bd

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ LDLIBS=
246246
# -DHAVE_DIRECT_H if mkdir needs <direct.h> (MS-Windows)
247247
# -DHAVE_FCHMOD=0 if your system lacks the fchmod function
248248
# -DHAVE__GENERIC=0 if _Generic does not work*
249-
# -DHAVE_GETAUXVAL=1 if getauxval works, 0 otherwise (default is guessed)
250249
# -DHAVE_GETEUID=0 if gete?[ug]id do not work
251250
# -DHAVE_GETRANDOM if getrandom works (e.g., GNU/Linux),
252251
# -DHAVE_GETRANDOM=0 to avoid using getrandom
@@ -258,7 +257,9 @@ LDLIBS=
258257
# ctime_r and asctime_r incompatibly with POSIX.1-2017 and earlier
259258
# (Solaris when _POSIX_PTHREAD_SEMANTICS is not defined).
260259
# -DHAVE_INTTYPES_H=0 if <inttypes.h> does not work*+
261-
# -DHAVE_ISSETUID=1 if issetugid works, 0 otherwise (default is guessed)
260+
# -DHAVE_ISSETUGID=1 if issetugid works, 0 otherwise (default is guessed)
261+
# If 0, you may also use -DHAVE_SYS_AUXV_H=1 if <sys/auxv.h> works,
262+
# 0 otherwise (default is guessed).
262263
# -DHAVE_LINK=0 if your system lacks a link function
263264
# -DHAVE_LOCALTIME_R=0 if your system lacks a localtime_r function
264265
# -DHAVE_LOCALTIME_RZ=0 if you do not want zdump to use localtime_rz
@@ -268,8 +269,8 @@ LDLIBS=
268269
# -DHAVE_POSIX_DECLS=0 if your system's include files do not declare
269270
# variables like 'tzname' required by POSIX
270271
# -DHAVE_PWD_H=0 if your system lacks pwd.h, grp.h and corresponding functions
271-
# The following additional options may be needed:
272-
# -Dgid_t=T, -Duid_t=T to define gid_t, uid_t to be type T
272+
# If 0, you may also need -Dgid_t=G -Duid_t=U
273+
# to define gid_t and uid_t to be types G and U.
273274
# -DHAVE_SETENV=0 if your system lacks the setenv function
274275
# -DHAVE_SETMODE=[01] if your system lacks or has the setmode and getmode
275276
# functions (default is guessed)
@@ -285,8 +286,7 @@ LDLIBS=
285286
# -DHAVE_STRUCT_TIMESPEC=0 if your system lacks struct timespec+
286287
# -DHAVE_SYMLINK=0 if your system lacks the symlink function
287288
# -DHAVE_SYS_STAT_H=0 if <sys/stat.h> does not work*
288-
# The following additional option may be needed:
289-
# -Dmode_t=T to define mode_t to be type T
289+
# If 0, you may also need -Dmode_t=M to define mode_t to be type M.
290290
# -DHAVE_TZSET=0 if your system lacks a tzset function
291291
# -DHAVE_UNISTD_H=0 if <unistd.h> does not work*
292292
# -DHAVE_UTMPX_H=0 if <utmpx.h> does not work*

NEWS

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ Unreleased, experimental changes
4444
no less caution than TZ strings taken from the environment, as
4545
the old undocumented behavior would have been hard to explain.
4646
tzset etc. no longer use the 'access' system call to check access;
47-
instead they now use the system calls issetuid, getauxval,
47+
instead they now use the system calls issetugid, getauxval,
4848
getresuid/getresgid, and geteuid/getegid/getuid/getgid (whichever
4949
first works) to test whether a program is privileged.
50-
Compile with -DHAVE_ISSETUID=[01], -DHAVE_GETAUXVAL=[01],
51-
-DHAVE_GETRESUID=[01], and -DHAVE_GETEUID=[01] to enable or
52-
disable these system calls' use.
50+
Compile with -DHAVE_SYS_AUXV_H=[01] to enable or disable
51+
<sys/auxv.h> which (if it defines AT_SECURE) enables getauxval,
52+
and compile with -DHAVE_ISSETUGID=[01], -DHAVE_GETRESUID=[01], and
53+
-DHAVE_GETEUID=[01] to enable or disable the other calls' use.
5354

5455
The new CFLAGS option -DTZ_CHANGE_INTERVAL=N makes tzset etc.
5556
check for TZif file changes if the in-memory data are N seconds

localtime.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
#include "tzfile.h"
2020
#include <fcntl.h>
2121

22-
#if HAVE_GETAUXVAL && !HAVE_ISSETUGID
23-
# include <sys/auxv.h>
24-
#endif
25-
2622
#if HAVE_SYS_STAT_H
2723
# include <sys/stat.h>
2824
# ifndef S_ISREG
@@ -366,12 +362,29 @@ static int openat(int dd, char const *path, int oflag) { unreachable (); }
366362
# define O_SEARCH 0
367363
#endif
368364

369-
/* Return 1 if the process is privileged, 0 otherwise. */
370365
#if !HAVE_ISSETUGID
366+
367+
# if !defined HAVE_SYS_AUXV_H && defined __has_include
368+
# if __has_include(<sys/auxv.h>)
369+
# define HAVE_SYS_AUXV_H 1
370+
# endif
371+
# endif
372+
# ifndef HAVE_SYS_AUXV_H
373+
# if defined __GLIBC__ && 2 < __GLIBC__ + (19 <= __GLIBC_MINOR__)
374+
# define HAVE_SYS_AUXV_H 1
375+
# else
376+
# define HAVE_SYS_AUXV_H 0
377+
# endif
378+
# endif
379+
# if HAVE_SYS_AUXV_H
380+
# include <sys/auxv.h>
381+
# endif
382+
383+
/* Return 1 if the process is privileged, 0 otherwise. */
371384
static int
372385
issetugid(void)
373386
{
374-
# if HAVE_GETAUXVAL && defined AT_SECURE
387+
# if HAVE_SYS_AUXV_H && defined AT_SECURE
375388
unsigned long val;
376389
errno = 0;
377390
val = getauxval(AT_SECURE);

private.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,6 @@ extern int optind;
294294
# endif
295295
#endif
296296

297-
#if !defined HAVE_GETAUXVAL && defined __has_include
298-
# if __has_include(<sys/auxv.h>)
299-
# define HAVE_GETAUXVAL 1
300-
# endif
301-
#endif
302-
#ifndef HAVE_GETAUXVAL
303-
# if defined __GLIBC__ && 2 < __GLIBC__ + (19 <= __GLIBC_MINOR__)
304-
# define HAVE_GETAUXVAL 1
305-
# else
306-
# define HAVE_GETAUXVAL 0
307-
# endif
308-
#endif
309-
310297
#ifndef HAVE_ISSETUGID
311298
# if (defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
312299
|| (defined __linux__ && !defined __GLIBC__) /* Android, musl, etc. */ \

0 commit comments

Comments
 (0)