[polypaudio-commits] r719 - in /trunk/src: daemon/main.c polypcore/random.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun Apr 16 02:13:10 PDT 2006


Author: lennart
Date: Sun Apr 16 11:13:09 2006
New Revision: 719

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=719&root=polypaudio&view=rev
Log:
initialize random seed globaly from $RANDOM_DEVICE

Modified:
    trunk/src/daemon/main.c
    trunk/src/polypcore/random.c

Modified: trunk/src/daemon/main.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/daemon/main.c?rev=719&root=polypaudio&r1=718&r2=719&view=diff
==============================================================================
--- trunk/src/daemon/main.c (original)
+++ trunk/src/daemon/main.c Sun Apr 16 11:13:09 2006
@@ -135,6 +135,29 @@
     p[0] = p[1] = -1;
 }
 
+static void set_random_seed(void) {
+    unsigned int seed = 0;
+    
+#ifdef RANDOM_DEVICE
+    int fd;
+    
+    if ((fd = open(RANDOM_DEVICE, O_RDONLY)) >= 0) {
+        ssize_t r;
+
+        if ((r = pa_loop_read(fd, &seed, sizeof(seed))) < 0 || (size_t) r != sizeof(seed)) {
+            pa_log_error(__FILE__": failed to read entropy from '"RANDOM_DEVICE"'");
+            seed += (unsigned int) time(NULL);
+        }
+
+        close(fd);
+    }
+#else
+    seed = (unsigned int) time(NULL);
+#endif
+    
+    srand(seed);
+}
+
 int main(int argc, char *argv[]) {
     pa_core *c;
     pa_strbuf *buf = NULL;
@@ -180,6 +203,8 @@
     }
 #endif
 
+    set_random_seed();
+    
     pa_log_set_ident("polypaudio");
     
     conf = pa_daemon_conf_new();

Modified: trunk/src/polypcore/random.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/random.c?rev=719&root=polypaudio&r1=718&r2=719&view=diff
==============================================================================
--- trunk/src/polypcore/random.c (original)
+++ trunk/src/polypcore/random.c Sun Apr 16 11:13:09 2006
@@ -36,10 +36,6 @@
 
 #include "random.h"
 
-#ifndef OS_IS_WIN32
-#define RANDOM_DEVICE "/dev/urandom"
-#endif
-
 void pa_random(void *ret_data, size_t length) {
     int fd;
     ssize_t r = 0;
@@ -64,8 +60,6 @@
                     ", falling back to unsecure pseudo RNG.\n", strerror(errno));
 #endif
 
-        srand(time(NULL));
-        
         for (p = ret_data, l = length; l > 0; p++, l--)
             *p = (uint8_t) rand();
     }




More information about the pulseaudio-commits mailing list