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>
master
Miroslav Lichvar 2013-10-25 14:45:35 +02:00 committed by Richard Cochran
parent 23d31d090e
commit ab84eade0a
1 changed files with 3 additions and 1 deletions

View File

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