From: Todd C. Miller Date: Mon, 20 Aug 2018 16:56:34 +0000 (-0600) Subject: HP-UX doesn't suport CLOCK_MONOTONIC but we can use gethrtime() instead. X-Git-Tag: SUDO_1_8_25^2~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df1c062526333b3fa85b0dfeb126496abd8bc890;p=sudo HP-UX doesn't suport CLOCK_MONOTONIC but we can use gethrtime() instead. --- diff --git a/config.h.in b/config.h.in index f8d09ceb0..17b0681ea 100644 --- a/config.h.in +++ b/config.h.in @@ -298,6 +298,9 @@ /* Define to 1 if you have the `getgrset' function. */ #undef HAVE_GETGRSET +/* Define to 1 if you have the `gethrtime' function. */ +#undef HAVE_GETHRTIME + /* Define to 1 if you have the `getifaddrs' function. */ #undef HAVE_GETIFADDRS diff --git a/configure b/configure index 77eef570d..64e8dac27 100755 --- a/configure +++ b/configure @@ -15604,12 +15604,13 @@ _ACEOF # HP-UX won't unlink a shared lib that is open INSTALL_BACKUP='~' - for ac_func in pstat_getproc + for ac_func in pstat_getproc gethrtime do : - ac_fn_c_check_func "$LINENO" "pstat_getproc" "ac_cv_func_pstat_getproc" -if test "x$ac_cv_func_pstat_getproc" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_PSTAT_GETPROC 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi @@ -15720,12 +15721,13 @@ $as_echo "$sudo_cv_var_daportable" >&6; } test -z "$with_pam" && AUTH_EXCL_DEF="PAM" ;; esac - for ac_func in pstat_getproc + for ac_func in pstat_getproc gethrtime do : - ac_fn_c_check_func "$LINENO" "pstat_getproc" "ac_cv_func_pstat_getproc" -if test "x$ac_cv_func_pstat_getproc" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_PSTAT_GETPROC 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi diff --git a/configure.ac b/configure.ac index a91ca18d9..ed3027f14 100644 --- a/configure.ac +++ b/configure.ac @@ -1875,7 +1875,7 @@ case "$host" in # HP-UX won't unlink a shared lib that is open INSTALL_BACKUP='~' - AC_CHECK_FUNCS([pstat_getproc]) + AC_CHECK_FUNCS([pstat_getproc gethrtime]) ;; *-*-hpux*) AC_DEFINE([PAM_SUN_CODEBASE]) @@ -1954,7 +1954,7 @@ case "$host" in test -z "$with_pam" && AUTH_EXCL_DEF="PAM" ;; esac - AC_CHECK_FUNCS([pstat_getproc]) + AC_CHECK_FUNCS([pstat_getproc gethrtime]) ;; *-dec-osf*) # ignore envariables wrt dynamic lib path diff --git a/lib/util/gettime.c b/lib/util/gettime.c index 63c9ea11d..72bdbe6d7 100644 --- a/lib/util/gettime.c +++ b/lib/util/gettime.c @@ -111,6 +111,18 @@ sudo_gettime_mono_v1(struct timespec *ts) } debug_return_int(0); } +#elif defined(HAVE_GETHRTIME) +int +sudo_gettime_mono_v1(struct timespec *ts) +{ + hrtime_t nsec; + debug_decl(sudo_gettime_mono, SUDO_DEBUG_UTIL) + + nsec = gethrtime(); + ts->tv_sec = nsec / 1000000000; + ts->tv_nsec = nsec % 1000000000; + debug_return_int(0); +} #elif defined(__MACH__) int sudo_gettime_mono_v1(struct timespec *ts) @@ -167,6 +179,19 @@ sudo_gettime_awake_v1(struct timespec *ts) } debug_return_int(0); } +#elif defined(HAVE_GETHRTIME) +int +sudo_gettime_awake_v1(struct timespec *ts) +{ + hrtime_t nsec; + debug_decl(sudo_gettime_awake, SUDO_DEBUG_UTIL) + + /* Currently the same as sudo_gettime_mono() */ + nsec = gethrtime(); + ts->tv_sec = nsec / 1000000000; + ts->tv_nsec = nsec % 1000000000; + debug_return_int(0); +} #elif defined(__MACH__) int sudo_gettime_awake_v1(struct timespec *ts)