mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-09-20 00:11:31 +00:00
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.
This commit is contained in:
parent
25ddf0e3cf
commit
7d9b49293c
|
@ -34,18 +34,22 @@
|
|||
#include <sys/random.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETRANDOM
|
||||
#include <fcntl.h>
|
||||
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 <spa/utils/string.h>
|
||||
#include <spa/debug/types.h>
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue