diff options
author | jbj <devnull@localhost> | 2004-10-16 01:31:54 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2004-10-16 01:31:54 +0000 |
commit | d03f220fde879509cab2ac1c73b71b7efb52b737 (patch) | |
tree | 1e34bfadac0a6618d0e9a7933bad90063a785acf /db/os/os_fid.c | |
parent | 2dc699bfe049b9319ea3719f604d25940ff52004 (diff) | |
download | librpm-tizen-d03f220fde879509cab2ac1c73b71b7efb52b737.tar.gz librpm-tizen-d03f220fde879509cab2ac1c73b71b7efb52b737.tar.bz2 librpm-tizen-d03f220fde879509cab2ac1c73b71b7efb52b737.zip |
... and in with the New ...
CVS patchset: 7471
CVS date: 2004/10/16 01:31:54
Diffstat (limited to 'db/os/os_fid.c')
-rw-r--r-- | db/os/os_fid.c | 77 |
1 files changed, 33 insertions, 44 deletions
diff --git a/db/os/os_fid.c b/db/os/os_fid.c index 5a2b6ca8e..29f19cd81 100644 --- a/db/os/os_fid.c +++ b/db/os/os_fid.c @@ -1,16 +1,14 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1996-2003 + * Copyright (c) 1996-2004 * Sleepycat Software. All rights reserved. + * + * $Id: os_fid.c,v 11.21 2004/07/06 13:55:48 bostic Exp $ */ #include "db_config.h" -#ifndef lint -static const char revid[] = "$Id: os_fid.c,v 11.17 2003/05/05 19:55:04 bostic Exp $"; -#endif /* not lint */ - #ifndef NO_SYSTEM_INCLUDES #include <sys/types.h> #include <sys/stat.h> @@ -32,9 +30,6 @@ static const char revid[] = "$Id: os_fid.c,v 11.17 2003/05/05 19:55:04 bostic Ex #include "db_int.h" -#define SERIAL_INIT 0 -static u_int32_t fid_serial = SERIAL_INIT; - /* * __os_fileid -- * Return a unique identifier for a file. The structure @@ -55,49 +50,25 @@ __os_fileid(dbenv, fname, unique_okay, fidp) { struct stat sb; size_t i; - int ret, retries; + int ret; u_int32_t tmp; u_int8_t *p; - retries = 0; - /* Clear the buffer. */ memset(fidp, 0, DB_FILE_ID_LEN); /* On POSIX/UNIX, use a dev/inode pair. */ -retry: #ifdef HAVE_VXWORKS - if (stat((char *)fname, &sb) != 0) { + RETRY_CHK((stat((char *)fname, &sb)), ret); #else - if (stat(fname, &sb) != 0) { + RETRY_CHK((stat(fname, &sb)), ret); #endif - if (((ret = __os_get_errno()) == EINTR || ret == EBUSY) && - ++retries < DB_RETRY) - goto retry; + if (ret != 0) { __db_err(dbenv, "%s: %s", fname, strerror(ret)); return (ret); } /* - * Initialize/increment the serial number we use to help avoid - * fileid collisions. Note that we don't bother with locking; - * it's unpleasant to do from down in here, and if we race on - * this no real harm will be done, since the finished fileid - * has so many other components. - * - * We increment by 100000 on each call as a simple way of - * randomizing; simply incrementing seems potentially less useful - * if pids are also simply incremented, since this is process-local - * and we may be one of a set of processes starting up. 100000 - * pushes us out of pid space on most platforms, and has few - * interesting properties in base 2. - */ - if (fid_serial == SERIAL_INIT) - __os_id(&fid_serial); - else - fid_serial += 100000; - - /* * !!! * Nothing is ever big enough -- on Sparc V9, st_ino, st_dev and the * time_t types are all 8 bytes. As DB_FILE_ID_LEN is only 20 bytes, @@ -132,17 +103,35 @@ retry: *fidp++ = *p++; if (unique_okay) { - /* - * We want the number of seconds, not the high-order 0 bits, - * so convert the returned time_t to a (potentially) smaller - * fixed-size type. - */ - tmp = (u_int32_t)time(NULL); + static u_int32_t fid_serial = 0; + + /* Add in 32-bits of (hopefully) unique number. */ + __os_unique_id(dbenv, &tmp); for (p = (u_int8_t *)&tmp, i = sizeof(u_int32_t); i > 0; --i) *fidp++ = *p++; - for (p = (u_int8_t *)&fid_serial, i = sizeof(u_int32_t); - i > 0; --i) + /* + * Initialize/increment the serial number we use to help + * avoid fileid collisions. Note we don't bother with + * locking; it's unpleasant to do from down in here, and + * if we race on this no real harm will be done, since the + * finished fileid has so many other components. + * + * We increment by 100000 on each call as a simple way of + * randomizing; simply incrementing seems potentially less + * useful if pids are also simply incremented, since this + * is process-local and we may be one of a set of processes + * starting up. 100000 pushes us out of pid space on most + * 32-bit platforms, and has few interesting properties in + * base 2. + */ + if (fid_serial == 0) + __os_id(&fid_serial); + else + fid_serial += 100000; + + for (p = + (u_int8_t *)&fid_serial, i = sizeof(u_int32_t); i > 0; --i) *fidp++ = *p++; } |