Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

error build src/uv.c:612:10: error: implicit declaration of function 'getrandom' #318

Closed
SergeyDjam opened this issue Oct 22, 2022 · 14 comments
Assignees
Labels
Bug Confirmed to be a bug

Comments

@SergeyDjam
Copy link

src/uv.c: In function 'uvSeedRand':
src/uv.c:612:10: error: implicit declaration of function 'getrandom' [-Werror=implicit-function-declaration]
     sz = getrandom(&seed, sizeof seed, GRND_NONBLOCK);

Linux x86_64
gcc 5.5.0
libuv 1.24.0

how fix this problem?

@MathieuBordere
Copy link
Contributor

Which Linux distribution are you using?

You are probably experiencing something similar to this: https://stackoverflow.com/questions/45237324/why-doesnt-getrandom-compile.

Can you check if the solution in that topic fixes the problem for you? If yes, we can add something similar in our source.

@MathieuBordere
Copy link
Contributor

@SergeyDjam any update?

@SergeyDjam
Copy link
Author

Unfortunately, the news is sad. I was unable to solve the problem. The recommendation did not help. I tried a hack with
sed -i 's/sys\/random.h/linux\/random.h/' src/uv.c
but that doesn't help either.
I tried to build with clang, but there are errors and the build goes no further
Tried on 0.16.0 raft the errors are the same

@cole-miller
Copy link
Contributor

@cagev

on centos 7.9 gcc 8.3.1

src/uv.c:6:10: fatal error: sys/random.h: No such file or directory
#include <sys/random.h>

according to aria2/aria2#1249 the head file is missing in some libc

and since the flag -Werror=sign-conversion is on , compile will complain this error

src/uv_os.c: In function 'UvOsEventfd':
src/uv_os.c:213:18: error: conversion to 'int' from 'unsigned int' may change the sign of the result [-Werror=sign-conversion]
rv = eventfd(initval, flags);

@cole-miller
Copy link
Contributor

We could add some logic to configure.ac that tries to compile a program like

#include <sys/random.h>
void check(void) { getrandom(NULL, 0, 0); }

and then define the syscall wrapper ourselves behind an ifdef if it fails.

@bnoordhuis
Copy link

FWIW, if canonical/dqlite#584 goes through, you can fix this by switching to uv_random(), added in v1.33.0.

@cole-miller
Copy link
Contributor

It seems we try to avoid blocking in raft_uv_init, and the libuv event loop isn't (necessarily?) running at that point, so I don't think we can use uv_random to do the seeding unfortunately unless we're willing to relax the first requirement.

@freeekanayaka
Copy link
Contributor

Given that we use rand() only to generate the randomized election timeout (between election_timeout and election_timeout * 2), and not to, say, perform some secure-sensitive cryptographic task (or something like that), would it be ok to not use getrandom() at all in order to seed rand() and just use the system time combined with the node ID as seed?

That should be enough to get reasonable randomness for the election timeout, and we already have code for that, as a fallback in case getrandom fails, see uvSeedRand.

@cole-miller
Copy link
Contributor

@freeekanayaka that seems fine, I'm not itching to remove getrandom but I agree it's a little bit overkill here.

@SergeyDjam
Copy link
Author

SergeyDjam commented Jun 6, 2023

raft 0.17.1
gcc 5.5.0
ROSA Linux r11.1 FRESH
libuv - 1.44.0

src/uv.c:6:24: fatal error: sys/random.h: No such file or directory

@cole-miller
Copy link
Contributor

@SergeyDjam I guess you're using a glibc older than 2.25?

@SergeyDjam
Copy link
Author

rpm -qa | grep glibc
glibc-2.24-11-rosa2016.1.x86_64
glibc-i18ndata-2.24-11-rosa2016.1.x86_64
glibc-devel-2.24-11-rosa2016.1.x86_64

@SergeyDjam
Copy link
Author

Can't build with glibc 2.24?

@cole-miller
Copy link
Contributor

@SergeyDjam getrandom first appeared in glibc 2.25, so it's expected that you can't build libraft against glibc 2.24. We don't have an explicit policy for glibc support, and our CI covers only back to glibc 2.31, which is the version that ships in Ubuntu 20.04 (Focal Fossa, the older of the two currently-supported LTS releases). As discussed above, I think we'd be fine with a patch that removes the offending call to getrandom, but we're not treating this as a bug in libraft.

@MathieuBordere MathieuBordere added the Bug Confirmed to be a bug label Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Confirmed to be a bug
Projects
None yet
Development

No branches or pull requests

5 participants