From 8b26cf4365eb7411138e5aa1eb2d5a38c3f8dea7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 11 Oct 2017 13:42:11 +0200 Subject: [PATCH] systemd: fix compilation if libc doesn't provide getrandom() Before commit 650a7022c16d581a9eee71d6856fe147ec9ddd44, 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: 650a7022c16d581a9eee71d6856fe147ec9ddd44 --- src/systemd/src/basic/random-util.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/systemd/src/basic/random-util.c b/src/systemd/src/basic/random-util.c index 01092a81e6..3b6ddb7dbc 100644 --- a/src/systemd/src/basic/random-util.c +++ b/src/systemd/src/basic/random-util.c @@ -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)