summaryrefslogtreecommitdiff
path: root/source3/lib/tdb/common/open.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2008-01-11 15:08:37 -0800
committerJeremy Allison <jra@samba.org>2008-01-11 15:08:37 -0800
commit2ec41571a3efbea254cc3e132280a194c86a2f89 (patch)
treecc324e5f6cabfb4e017dfe021afd95cdd2738995 /source3/lib/tdb/common/open.c
parent9cd74303478ac15b4357fb7f76d9576fe9a060a1 (diff)
downloadsamba-2ec41571a3efbea254cc3e132280a194c86a2f89.tar.gz
samba-2ec41571a3efbea254cc3e132280a194c86a2f89.tar.bz2
samba-2ec41571a3efbea254cc3e132280a194c86a2f89.zip
Sync tdb with the tdb changes in ctdb. Spoke to tridge about
this. Fixes insidious problem with order n^2 freelist merging. Jeremy. (This used to be commit c6609c042b128e7d63eb64cfdfb0f6b65cb59d76)
Diffstat (limited to 'source3/lib/tdb/common/open.c')
-rw-r--r--source3/lib/tdb/common/open.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/source3/lib/tdb/common/open.c b/source3/lib/tdb/common/open.c
index 6efa482ac2..6bd8fda2bf 100644
--- a/source3/lib/tdb/common/open.c
+++ b/source3/lib/tdb/common/open.c
@@ -35,7 +35,7 @@ static struct tdb_context *tdbs = NULL;
static unsigned int default_tdb_hash(TDB_DATA *key)
{
uint32_t value; /* Used to compute the hash value. */
- uint32_t i; /* Used to cycle through random values. */
+ uint32_t i; /* Used to cycle through random values. */
/* Set the initial value from the key size. */
for (value = 0x238F13AF * key->dsize, i=0; i < key->dsize; i++)
@@ -90,7 +90,7 @@ static int tdb_new_database(struct tdb_context *tdb, int hash_size)
size -= written;
written = write(tdb->fd, newdb+written, size);
if (written == size) {
- ret = 0;
+ ret = 0;
} else if (written >= 0) {
/* a second incomplete write - we give up.
* guessing the errno... */
@@ -152,6 +152,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
int rev = 0, locked = 0;
unsigned char *vp;
uint32_t vertest;
+ unsigned v;
if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) {
/* Can't log this */
@@ -178,7 +179,9 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
tdb->page_size = 0x2000;
}
- tdb->max_dead_records = (open_flags & TDB_VOLATILE) ? 5 : 0;
+ if (open_flags & TDB_VOLATILE) {
+ tdb->max_dead_records = 5;
+ }
if ((open_flags & O_ACCMODE) == O_WRONLY) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't open tdb %s write-only\n",
@@ -213,6 +216,10 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
goto fail; /* errno set by open(2) */
}
+ /* on exec, don't inherit the fd */
+ v = fcntl(tdb->fd, F_GETFD, 0);
+ fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC);
+
/* ensure there is only one process initialising at once */
if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_WRLCK, F_SETLKW, 0, 1) == -1) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to get global lock on %s: %s\n",
@@ -240,7 +247,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
/* its not a valid database - possibly initialise it */
if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) {
if (errno == 0) {
- errno = EIO; /* ie bad format or something */
+ errno = EIO; /* ie bad format or something */
}
goto fail;
}
@@ -281,6 +288,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
tdb->map_size = st.st_size;
tdb->device = st.st_dev;
tdb->inode = st.st_ino;
+ tdb->max_dead_records = 0;
tdb_mmap(tdb);
if (locked) {
if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) {