mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 09:10:10 +01:00
glib-aux: add getrandom() syscall wrapper as fallback
We make an effort to get a better fallback case with
_bad_random_bytes().
Also make an effort to get good randomness in the first place. Even if
we compile against libc headers that don't provide getrandom(). Also,
this isn't really ugly, because for a long time glibc was reluctant to
add getrandom() wrapper and using syscall() was the way to go.
(cherry picked from commit 05a6936bef)
This commit is contained in:
parent
f84ebc4611
commit
e427f53b8f
1 changed files with 21 additions and 0 deletions
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <sys/auxv.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#if USE_SYS_RANDOM_H
|
||||
#include <sys/random.h>
|
||||
|
|
@ -21,6 +22,26 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !defined(SYS_getrandom) && defined(__NR_getrandom)
|
||||
#define SYS_getrandom __NR_getrandom
|
||||
#endif
|
||||
|
||||
#ifndef GRND_NONBLOCK
|
||||
#define GRND_NONBLOCK 0x01
|
||||
#endif
|
||||
|
||||
#if !HAVE_GETRANDOM && defined(SYS_getrandom)
|
||||
static int
|
||||
getrandom(void *buf, size_t buflen, unsigned flags)
|
||||
{
|
||||
return syscall(SYS_getrandom, buf, buflen, flags);
|
||||
}
|
||||
#undef HAVE_GETRANDOM
|
||||
#define HAVE_GETRANDOM 1
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define STATIC_SALT "l6z5vMBldDlCD6na"
|
||||
|
||||
typedef struct _nm_packed {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue