Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applications should use the clock_gettime() function instead of... #1636

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ AX_TYPE_SOCKLEN_T
AX_CREATE_STDINT_H([eggint.h])

# Checks for functions and their arguments.
AC_CHECK_FUNCS([dprintf explicit_bzero memset_explicit explicit_memset getrandom inet_aton memset_s snprintf strlcpy vsnprintf])
AC_CHECK_FUNCS([clock_gettime dprintf explicit_bzero memset_explicit explicit_memset getrandom inet_aton memset_s snprintf strlcpy vsnprintf])
AC_FUNC_SELECT_ARGTYPES
EGG_FUNC_B64_NTOP
AC_FUNC_MMAP
Expand Down
10 changes: 8 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,17 +923,23 @@ static void mainloop(int toplevel)
static void init_random(void) {
unsigned int seed;
#ifdef HAVE_GETRANDOM
if (getrandom(&seed, sizeof(seed), 0) != sizeof(seed)) {
if (getrandom(&seed, sizeof seed, 0) != (sizeof seed)) {
if (errno != ENOSYS) {
fatal("ERROR: getrandom()\n", 0);
} else {
/* getrandom() is available in header but syscall is not!
* This can happen with glibc>=2.25 and linux<3.17
*/
#endif
#ifdef HAVE_CLOCK_GETTIME
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
seed = ((uint64_t) tp.tv_sec * tp.tv_nsec) ^ getpid();
#else
struct timeval tp;
gettimeofday(&tp, NULL);
seed = (((int64_t) tp.tv_sec * tp.tv_usec)) ^ getpid();
seed = ((uint64_t) tp.tv_sec * tp.tv_usec) ^ getpid();
#endif
#ifdef HAVE_GETRANDOM
}
}
Expand Down
Loading