[PATCH 1/5] 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. --- 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
* private.h (static_assert): Improve comment. --- private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private.h b/private.h index 4daa4864..e5f6af59 100644 --- a/private.h +++ b/private.h @@ -83,7 +83,7 @@ #endif /* For pre-C23 compilers, a substitute for static_assert. - Some of these compilers may warn if it is not used at the top level. */ + Some of these compilers may warn if it is used outside the top level. */ #if __STDC_VERSION__ < 202311 && !defined static_assert # define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1] #endif -- 2.51.0
This is for FreeBSD libc, which still defines a hidden tzsetwall to support old binaries that use that old (and ineffective) function. FreeBSD can do so in a wrapper file that includes localtime.c. This patch does not affect behavior of existing functions. * localtime.c (tzset_unlocked): New arg WALL. All uses changed. --- localtime.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/localtime.c b/localtime.c index f2d35813..626e083d 100644 --- a/localtime.c +++ b/localtime.c @@ -1917,9 +1917,11 @@ zoneinit(struct state *sp, char const *name, char tzloadflags) /* Like tzset(), but in a critical section. If THREADED && THREAD_RWLOCK the caller has a read lock, and this function might upgrade it to a write lock. + If WALL, act as if TZ is unset; although always false in this file, + a wrapper .c file's obsolete and ineffective tzsetwall function can use it. If tz_change_interval is positive the time is NOW; otherwise ignore NOW. */ static void -tzset_unlocked(bool threaded, monotime_t now) +tzset_unlocked(bool threaded, bool wall, monotime_t now) { char const *name; struct state *sp; @@ -1928,7 +1930,7 @@ tzset_unlocked(bool threaded, monotime_t now) bool writing = false; for (;;) { - name = getenv("TZ"); + name = wall ? NULL : getenv("TZ"); sp = lclptr; tzloadflags = TZLOAD_FROMENV | TZLOAD_TZSTRING; namelen = sizeof lcl_TZname + 1; /* placeholder for no name */ @@ -2016,7 +2018,7 @@ tzset(void) errno = err; return; } - tzset_unlocked(!err, now); + tzset_unlocked(!err, false, now); unlock(!err); } #endif @@ -2207,7 +2209,7 @@ localtime_tzset(time_t const *timep, struct tm *tmp, bool setname) return NULL; } if (0 <= tz_change_interval || setname || !lcl_is_set) - tzset_unlocked(!err, now); + tzset_unlocked(!err, false, now); tmp = localsub(lclptr, timep, setname, tmp); unlock(!err); return tmp; @@ -2874,7 +2876,7 @@ mktime(struct tm *tmp) errno = err; return -1; } - tzset_unlocked(!err, now); + tzset_unlocked(!err, false, now); t = mktime_tzname(lclptr, tmp, true); unlock(!err); return t; @@ -2992,7 +2994,7 @@ time2posix(time_t t) return -1; } if (0 <= tz_change_interval || !lcl_is_set) - tzset_unlocked(!err, now); + tzset_unlocked(!err, false, now); if (lclptr) t = time2posix_z(lclptr, t); unlock(!err); @@ -3038,7 +3040,7 @@ posix2time(time_t t) return -1; } if (0 <= tz_change_interval || !lcl_is_set) - tzset_unlocked(!err, now); + tzset_unlocked(!err, false, now); if (lclptr) t = posix2time_z(lclptr, t); unlock(!err); -- 2.51.0
* private.h (GRANDPARENTED): Define only if not already defined. --- private.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/private.h b/private.h index e5f6af59..074da284 100644 --- a/private.h +++ b/private.h @@ -99,7 +99,9 @@ #endif /* This string was in the Factory zone through version 2016f. */ -#define GRANDPARENTED "Local time zone must be set--see zic manual page" +#ifndef GRANDPARENTED +# define GRANDPARENTED "Local time zone must be set--see zic manual page" +#endif /* ** Defaults for preprocessor symbols. -- 2.51.0
--- localtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localtime.c b/localtime.c index 626e083d..f1a82370 100644 --- a/localtime.c +++ b/localtime.c @@ -268,7 +268,7 @@ struct timespec { time_t tv_sec; long tv_nsec; }; # define TZ_CHANGE_INTERVAL 61 # else # define TZ_CHANGE_INTERVAL (-1) -#endif +# endif #endif static_assert(TZ_CHANGE_INTERVAL < 0 || HAVE_SYS_STAT_H); -- 2.51.0
participants (1)
-
Paul Eggert