1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| | Explicitly use a non-blocking random primitive. This is used primarily
to compute FAT "serial numbers" in libparted/fs/r/fat/fat.c:fat_create,
for which GRND_NONBLOCK is probably good enough.
Assume the running kernel does support 'getrandom', which is the case on
GuixSD. See <https://bugs.gnu.org/31268>.
--- a/libparted/labels/misc.h
+++ b/libparted/labels/misc.h
@@ -17,7 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <inttypes.h>
-#include <uuid/uuid.h>
+#include <sys/random.h>
+#include <errno.h>
/* hack: use the ext2 uuid library to generate a reasonably random (hopefully
* with /dev/random) number. Unfortunately, we can only use 4 bytes of it.
@@ -28,11 +29,17 @@ static inline uint32_t
generate_random_uint32 (void)
{
union {
- uuid_t uuid;
+ char uuid[4];
uint32_t i;
} uu32;
+ ssize_t ret;
- uuid_generate (uu32.uuid);
+ do
+ ret = getrandom (uu32.uuid, sizeof uu32, GRND_NONBLOCK);
+ while (ret == EAGAIN);
+
+ if (ret < sizeof uu32)
+ abort ();
return uu32.i > 0 ? uu32.i : 0xffffffff;
}
|