From 7d9b49293c560850e5555d7dd7fc65b20dfd29cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 2 Nov 2021 17:55:24 +0100 Subject: [PATCH] core: add runtime fallback for nonpresent getrandom() sycall The current compile-time-check only tests for the getrandom() syscall wrapper of libc. The presence of this wrapper however does not relate to the presence of the actual syscall at runtime. --- src/pipewire/impl-core.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pipewire/impl-core.c b/src/pipewire/impl-core.c index 624a35311..9545fdae0 100644 --- a/src/pipewire/impl-core.c +++ b/src/pipewire/impl-core.c @@ -34,18 +34,22 @@ #include #endif -#ifndef HAVE_GETRANDOM -#include +static ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags) { + ssize_t bytes; + +#ifdef HAVE_GETRANDOM + bytes = getrandom(buf, buflen ,flags); + if (!(bytes == -1 && errno == ENOSYS)) + return bytes; +#endif -ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) { int fd = open("/dev/urandom", O_CLOEXEC); if (fd < 0) return -1; - ssize_t bytes = read(fd, buf, buflen); + bytes = read(fd, buf, buflen); close(fd); return bytes; } -#endif #include #include @@ -429,7 +433,7 @@ struct pw_impl_core *pw_context_create_core(struct pw_context *context, this->info.host_name = pw_get_host_name(); this->info.version = pw_get_library_version(); do { - res = getrandom(&this->info.cookie, + res = pw_getrandom(&this->info.cookie, sizeof(this->info.cookie), 0); } while ((res == -1) && (errno == EINTR)); if (res == -1) {