Skip to content

Commit

Permalink
Port better to old Linux kernels
Browse files Browse the repository at this point in the history
Problem reported by Igor Ivanov in:
https://mm.icann.org/pipermail/tz/2022-October/032192.html
* NEWS: Mention this.
* zic.c (get_rand_u64): Don’t use clock_gettime; it’s too much of
a configuration hassle.
  • Loading branch information
eggert committed Oct 31, 2022
1 parent 71958dd commit 317cc2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
5 changes: 2 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ Unreleased, experimental changes
Fix bug in zdump's tzalloc emulation on hosts that lack tm_zone.
(Problem reported by Đoàn Trần Công Danh.)

Fix zic's default configuration to not use getrandom on macOS,
which has sys/random.h but lacks getrandom. (Problem reported by
Gilmore Davidson.)
Fix zic configuration to avoid linkage failures on some platforms.
(Problems reported by Gilmore Davidson and Igor Ivanov.)

Changes to build procedure

Expand Down
15 changes: 3 additions & 12 deletions zic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,21 +1210,12 @@ get_rand_u64(void)
#endif

/* getrandom didn't work, so fall back on portable code that is
not the best because the seed doesn't necessarily have enough bits,
the seed isn't cryptographically random on platforms lacking
getrandom, and 'rand' might not be cryptographically secure. */
not the best because the seed isn't cryptographically random and
'rand' might not be cryptographically secure. */
{
static bool initialized;
if (!initialized) {
unsigned seed;
#ifdef CLOCK_REALTIME
struct timespec now;
clock_gettime (CLOCK_REALTIME, &now);
seed = now.tv_sec ^ now.tv_nsec;
#else
seed = time(NULL);
#endif
srand(seed);
srand(time(NULL));
initialized = true;
}
}
Expand Down

0 comments on commit 317cc2c

Please sign in to comment.