mktemp from lfs-utils

Robert Connolly robert at linuxfromscratch.org
Mon Apr 26 00:20:21 PDT 2004


This works better:

diff -Naur lfs-utils-0.5.orig/mktemp-1.5/random.c lfs-utils-0.5.frandom/
mktemp-1.5/random.c
--- lfs-utils-0.5.orig/mktemp-1.5/random.c	2001-10-01 00:21:34.000000000 +0000
+++ lfs-utils-0.5.frandom/mktemp-1.5/random.c	2004-04-26 07:15:16.000000000 
+0000
@@ -26,6 +26,7 @@
  */

 #include "config.h"
+#include <sys/sysctl.h>

 #include <sys/types.h>
 #if defined(TIME_WITH_SYS_TIME) || defined(HAVE_SYS_TIME_H)
@@ -105,16 +106,17 @@
 	SEED_T seed;
 	struct timeval tv;

-#ifdef _PATH_RANDOM
-	int fd;
+        int i, mib[3];
+        size_t len;
+        mib[0] = CTL_KERN;
+        mib[1] = KERN_RANDOM;
+        mib[2] = RANDOM_ERANDOM;
+	len = sizeof(seed);

-	if ((fd = open(_PATH_RANDOM, O_RDONLY)) != -1 &&
-	    read_loop(fd, &seed, sizeof(seed)) == sizeof(seed)) {
-		close(fd);
+	if (sysctl(mib, 3, &seed, &len, NULL, 0) != -1) {
 		SRAND(seed);
-		return;
-	}
-#endif /* _PATH_RANDOM */
+                return;
+        }

 	/* Don't have /dev/random */
 	/* XXX - check for gettimeofday() and use time() if none? */




More information about the hlfs-dev mailing list