X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Fopen.c;h=ed32cf327f0dd8a21fe86a39ae380c5d5f0a6c99;hp=8b9776864a6729a5a85bcfe470c73c709db45364;hb=c92d0d635e1dcbb1d7b6f3356d4ac01e6f1d2535;hpb=b2c0ebc6f53b05b222937991f100f8a89701f9b1 diff --git a/ccan/tdb/open.c b/ccan/tdb/open.c index 8b977686..ed32cf32 100644 --- a/ccan/tdb/open.c +++ b/ccan/tdb/open.c @@ -164,6 +164,9 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, tdb_io_init(tdb); tdb->fd = -1; +#ifdef TDB_TRACE + tdb->tracefd = -1; +#endif tdb->name = NULL; tdb->map_ptr = NULL; tdb->flags = tdb_flags; @@ -200,6 +203,22 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, tdb->flags &= ~TDB_CLEAR_IF_FIRST; } + if ((tdb->flags & TDB_ALLOW_NESTING) && + (tdb->flags & TDB_DISALLOW_NESTING)) { + tdb->ecode = TDB_ERR_NESTING; + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: " + "allow_nesting and disallow_nesting are not allowed together!")); + errno = EINVAL; + goto fail; + } + + /* + * TDB_DISALLOW_NESTING is the default behavior. + */ + if (!(tdb->flags & TDB_ALLOW_NESTING)) { + tdb->flags |= TDB_DISALLOW_NESTING; + } + /* internal databases don't mmap or lock, and start off cleared */ if (tdb->flags & TDB_INTERNAL) { tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP); @@ -208,10 +227,6 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!")); goto fail; } -#ifdef TDB_TRACE - /* All tracing will fail. That's ok. */ - tdb->tracefd = -1; -#endif goto internal; } @@ -403,8 +418,10 @@ int tdb_close(struct tdb_context *tdb) tdb_munmap(tdb); } SAFE_FREE(tdb->name); - if (tdb->fd != -1) + if (tdb->fd != -1) { ret = close(tdb->fd); + tdb->fd = -1; + } SAFE_FREE(tdb->lockrecs); /* Remove from contexts list */