If virRandomBytes() fails there is no point calling
virRandomBits() because it uses virRandomBytes() internally
again.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/util/viruuid.c | 25 +++----------------------
1 file changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/util/viruuid.c b/src/util/viruuid.c
index 61877aeba4..f588a62ec6 100644
--- a/src/util/viruuid.c
+++ b/src/util/viruuid.c
@@ -48,18 +48,6 @@ VIR_LOG_INIT("util.uuid");
static unsigned char host_uuid[VIR_UUID_BUFLEN];
-static int
-virUUIDGeneratePseudoRandomBytes(unsigned char *buf,
- int buflen)
-{
- while (buflen > 0) {
- *buf++ = virRandomBits(8);
- buflen--;
- }
-
- return 0;
-}
-
/**
* virUUIDGenerate:
* @uuid: array of VIR_UUID_BUFLEN bytes to store the new UUID
@@ -71,18 +59,11 @@ virUUIDGeneratePseudoRandomBytes(unsigned char *buf,
int
virUUIDGenerate(unsigned char *uuid)
{
- int err;
-
if (uuid == NULL)
return -1;
- if ((err = virRandomBytes(uuid, VIR_UUID_BUFLEN)) < 0) {
- char ebuf[1024];
- VIR_WARN("Falling back to pseudorandom UUID,"
- " failed to generate random bytes: %s",
- virStrerror(-err, ebuf, sizeof(ebuf)));
- err = virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_BUFLEN);
- }
+ if (virRandomBytes(uuid, VIR_UUID_BUFLEN) < 0)
+ return -1;
/*
* Make UUID RFC 4122 compliant. Following form will be used:
@@ -103,7 +84,7 @@ virUUIDGenerate(unsigned char *uuid)
uuid[6] = (uuid[6] & 0x0F) | (4 << 4);
uuid[8] = (uuid[8] & 0x3F) | (2 << 6);
- return err;
+ return 0;
}
/**
--
2.16.1