diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2021-10-05 04:53:29 +0200 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2021-10-05 04:53:29 +0200 |
commit | eeb25df6f8fc1e3cf18ec5578445f8fc281e41bc (patch) | |
tree | a7efc635f600379cb90fe8856cd544bb9ba454bd /agent/protect.c | |
parent | tests: Use the new gpgconf.ctl based method. (diff) | |
download | gnupg2-eeb25df6f8fc1e3cf18ec5578445f8fc281e41bc.tar.xz gnupg2-eeb25df6f8fc1e3cf18ec5578445f8fc281e41bc.zip |
agent: Fix calibrate_get_time use of clock_gettime.
* agent/protect.c (USE_CLOCK_GETTIME): New macro.
(calibrate_get_time): Only use clock_gettime if USE_CLOCK_GETTIME.
--
GnuPG-bug-id: 5623
Fixes-commit: 380bce13d94ff03c96e39ac1d834f382c5c730a1
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'agent/protect.c')
-rw-r--r-- | agent/protect.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/agent/protect.c b/agent/protect.c index 7ae067ec7..4ceb3006e 100644 --- a/agent/protect.c +++ b/agent/protect.c @@ -96,6 +96,27 @@ hash_passphrase (const char *passphrase, int hashalgo, +/* + * Determine if we can use clock_gettime with CLOCK_THREAD_CPUTIME_ID, + * at compile time. + */ +#if defined (CLOCK_THREAD_CPUTIME_ID) +# if _POSIX_THREAD_CPUTIME > 0 +# define USE_CLOCK_GETTIME 1 +# elif _POSIX_THREAD_CPUTIME == 0 +/* + * In this case, we should check sysconf with _POSIX_THREAD_CPUTIME at + * run time. As heuristics, for system with newer GNU C library, we + * can assume it is available. + */ +# if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 17 +# define USE_CLOCK_GETTIME 1 +# endif +# endif +#else +#undef USE_CLOCK_GETTIME +#endif + /* Get the process time and store it in DATA. */ static void calibrate_get_time (struct calibrate_time_s *data) @@ -110,7 +131,7 @@ calibrate_get_time (struct calibrate_time_s *data) &data->creation_time, &data->exit_time, &data->kernel_time, &data->user_time); # endif -#elif defined (CLOCK_THREAD_CPUTIME_ID) +#elif defined (USE_CLOCK_GETTIME) struct timespec tmp; clock_gettime (CLOCK_THREAD_CPUTIME_ID, &tmp); |