mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	Make the probe for RNG sources at runtime since the configure script isn't
compatible with cross-compiling. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@744 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									e4b2a47bb1
								
							
						
					
					
						commit
						c22a0c12e4
					
				
					 4 changed files with 65 additions and 65 deletions
				
			
		
							
								
								
									
										20
									
								
								configure.ac
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								configure.ac
									
										
									
									
									
								
							| 
						 | 
					@ -396,26 +396,6 @@ AC_SUBST(LIRC_CFLAGS)
 | 
				
			||||||
AC_SUBST(LIRC_LIBS)
 | 
					AC_SUBST(LIRC_LIBS)
 | 
				
			||||||
AM_CONDITIONAL([HAVE_LIRC], [test "x$HAVE_LIRC" = x1])
 | 
					AM_CONDITIONAL([HAVE_LIRC], [test "x$HAVE_LIRC" = x1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### /dev/random ###
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
AC_MSG_CHECKING([whether a random device is available])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
rnd="no"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if test -e /dev/urandom ; then
 | 
					 | 
				
			||||||
   rnd=/dev/urandom
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
   if test -e /dev/random ; then
 | 
					 | 
				
			||||||
      rnd=/dev/random
 | 
					 | 
				
			||||||
   fi
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if test "x$rnd" != "no" ; then
 | 
					 | 
				
			||||||
   AC_DEFINE_UNQUOTED([RANDOM_DEVICE], ["$rnd"], [Random device])
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
AC_MSG_RESULT([$rnd])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
###################################
 | 
					###################################
 | 
				
			||||||
#            Output               #
 | 
					#            Output               #
 | 
				
			||||||
###################################
 | 
					###################################
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,6 +63,7 @@
 | 
				
			||||||
#include <polypcore/cli-text.h>
 | 
					#include <polypcore/cli-text.h>
 | 
				
			||||||
#include <polypcore/pid.h>
 | 
					#include <polypcore/pid.h>
 | 
				
			||||||
#include <polypcore/namereg.h>
 | 
					#include <polypcore/namereg.h>
 | 
				
			||||||
 | 
					#include <polypcore/random.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "cmdline.h"
 | 
					#include "cmdline.h"
 | 
				
			||||||
#include "cpulimit.h"
 | 
					#include "cpulimit.h"
 | 
				
			||||||
| 
						 | 
					@ -135,29 +136,6 @@ static void close_pipe(int p[2]) {
 | 
				
			||||||
    p[0] = p[1] = -1;
 | 
					    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[]) {
 | 
					int main(int argc, char *argv[]) {
 | 
				
			||||||
    pa_core *c;
 | 
					    pa_core *c;
 | 
				
			||||||
    pa_strbuf *buf = NULL;
 | 
					    pa_strbuf *buf = NULL;
 | 
				
			||||||
| 
						 | 
					@ -203,7 +181,7 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set_random_seed();
 | 
					    pa_random_seed();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    pa_log_set_ident("polypaudio");
 | 
					    pa_log_set_ident("polypaudio");
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,31 +36,72 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "random.h"
 | 
					#include "random.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_random(void *ret_data, size_t length) {
 | 
					static int has_whined = 0;
 | 
				
			||||||
    int fd;
 | 
					
 | 
				
			||||||
    ssize_t r = 0;
 | 
					static const char *devices[] = { "/dev/urandom", "/dev/random", NULL };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int pa_random_proper(void *ret_data, size_t length) {
 | 
				
			||||||
    assert(ret_data && length);
 | 
					    assert(ret_data && length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef RANDOM_DEVICE
 | 
					#ifdef OS_IS_WIN32
 | 
				
			||||||
    if ((fd = open(RANDOM_DEVICE, O_RDONLY)) >= 0) {
 | 
					
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else /* OS_IS_WIN32 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int fd, ret;
 | 
				
			||||||
 | 
					    ssize_t r = 0;
 | 
				
			||||||
 | 
					    const char **device;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    device = devices;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (*device) {
 | 
				
			||||||
 | 
					        ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ((fd = open(*device, O_RDONLY)) >= 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ((r = pa_loop_read(fd, ret_data, length)) < 0 || (size_t) r != length)
 | 
					            if ((r = pa_loop_read(fd, ret_data, length)) < 0 || (size_t) r != length)
 | 
				
			||||||
            pa_log_error(__FILE__": failed to read entropy from '%s'", RANDOM_DEVICE);
 | 
					                ret = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            close(fd);
 | 
					            close(fd);
 | 
				
			||||||
    }
 | 
					        } else
 | 
				
			||||||
#endif
 | 
					            ret = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((size_t) r != length) {
 | 
					        if (ret == 0)
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					#endif /* OS_IS_WIN32 */
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void pa_random_seed() {
 | 
				
			||||||
 | 
					    unsigned int seed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (pa_random_proper(&seed, sizeof(unsigned int)) < 0) {
 | 
				
			||||||
 | 
					        if (!has_whined)
 | 
				
			||||||
 | 
					            pa_log_warn(__FILE__": failed to get proper entropy. Falling back to seeding with current time.");
 | 
				
			||||||
 | 
					        has_whined = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        seed = (unsigned int) time(NULL);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    srand(seed);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void pa_random(void *ret_data, size_t length) {
 | 
				
			||||||
    uint8_t *p;
 | 
					    uint8_t *p;
 | 
				
			||||||
    size_t l;
 | 
					    size_t l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef RANDOM_DEVICE        
 | 
					    assert(ret_data && length);
 | 
				
			||||||
        pa_log_warn(__FILE__": WARNING: Failed to open entropy device '"RANDOM_DEVICE"': %s"
 | 
					
 | 
				
			||||||
                    ", falling back to unsecure pseudo RNG.\n", strerror(errno));
 | 
					    if (pa_random_proper(ret_data, length) >= 0)
 | 
				
			||||||
#endif
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!has_whined)
 | 
				
			||||||
 | 
					        pa_log_warn(__FILE__": failed to get proper entropy. Falling back to unsecure pseudo RNG.");
 | 
				
			||||||
 | 
					    has_whined = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (p = ret_data, l = length; l > 0; p++, l--)
 | 
					    for (p = ret_data, l = length; l > 0; p++, l--)
 | 
				
			||||||
        *p = (uint8_t) rand();
 | 
					        *p = (uint8_t) rand();
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@
 | 
				
			||||||
  USA.
 | 
					  USA.
 | 
				
			||||||
***/
 | 
					***/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void pa_random_seed();
 | 
				
			||||||
void pa_random(void *ret_data, size_t length);
 | 
					void pa_random(void *ret_data, size_t length);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue