summaryrefslogtreecommitdiff
path: root/source4/lib/tdb/common/open.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2008-01-16 09:26:24 +1100
committerAndrew Bartlett <abartlet@samba.org>2008-01-16 09:26:24 +1100
commite02e67ec36ecc5f5af2fcf3a7c6b0282173df8aa (patch)
tree0e615183dba95d8268b8e9bd553928581eca1ccb /source4/lib/tdb/common/open.c
parent9ff39862266f19c2a8e0243ec97ea8d7c463c3ef (diff)
parentc92a1d0752abf42a76e16e7c19229841ac35dc81 (diff)
downloadsamba-e02e67ec36ecc5f5af2fcf3a7c6b0282173df8aa.tar.gz
samba-e02e67ec36ecc5f5af2fcf3a7c6b0282173df8aa.tar.bz2
samba-e02e67ec36ecc5f5af2fcf3a7c6b0282173df8aa.zip
Merge branch 'v4-0-test' of git://git.samba.org/samba into 4-0-abartlet
(This used to be commit c4aba5ad01f5095ad7a9d0d0f1e3c6afedbbd9b7)
Diffstat (limited to 'source4/lib/tdb/common/open.c')
-rw-r--r--source4/lib/tdb/common/open.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/source4/lib/tdb/common/open.c b/source4/lib/tdb/common/open.c
index 0bd1c91a5e..6bd8fda2bf 100644
--- a/source4/lib/tdb/common/open.c
+++ b/source4/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 */
@@ -215,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",
@@ -242,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;
}