Richard W.M. Jones
2017-Jan-26 15:51 UTC
[Libguestfs] [PATCH] Use srandom (time (NULL) + getpid ()) throughout.
It avoids two programs which start at exactly the same time from having the same random number seed, which helps in some tests. --- edit/edit.c | 3 ++- fish/fish.c | 2 +- tests/mount-local/test-parallel-mount-local.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/edit/edit.c b/edit/edit.c index 2f986a3..1e2641c 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -29,6 +29,7 @@ #include <error.h> #include <assert.h> #include <libintl.h> +#include <sys/types.h> #include <sys/time.h> #include <sys/stat.h> #include <utime.h> @@ -103,7 +104,7 @@ main (int argc, char *argv[]) textdomain (PACKAGE); /* We use random(3) below. */ - srandom (time (NULL)); + srandom (time (NULL) + getpid ()); enum { HELP_OPTION = CHAR_MAX + 1 }; diff --git a/fish/fish.c b/fish/fish.c index b7d63cf..52a9093 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -181,7 +181,7 @@ main (int argc, char *argv[]) textdomain (PACKAGE); /* We use random(3) in edit.c. */ - srandom (time (NULL)); + srandom (time (NULL) + getpid ()); parse_config (); diff --git a/tests/mount-local/test-parallel-mount-local.c b/tests/mount-local/test-parallel-mount-local.c index 3e5d95c..542f1ed 100644 --- a/tests/mount-local/test-parallel-mount-local.c +++ b/tests/mount-local/test-parallel-mount-local.c @@ -85,7 +85,7 @@ main (int argc, char *argv[]) int r, errors = 0; void *status; - srandom (time (NULL)); + srandom (time (NULL) + getpid ()); /* If the --test flag is given, then this is the test subprocess. */ if (argc == 3 && STREQ (argv[1], "--test")) { -- 2.9.3
Richard W.M. Jones
2017-Jan-26 19:30 UTC
Re: [Libguestfs] [PATCH] Use srandom (time (NULL) + getpid ()) throughout.
On Thu, Jan 26, 2017 at 03:51:20PM +0000, Richard W.M. Jones wrote:> It avoids two programs which start at exactly the same time from > having the same random number seed, which helps in some tests.Ignore this patch, better one to come. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Reasonably Related Threads
- [PATCH v2 0/2] Fix srandom issues.
- [PATCH v2] virtio-rng: return available data with O_NONBLOCK
- [problem in `xl_cmdimpl.c`] Why pid return by fork() in parent process is not the same with pid returned by getpid()?
- [PATCH v2] virtio-rng: return available data with O_NONBLOCK
- [PATCH v3] virtio-rng: return available data with O_NONBLOCK