systemd: fix compilation if libc doesn't provide getrandom()

Before commit 650a7022c1, we would
always forego using getrandom(). That changed, and now we detect
at compile time whether getrandom() is provided by libc. So, if you
build against recent libc, we use it too.

However, systemd's src/basic/missing_syscall.h also provides getrandom() by
calling the syscall directly. We don't do that, because it seems too cumbersome
to maintain.

Fixes: 650a7022c1
This commit is contained in:
Thomas Haller 2017-10-11 13:42:11 +02:00
parent 650a7022c1
commit 8b26cf4365

View file

@ -60,7 +60,14 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) {
/* Use the getrandom() syscall unless we know we don't have it. */
if (have_syscall != 0) {
#if !HAVE_GETRANDOM
/* XXX: NM: systemd calls the syscall directly in this case. Don't add that workaround.
* If you don't compile against a libc that provides getrandom(), you don't get it. */
r = -1;
errno = ENOSYS;
#else
r = getrandom(p, n, GRND_NONBLOCK);
#endif
if (r > 0) {
have_syscall = true;
if ((size_t) r == n)