2009-08-28 17:45:57 +02:00
|
|
|
Index: variables.c
|
|
|
|
===================================================================
|
|
|
|
--- variables.c.orig
|
|
|
|
+++ variables.c
|
2009-03-03 18:12:53 +01:00
|
|
|
@@ -1203,6 +1203,7 @@ init_seconds_var ()
|
2006-12-15 18:03:59 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#if !defined(linux)
|
|
|
|
/* The random number seed. You can change this by setting RANDOM. */
|
|
|
|
static unsigned long rseed = 1;
|
|
|
|
static int last_random_value;
|
2009-03-03 18:12:53 +01:00
|
|
|
@@ -1256,6 +1257,24 @@ seedrand ()
|
|
|
|
sbrand (tv.tv_sec ^ tv.tv_usec ^ getpid ());
|
2006-12-15 18:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+#else
|
|
|
|
+
|
|
|
|
+static int last_sbrand_pid;
|
|
|
|
+
|
|
|
|
+static int brand ()
|
|
|
|
+{
|
|
|
|
+ return random() & 32767;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void sbrand (unsigned long seed)
|
|
|
|
+{
|
|
|
|
+ srandom(seed);
|
|
|
|
+}
|
2009-03-03 18:12:53 +01:00
|
|
|
+
|
|
|
|
+static void
|
|
|
|
+seedrand () {}
|
2006-12-15 18:03:59 +01:00
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
static SHELL_VAR *
|
2009-03-03 18:12:53 +01:00
|
|
|
assign_random (self, value, unused, key)
|
2006-12-15 18:03:59 +01:00
|
|
|
SHELL_VAR *self;
|
2009-03-03 18:12:53 +01:00
|
|
|
@@ -1264,8 +1283,10 @@ assign_random (self, value, unused, key)
|
|
|
|
char *key;
|
|
|
|
{
|
|
|
|
sbrand (strtoul (value, (char **)NULL, 10));
|
|
|
|
+#if !defined(linux)
|
|
|
|
if (subshell_environment)
|
|
|
|
seeded_subshell = getpid ();
|
|
|
|
+#endif
|
|
|
|
return (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1274,6 +1295,7 @@ get_random_number ()
|
2006-12-15 18:03:59 +01:00
|
|
|
{
|
2009-03-03 18:12:53 +01:00
|
|
|
int rv, pid;
|
2006-12-15 18:03:59 +01:00
|
|
|
|
|
|
|
+#if !defined(linux)
|
|
|
|
/* Reset for command and process substitution. */
|
2009-03-03 18:12:53 +01:00
|
|
|
pid = getpid ();
|
|
|
|
if (subshell_environment && seeded_subshell != pid)
|
|
|
|
@@ -1285,6 +1307,18 @@ get_random_number ()
|
2006-12-15 18:03:59 +01:00
|
|
|
do
|
|
|
|
rv = brand ();
|
|
|
|
while (rv == last_random_value);
|
|
|
|
+#else
|
|
|
|
+ if (subshell_environment)
|
|
|
|
+ {
|
|
|
|
+ int mypid = getpid();
|
|
|
|
+ if (mypid != last_sbrand_pid)
|
|
|
|
+ {
|
|
|
|
+ last_sbrand_pid = mypid;
|
|
|
|
+ sbrand (mypid + NOW);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rv = brand();
|
|
|
|
+#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-03-03 18:12:53 +01:00
|
|
|
@@ -1296,7 +1330,9 @@ get_random (var)
|
2006-12-15 18:03:59 +01:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
rv = get_random_number ();
|
|
|
|
+#if !defined(linux)
|
|
|
|
last_random_value = rv;
|
|
|
|
+#endif
|
|
|
|
p = itos (rv);
|
|
|
|
|
|
|
|
FREE (value_cell (var));
|