Tomas Janousek 5a0cfd
diff -up bash-3.2/config.h.in.rng.patch bash-3.2/config.h.in
Tomas Janousek 5a0cfd
--- bash-3.2/config.h.in.rng.patch	2007-08-20 13:42:49.000000000 +0200
Tomas Janousek 5a0cfd
+++ bash-3.2/config.h.in	2007-08-20 13:42:49.000000000 +0200
Tomas Janousek 5a0cfd
@@ -203,6 +203,8 @@
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
 #define DEFAULT_MAIL_DIRECTORY "/var/spool/mail"
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
+#undef PATH_RANDOMDEV
Tomas Janousek 5a0cfd
+
Tomas Janousek 5a0cfd
 /* Characteristics of the system's header files and libraries that affect
Tomas Janousek 5a0cfd
    the compilation environment. */
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
@@ -817,6 +819,10 @@
Tomas Janousek 5a0cfd
 /* Define if you have the wcwidth function.  */
Tomas Janousek 5a0cfd
 #undef HAVE_WCWIDTH
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
+#undef HAVE_RANDOM
Tomas Janousek 5a0cfd
+
Tomas Janousek 5a0cfd
+#undef HAVE_SRANDOM
Tomas Janousek 5a0cfd
+
Tomas Janousek 5a0cfd
 /* Presence of certain system include files. */
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
 /* Define if you have the <arpa/inet.h> header file. */
