From cc5bf815d325867d4d96edb7963b695dfce7d849 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 13 May 2021 21:33:55 +0200 Subject: [PATCH] getrandom: Produce a better error code. Reported by Paul Eggert in . * lib/getrandom.c (getrandom): When open() fails with an error that does not indicate the absence of the file, fail with that error code, not with ENOSYS. --- ChangeLog | 9 +++++++++ lib/getrandom.c | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 711e53f9c1..b12c196128 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2021-05-13 Bruno Haible + + getrandom: Produce a better error code. + Reported by Paul Eggert in + . + * lib/getrandom.c (getrandom): When open() fails with an error that does + not indicate the absence of the file, fail with that error code, not + with ENOSYS. + 2021-05-13 Bruno Haible fstatat: Document a glibc 2.7 bug. diff --git a/lib/getrandom.c b/lib/getrandom.c index 6160118336..9e90e646aa 100644 --- a/lib/getrandom.c +++ b/lib/getrandom.c @@ -179,7 +179,8 @@ getrandom (void *buffer, size_t length, unsigned int flags) fd = open (randdevice[devrandom], oflags); if (fd < 0) { - errno = ENOSYS; + if (errno == ENOENT || errno == ENOTDIR) + errno = ENOSYS; return -1; } randfd[devrandom] = fd; -- 2.39.5