$NetBSD: patch-aa,v 1.1 2012/10/15 22:48:01 drochner Exp $

--- uuid.c.orig	2010-11-11 23:48:13.000000000 +0000
+++ uuid.c
@@ -30,6 +30,7 @@
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
@@ -46,16 +47,7 @@ static u_int32_t clock_seq;
 static const u_int32_t clock_seq_max = 0x3fff; /* 14 bits */
 static int clock_seq_initialized;
 
-unsigned long long
-monotonic_us(void)
-{
-	struct timespec ts;
-
-	syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &ts);
-	return ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000;
-}
-
-int
+static int
 read_bootid_node(unsigned char *buf, size_t size)
 {
 	FILE *boot_id;
@@ -81,28 +73,17 @@ read_bootid_node(unsigned char *buf, siz
 static void
 read_random_bytes(unsigned char *buf, size_t size)
 {
-	int i;
-	pid_t pid;
-
-	i = open("/dev/urandom", O_RDONLY);
-	if(i >= 0)
-	{
-		read(i, buf, size);
-		close(i);
-	}
-	/* Paranoia. /dev/urandom may be missing.
-	 * rand() is guaranteed to generate at least [0, 2^15) range,
-	 * but lowest bits in some libc are not so "random".  */
-	srand(monotonic_us());
-	pid = getpid();
-	while(1)
-	{
-		for(i = 0; i < size; i++)
-			buf[i] ^= rand() >> 5;
-		if(pid == 0)
-			break;
-		srand(pid);
-		pid = 0;
+	long r;
+#if 0
+	srandomdev();
+#endif
+
+	while ((ssize_t)size > 0) {
+		r = random();
+		memcpy(buf, &r,
+		    size > sizeof(r) ? sizeof(r) : size);
+		buf += sizeof(r);
+		size -= sizeof(r);
 	}
 }
 
@@ -162,7 +143,7 @@ generate_uuid(unsigned char uuid_out[16]
 	 * nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of
 	 * Gregorian reform to the Christian calendar).
 	 */
-	syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
+	clock_gettime(CLOCK_REALTIME, &ts);
 	time_all = ((u_int64_t)ts.tv_sec) * (NSEC_PER_SEC / 100);
 	time_all += ts.tv_nsec / 100;
 
