mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-22 00:00:03 +03:00
urandom fallback
This commit is contained in:
parent
4b9e40b23a
commit
8aaf7d913a
@ -10,10 +10,19 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <linux/bug.h>
|
||||
|
||||
#ifdef __NR_getrandom
|
||||
static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
{
|
||||
return syscall(SYS_getrandom, buf, buflen, flags);
|
||||
}
|
||||
#else
|
||||
extern int urandom_fd;
|
||||
|
||||
static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
{
|
||||
return read(urandom_fd, buf, buflen);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void get_random_bytes(void *buf, int nbytes)
|
||||
{
|
||||
|
@ -179,3 +179,17 @@ static void sched_init(void)
|
||||
rcu_init();
|
||||
rcu_register_thread();
|
||||
}
|
||||
|
||||
#ifndef __NR_getrandom
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
int urandom_fd;
|
||||
|
||||
__attribute__((constructor(101)))
|
||||
static void rand_init(void)
|
||||
{
|
||||
urandom_fd = open("/dev/urandom", O_RDONLY);
|
||||
BUG_ON(urandom_fd < 0);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user