Make random() more random between machines.

Include also nanoseconds from the current time in the srandom() call.
This should significantly decrease the chance of two machines using the
same random sequence.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
This commit is contained in:
Miroslav Lichvar 2013-10-25 14:45:35 +02:00 committed by Richard Cochran
parent 23d31d090e
commit ab84eade0a

View File

@ -576,12 +576,14 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
struct clock *c = &the_clock;
char phc[32];
struct interface udsif;
struct timespec ts;
memset(&udsif, 0, sizeof(udsif));
snprintf(udsif.name, sizeof(udsif.name), "%s", uds_path);
udsif.transport = TRANS_UDS;
srandom(time(NULL));
clock_gettime(CLOCK_REALTIME, &ts);
srandom(ts.tv_sec ^ ts.tv_nsec);
if (c->nports)
clock_destroy(c);