1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2001,2008 Oracle. All rights reserved. 5 * 6 * $Id: os_uid.c,v 12.31 2008/01/08 20:58:43 bostic Exp $ 7 */ 8 9#include "db_config.h" 10 11#include "db_int.h" 12 13/* 14 * __os_unique_id -- 15 * Return a unique 32-bit value. 16 * 17 * PUBLIC: void __os_unique_id __P((ENV *, u_int32_t *)); 18 */ 19void 20__os_unique_id(env, idp) 21 ENV *env; 22 u_int32_t *idp; 23{ 24 DB_ENV *dbenv; 25 db_timespec v; 26 pid_t pid; 27 u_int32_t id; 28 29 *idp = 0; 30 31 dbenv = env == NULL ? NULL : env->dbenv; 32 33 /* 34 * Our randomized value is comprised of our process ID, the current 35 * time of day and a stack address, all XOR'd together. 36 */ 37 __os_id(dbenv, &pid, NULL); 38 __os_gettime(env, &v, 1); 39 40 id = (u_int32_t)pid ^ 41 (u_int32_t)v.tv_sec ^ (u_int32_t)v.tv_nsec ^ P_TO_UINT32(&pid); 42 43 /* 44 * We could try and find a reasonable random-number generator, but 45 * that's not all that easy to do. Seed and use srand()/rand(), if 46 * we can find them. 47 */ 48 if (DB_GLOBAL(uid_init) == 0) { 49 DB_GLOBAL(uid_init) = 1; 50 srand((u_int)id); 51 } 52 id ^= (u_int)rand(); 53 54 *idp = id; 55} 56