@@ -65,29 +65,23 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED,
"Unable to read random bytes");
return -1;
}
-
- return 0;
#else
- int ret = -1;
- int got;
-
- while (buflen > 0) {
- got = read(fd, buf, buflen);
- if (got < 0) {
- error_setg_errno(errp, errno,
- "Unable to read random bytes");
- goto cleanup;
- } else if (!got) {
- error_setg(errp,
- "Unexpected EOF reading random bytes");
- goto cleanup;
+ while (1) {
+ ssize_t got = read(fd, buf, buflen);
+ if (likely(got == buflen)) {
+ return 0;
+ }
+ if (got > 0) {
+ buflen -= got;
+ buf += got;
+ } else if (got == 0) {
+ error_setg(errp, "Unexpected EOF reading random bytes");
+ return -1;
+ } else if (errno != EINTR) {
+ error_setg_errno(errp, errno, "Unable to read random bytes");
+ return -1;
}
- buflen -= got;
- buf += got;
}
-
- ret = 0;
- cleanup:
- return ret;
#endif
+ return 0;
}