diff options
Diffstat (limited to 'src/os/os_uid.c')
-rw-r--r-- | src/os/os_uid.c | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/src/os/os_uid.c b/src/os/os_uid.c index 2e5c9f87..c3bccb3d 100644 --- a/src/os/os_uid.c +++ b/src/os/os_uid.c @@ -1,7 +1,7 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015 Oracle and/or its affiliates. All rights reserved. * * $Id$ */ @@ -26,8 +26,6 @@ __os_unique_id(env, idp) pid_t pid; u_int32_t id; - *idp = 0; - dbenv = env == NULL ? NULL : env->dbenv; /* @@ -35,21 +33,60 @@ __os_unique_id(env, idp) * time of day and a stack address, all XOR'd together. */ __os_id(dbenv, &pid, NULL); - __os_gettime(env, &v, 1); + __os_gettime(env, &v, 0); id = (u_int32_t)pid ^ (u_int32_t)v.tv_sec ^ (u_int32_t)v.tv_nsec ^ P_TO_UINT32(&pid); - /* - * We could try and find a reasonable random-number generator, but - * that's not all that easy to do. Seed and use srand()/rand(), if - * we can find them. - */ - if (DB_GLOBAL(uid_init) == 0) { - DB_GLOBAL(uid_init) = 1; - srand((u_int)id); - } - id ^= (u_int)rand(); + if (DB_GLOBAL(random_seeded) == 0) + __os_srandom(id); + id ^= __os_random(); *idp = id; } + +/* + * __os_srandom -- + * Set the random number generator seed for BDB. + * + * PUBLIC: void __os_srandom __P((u_int)); + */ +void +__os_srandom(seed) + u_int seed; +{ + DB_GLOBAL(random_seeded) = 1; +#ifdef HAVE_RANDOM_R + (void)initstate_r(seed, &DB_GLOBAL(random_state), + sizeof(DB_GLOBAL(random_state)), &DB_GLOBAL(random_data)); + (void)srandom_r(seed, &DB_GLOBAL(random_data)); +#elif defined(HAVE_RANDOM) + srandom(seed); +#else + srand(seed); +#endif +} + +/* + * __os_random -- + * Return the next the random number generator for BDB. + * + * PUBLIC: u_int __os_random __P((void)); + */ +u_int +__os_random() +{ +#ifdef HAVE_RANDOM_R + int32_t result; +#endif + if (DB_GLOBAL(random_seeded) == 0) + __os_srandom((u_int)time(NULL)); +#ifdef HAVE_RANDOM_R + random_r(&DB_GLOBAL(random_data), &result); + return ((u_int)result); +#elif defined(HAVE_RANDOM) + return ((u_int)random()); +#else + return ((u_int)rand()); +#endif +} |