random-util: open /dev/urandom implicitly in random_write_entropy() if needed

This commit is contained in:
Lennart Poettering
2020-12-03 20:14:17 +01:00
parent e267d76f73
commit 61bd7d1ed5
4 changed files with 17 additions and 23 deletions
+1 -6
View File
@@ -671,7 +671,6 @@ int pkcs11_token_acquire_rng(
CK_SESSION_HANDLE session) {
_cleanup_free_ void *buffer = NULL;
_cleanup_close_ int fd = -1;
size_t rps;
CK_RV rv;
int r;
@@ -696,11 +695,7 @@ int pkcs11_token_acquire_rng(
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Failed to generate RNG data on security token: %s", p11_kit_strerror(rv));
fd = open("/dev/urandom", O_WRONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
return log_debug_errno(errno, "Failed to open /dev/urandom for writing: %m");
r = loop_write(fd, buffer, rps, false);
r = random_write_entropy(-1, buffer, rps, false);
if (r < 0)
return log_debug_errno(r, "Failed to write PKCS#11 acquired random data to /dev/urandom: %m");