From 02efd4fba5494565cab44842b4764744d0d860e1 Mon Sep 17 00:00:00 2001 From: KotlinCrypto Date: Sat, 23 Aug 2025 15:38:36 -0400 Subject: [PATCH] Retry posix.open when errno == EINTR --- .../kotlin/org/kotlincrypto/random/internal/URandom.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/crypto-rand/src/linuxAndroidMain/kotlin/org/kotlincrypto/random/internal/URandom.kt b/library/crypto-rand/src/linuxAndroidMain/kotlin/org/kotlincrypto/random/internal/URandom.kt index 607cfda..9d0488a 100644 --- a/library/crypto-rand/src/linuxAndroidMain/kotlin/org/kotlincrypto/random/internal/URandom.kt +++ b/library/crypto-rand/src/linuxAndroidMain/kotlin/org/kotlincrypto/random/internal/URandom.kt @@ -33,7 +33,11 @@ private inline fun openRDONLY(path: String, block: (fd: Int) -> T): T callsInPlace(block, InvocationKind.AT_MOST_ONCE) } - val fd = open(path, O_RDONLY or O_CLOEXEC, null) + @Suppress("VariableInitializerIsRedundant") + var fd = -1 + do { + fd = open(path, O_RDONLY or O_CLOEXEC, 0) + } while (fd == -1 && errno == EINTR) if (fd == -1) throw errnoToRandomnessProcurementException(errno) try {