Tomas Janousek 5a0cfd
diff -up bash-3.2/configure.in.rng.patch bash-3.2/configure.in
Tomas Janousek 5a0cfd
--- bash-3.2/configure.in.rng.patch	2007-08-20 13:42:49.000000000 +0200
Tomas Janousek 5a0cfd
+++ bash-3.2/configure.in	2007-08-20 13:42:49.000000000 +0200
Tomas Janousek 5a0cfd
@@ -111,6 +111,7 @@ AC_ARG_WITH(gnu-malloc, AC_HELP_STRING([
Tomas Janousek 5a0cfd
 AC_ARG_WITH(installed-readline, AC_HELP_STRING([--with-installed-readline], [use a version of the readline library that is already installed]), opt_with_installed_readline=$withval)
Tomas Janousek 5a0cfd
 AC_ARG_WITH(purecov, AC_HELP_STRING([--with-purecov], [configure to postprocess with pure coverage]), opt_purecov=$withval)
Tomas Janousek 5a0cfd
 AC_ARG_WITH(purify, AC_HELP_STRING([--with-purify], [configure to postprocess with purify]), opt_purify=$withval)
Tomas Janousek 5a0cfd
+AC_ARG_WITH(random, AC_HELP_STRING([--with-randomdev=path], [use specified random device instead of /dev/urandom]), opt_randomdev=$withval)
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
 if test "$opt_bash_malloc" = yes; then
Tomas Janousek 5a0cfd
 	MALLOC_TARGET=malloc
Tomas Janousek 5a0cfd
@@ -152,6 +153,15 @@ if test -z "${DEBUGGER_START_FILE}"; the
Tomas Janousek 5a0cfd
 	DEBUGGER_START_FILE=${ac_default_prefix}/share/bashdb/bashdb-main.inc
Tomas Janousek 5a0cfd
 fi
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
+if test "$opt_randomdev" = yes -o -z "$opt_randomdev"; then
Tomas Janousek 5a0cfd
+	opt_randomdev="/dev/urandom"
Tomas Janousek 5a0cfd
+elif test "$opt_randomdev" = no; then
Tomas Janousek 5a0cfd
+	opt_randomdev=
Tomas Janousek 5a0cfd
+fi
Tomas Janousek 5a0cfd
+if test -n "$opt_randomdev"; then
Tomas Janousek 5a0cfd
+	AC_DEFINE_UNQUOTED(PATH_RANDOMDEV, "$opt_randomdev", [Random device path.])
Tomas Janousek 5a0cfd
+fi
Tomas Janousek 5a0cfd
+
Tomas Janousek 5a0cfd
 dnl optional shell features in config.h.in
Tomas Janousek 5a0cfd
 opt_minimal_config=no
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
@@ -708,6 +718,8 @@ AC_CHECK_FUNCS(bcopy bzero confstr fnmat
Tomas Janousek 5a0cfd
 		setenv setlinebuf setlocale setvbuf siginterrupt strchr \
Tomas Janousek 5a0cfd
 		sysconf tcgetattr times ttyname tzset unsetenv)
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
+AC_CHECK_FUNCS(random srandom)
Tomas Janousek 5a0cfd
+
Tomas Janousek 5a0cfd
 AC_CHECK_FUNCS(vsnprintf snprintf vasprintf asprintf)
Tomas Janousek 5a0cfd
 AC_CHECK_FUNCS(isascii isblank isgraph isprint isspace isxdigit)
Tomas Janousek 5a0cfd
 AC_CHECK_FUNCS(getpwent getpwnam getpwuid)
Tomas Janousek 5a0cfd
diff -up bash-3.2/variables.c.rng.patch bash-3.2/variables.c
Tomas Janousek 5a0cfd
--- bash-3.2/variables.c.rng.patch	2006-09-08 19:33:32.000000000 +0200
Tomas Janousek 5a0cfd
+++ bash-3.2/variables.c	2007-08-20 16:16:56.000000000 +0200
Tomas Janousek 5a0cfd
@@ -42,6 +42,11 @@
Tomas Janousek 5a0cfd
 #include "bashansi.h"
Tomas Janousek 5a0cfd
 #include "bashintl.h"
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
+#if defined (PATH_RANDOMDEV)
Tomas Janousek 5a0cfd
+#  include <errno.h>
Tomas Janousek 5a0cfd
+#  include "filecntl.h"
Tomas Janousek 5a0cfd
+#endif
Tomas Janousek 5a0cfd
+
Tomas Janousek 5a0cfd
 #include "shell.h"
Tomas Janousek 5a0cfd
 #include "flags.h"
Tomas Janousek 5a0cfd
 #include "execute_cmd.h"
Tomas Janousek 5a0cfd
@@ -182,7 +187,8 @@ static SHELL_VAR *get_seconds __P((SHELL
Tomas Janousek 5a0cfd
 static SHELL_VAR *init_seconds_var __P((void));
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
 static int brand __P((void));
Tomas Janousek 5a0cfd
-static void sbrand __P((unsigned long));		/* set bash random number generator. */
Tomas Janousek 5a0cfd
+static void sbrand __P((unsigned int));		/* set bash random number generator. */
Tomas Janousek 5a0cfd
+static void seed_random __P((void));                    /* seed the generator randomly */
Tomas Janousek 5a0cfd
 static SHELL_VAR *assign_random __P((SHELL_VAR *, char *, arrayind_t));
Tomas Janousek 5a0cfd
 static SHELL_VAR *get_random __P((SHELL_VAR *));
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
@@ -494,9 +500,6 @@ initialize_shell_variables (env, privmod
Tomas Janousek 5a0cfd
     }
Tomas Janousek 5a0cfd
 #endif /* HISTORY */
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
-  /* Seed the random number generator. */
Tomas Janousek 5a0cfd
-  sbrand (dollar_dollar_pid + shell_start_time);
Tomas Janousek 5a0cfd
-
Tomas Janousek 5a0cfd
   /* Handle some "special" variables that we may have inherited from a
Tomas Janousek 5a0cfd
      parent shell. */
Tomas Janousek 5a0cfd
   if (interactive_shell)
Tomas Janousek 5a0cfd
@@ -1143,9 +1146,11 @@ init_seconds_var ()
Tomas Janousek 5a0cfd
 }
Tomas Janousek 5a0cfd
      
Tomas Janousek 5a0cfd
 /* The random number seed.  You can change this by setting RANDOM. */
Tomas Janousek 5a0cfd
+#if !defined (HAVE_RANDOM)
Tomas Janousek 5a0cfd
 static unsigned long rseed = 1;
Tomas Janousek 5a0cfd
+#endif
Tomas Janousek 5a0cfd
 static int last_random_value;
Tomas Janousek 5a0cfd
-static int seeded_subshell = 0;
Tomas Janousek 5a0cfd
+static int seeded_subshell = -1;
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
 /* A linear congruential random number generator based on the example
Tomas Janousek 5a0cfd
    one in the ANSI C standard.  This one isn't very good, but a more
Tomas Janousek 5a0cfd
@@ -1155,28 +1160,58 @@ static int seeded_subshell = 0;
Tomas Janousek 5a0cfd
 static int
Tomas Janousek 5a0cfd
 brand ()
Tomas Janousek 5a0cfd
 {
Tomas Janousek 5a0cfd
+#if defined (HAVE_RANDOM)
Tomas Janousek 5a0cfd
+  unsigned int rseed;
Tomas Janousek 5a0cfd
+  rseed = random();
Tomas Janousek 5a0cfd
+#else
Tomas Janousek 5a0cfd
   rseed = rseed * 1103515245 + 12345;
Tomas Janousek 5a0cfd
+#endif
Tomas Janousek 5a0cfd
   return ((unsigned int)((rseed >> 16) & 32767));	/* was % 32768 */
Tomas Janousek 5a0cfd
 }
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
 /* Set the random number generator seed to SEED. */
Tomas Janousek 5a0cfd
 static void
Tomas Janousek 5a0cfd
 sbrand (seed)
Tomas Janousek 5a0cfd
-     unsigned long seed;
Tomas Janousek 5a0cfd
+     unsigned int seed;
Tomas Janousek 5a0cfd
 {
Tomas Janousek 5a0cfd
+#if defined (HAVE_RANDOM)
Tomas Janousek 5a0cfd
+  srandom((unsigned int)seed);
Tomas Janousek 5a0cfd
+#else
Tomas Janousek 5a0cfd
   rseed = seed;
Tomas Janousek 5a0cfd
+#endif
Tomas Janousek 5a0cfd
   last_random_value = 0;
Tomas Janousek 5a0cfd
 }
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
+static void
Tomas Janousek 5a0cfd
+seed_random ()
Tomas Janousek 5a0cfd
+{
Tomas Janousek 5a0cfd
+  unsigned int seed;
Tomas Janousek 5a0cfd
+#if defined (PATH_RANDOMDEV)
Tomas Janousek 5a0cfd
+  int fd;
Tomas Janousek 5a0cfd
+  int rv;
Tomas Janousek 5a0cfd
+  if ((rv = fd = open (PATH_RANDOMDEV, O_RDONLY)) != -1) { 
Tomas Janousek 5a0cfd
+    while ((rv = read(fd, &seed, sizeof(seed))) != sizeof(seed) && errno == EINTR);
Tomas Janousek 5a0cfd
+    close (fd);
Tomas Janousek 5a0cfd
+  }
Tomas Janousek 5a0cfd
+  if (rv != sizeof(seed)) {
Tomas Janousek 5a0cfd
+#endif
Tomas Janousek 5a0cfd
+    struct timeval tv;
Tomas Janousek 5a0cfd
+    gettimeofday(&tv, NULL);
Tomas Janousek 5a0cfd
+    seed = (unsigned int)tv.tv_sec + (unsigned int)tv.tv_usec + getpid();
Tomas Janousek 5a0cfd
+#if defined (PATH_RANDOMDEV)
Tomas Janousek 5a0cfd
+  }
Tomas Janousek 5a0cfd
+#endif
Tomas Janousek 5a0cfd
+  sbrand (seed);
Tomas Janousek 5a0cfd
+}
Tomas Janousek 5a0cfd
+
Tomas Janousek 5a0cfd
 static SHELL_VAR *
Tomas Janousek 5a0cfd
 assign_random (self, value, unused)
Tomas Janousek 5a0cfd
      SHELL_VAR *self;
Tomas Janousek 5a0cfd
      char *value;
Tomas Janousek 5a0cfd
      arrayind_t unused;
Tomas Janousek 5a0cfd
 {
Tomas Janousek 5a0cfd
-  sbrand (strtoul (value, (char **)NULL, 10));
Tomas Janousek 5a0cfd
-  if (subshell_environment)
Tomas Janousek 5a0cfd
-    seeded_subshell = 1;
Tomas Janousek 5a0cfd
+  sbrand ((unsigned int)strtoul (value, (char **)NULL, 10));
Tomas Janousek 5a0cfd
+  seeded_subshell = subshell_level;
Tomas Janousek 5a0cfd
   return (self);
Tomas Janousek 5a0cfd
 }
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
@@ -1186,10 +1221,10 @@ get_random_number ()
Tomas Janousek 5a0cfd
   int rv;
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
   /* Reset for command and process substitution. */
Tomas Janousek 5a0cfd
-  if (subshell_environment && seeded_subshell == 0)
Tomas Janousek 5a0cfd
+  if (seeded_subshell < subshell_level)
Tomas Janousek 5a0cfd
     {
Tomas Janousek 5a0cfd
-      sbrand (rseed + getpid() + NOW);
Tomas Janousek 5a0cfd
-      seeded_subshell = 1;
Tomas Janousek 5a0cfd
+      seed_random ();
Tomas Janousek 5a0cfd
+      seeded_subshell = subshell_level;
Tomas Janousek 5a0cfd
     }
Tomas Janousek 5a0cfd
 
Tomas Janousek 5a0cfd
   do