mirror of https://github.com/aria2/aria2
Fix getrandom for system with libc not including errno or systems
not supporting ENOSYS in the first place. Fixes GH-347pull/364/head
parent
1ad1d43a6a
commit
ee63dff225
|
@ -46,6 +46,8 @@
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
|
|
||||||
#ifdef HAVE_GETRANDOM_INTERFACE
|
#ifdef HAVE_GETRANDOM_INTERFACE
|
||||||
|
# include <errno.h>
|
||||||
|
# include <linux/errno.h>
|
||||||
# include "getrandom_linux.h"
|
# include "getrandom_linux.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -95,7 +97,15 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len)
|
||||||
static bool have_random_support = true;
|
static bool have_random_support = true;
|
||||||
if (have_random_support) {
|
if (have_random_support) {
|
||||||
auto rv = getrandom_linux(buf, len);
|
auto rv = getrandom_linux(buf, len);
|
||||||
if (rv != -1 || errno != ENOSYS) {
|
if (rv != -1
|
||||||
|
#ifdef ENOSYS
|
||||||
|
/* If the system does not know ENOSYS at this point, just leave the
|
||||||
|
* check out. If the call failed, we'll not take this branch at all
|
||||||
|
* and disable support below.
|
||||||
|
*/
|
||||||
|
|| errno != ENOSYS
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
if (rv < -1) {
|
if (rv < -1) {
|
||||||
A2_LOG_ERROR(fmt("Failed to produce randomness: %d", errno));
|
A2_LOG_ERROR(fmt("Failed to produce randomness: %d", errno));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue