From: didg Date: Fri, 7 Mar 2003 14:51:50 +0000 (+0000) Subject: cnid_add: bugfix use a cursor for atomic operation. X-Git-Tag: netatalk-2-0-alpha1~215 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aad3798598fbc9c3dca075332a976311312bb472;hp=0a0bba7c0811eeb0f68071c899599f986c01d48c;p=netatalk.git cnid_add: bugfix use a cursor for atomic operation. cnid_open: clean a little cnid_open() --- diff --git a/libatalk/cnid/cnid_add.c b/libatalk/cnid/cnid_add.c index 0a36bfd8..f044f950 100644 --- a/libatalk/cnid/cnid_add.c +++ b/libatalk/cnid/cnid_add.c @@ -1,5 +1,5 @@ /* - * $Id: cnid_add.c,v 1.33 2003-02-07 15:00:55 didg Exp $ + * $Id: cnid_add.c,v 1.34 2003-03-07 14:51:50 didg Exp $ * * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -125,89 +125,27 @@ abort: return rc; } -cnid_t cnid_add(void *CNID, const struct stat *st, - const cnid_t did, const char *name, const int len, - cnid_t hint) -{ - CNID_private *db; - DBT key, data, rootinfo_key, rootinfo_data; +/* ---------------------- */ #ifndef CNID_DB_CDB +static cnid_t get_cnid(CNID_private *db) +{ + DBT rootinfo_key, rootinfo_data; DB_TXN *tid; -#endif /* CNID_DB_CDB */ - cnid_t id; int rc; - - if (!(db = CNID) || !st || !name) { - errno = CNID_ERR_PARAM; - return CNID_INVALID; - } - - /* Do a lookup. */ - id = cnid_lookup(db, st, did, name, len); - /* ... Return id if it is valid, or if Rootinfo is read-only. */ - if (id || (db->flags & CNIDFLAG_DB_RO)) { -#ifdef DEBUG - LOG(log_info, logtype_default, "cnid_add: Looked up did %u, name %s as %u", ntohl(did), name, ntohl(id)); -#endif - return id; - } - - /* Initialize our DBT data structures. */ - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - - /* Just tickle hint, and the key will change (gotta love pointers). */ - key.data = &hint; - key.size = sizeof(hint); - - if ((data.data = make_cnid_data(st, did, name, len)) == NULL) { - LOG(log_error, logtype_default, "cnid_add: Path name is too long"); - errno = CNID_ERR_PATH; - return CNID_INVALID; - } - - data.size = CNID_HEADER_LEN + len + 1; - - /* Start off with the hint. It should be in network byte order. - * We need to make sure that somebody doesn't add in restricted - * cnid's to the database. */ - if (ntohl(hint) >= CNID_START) { - /* If the key doesn't exist, add it in. Don't fiddle with nextID. */ - rc = add_cnid(db, &key, &data); - switch (rc) { - case DB_KEYEXIST: /* Need to use RootInfo after all. */ - break; - default: - LOG(log_error, logtype_default, "cnid_add: Unable to add CNID %u: %s", ntohl(hint), db_strerror(rc)); - errno = CNID_ERR_DB; - return CNID_INVALID; - case 0: -#ifdef DEBUG - LOG(log_info, logtype_default, "cnid_add: Used hint for did %u, name %s as %u", ntohl(did), name, ntohl(hint)); -#endif - return hint; - } - } + int flag; + cnid_t hint,id; memset(&rootinfo_key, 0, sizeof(rootinfo_key)); memset(&rootinfo_data, 0, sizeof(rootinfo_data)); rootinfo_key.data = ROOTINFO_KEY; rootinfo_key.size = ROOTINFO_KEYLEN; -#ifndef CNID_DB_CDB retry: if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) { LOG(log_error, logtype_default, "cnid_add: Failed to begin transaction: %s", db_strerror(rc)); errno = CNID_ERR_DB; return CNID_INVALID; } -#endif /* CNID_DB_CDB */ - - /* Get the key. */ -#ifdef CNID_DB_CDB - switch (rc = db->db_didname->get(db->db_didname, NULL, &rootinfo_key, - &rootinfo_data, 0)) { -#else /* CNID_DB_CDB */ switch (rc = db->db_didname->get(db->db_didname, tid, &rootinfo_key, &rootinfo_data, DB_RMW)) { case DB_LOCK_DEADLOCK: @@ -217,16 +155,13 @@ retry: return CNID_INVALID; } goto retry; -#endif /* CNID_DB_CDB */ case 0: memcpy(&hint, rootinfo_data.data, sizeof(hint)); id = ntohl(hint); /* If we've hit the max CNID allowed, we return a fatal error. CNID * needs to be recycled before proceding. */ if (++id == CNID_INVALID) { -#ifndef CNID_DB_CDB txn_abort(tid); -#endif /* CNID_DB_CDB */ LOG(log_error, logtype_default, "cnid_add: FATAL: Cannot add CNID for %s. CNID database has reached its limit.", name); errno = CNID_ERR_MAX; return CNID_INVALID; @@ -251,7 +186,6 @@ retry: rootinfo_data.size = sizeof(hint); switch (rc = db->db_didname->put(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) { -#ifndef CNID_DB_CDB case DB_LOCK_DEADLOCK: if ((rc = txn_abort(tid)) != 0) { LOG(log_error, logtype_default, "cnid_add: txn_abort: %s", db_strerror(rc)); @@ -259,22 +193,165 @@ retry: return CNID_INVALID; } goto retry; -#endif /* CNID_DB_CDB */ case 0: -#ifndef CNID_DB_CDB /* The transaction finished, commit it. */ if ((rc = txn_commit(tid, 0)) != 0) { LOG(log_error, logtype_default, "cnid_add: Unable to commit transaction: %s", db_strerror(rc)); errno = CNID_ERR_DB; return CNID_INVALID; } -#endif /* CNID_DB_CDB */ break; default: LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s", db_strerror(rc)); goto cleanup_abort; } + return hint; + +cleanup_abort: + txn_abort(tid); + errno = CNID_ERR_DB; + return CNID_INVALID; +} +#else +static cnid_t get_cnid(CNID_private *db) +{ + DBT rootinfo_key, rootinfo_data; + DBC *cursor; + int rc; + int flag; + cnid_t hint,id; + + if ((rc = db->db_didname->cursor(db->db_didname, NULL, &cursor, DB_WRITECURSOR) ) != 0) { + LOG(log_error, logtype_default, "get_cnid: Unable to get a cursor: %s", db_strerror(rc)); + return CNID_INVALID; + } + + memset(&rootinfo_key, 0, sizeof(rootinfo_key)); + memset(&rootinfo_data, 0, sizeof(rootinfo_data)); + rootinfo_key.data = ROOTINFO_KEY; + rootinfo_key.size = ROOTINFO_KEYLEN; + switch (rc = cursor->c_get(cursor, &rootinfo_key, &rootinfo_data, DB_SET)) { + case 0: + memcpy(&hint, rootinfo_data.data, sizeof(hint)); + id = ntohl(hint); + /* If we've hit the max CNID allowed, we return a fatal error. CNID + * needs to be recycled before proceding. */ + if (++id == CNID_INVALID) { + LOG(log_error, logtype_default, "cnid_add: FATAL: CNID database has reached its limit."); + errno = CNID_ERR_MAX; + goto cleanup; + } + hint = htonl(id); + flag = DB_CURRENT; + break; + case DB_NOTFOUND: + hint = htonl(CNID_START); + flag = DB_KEYFIRST; + break; + default: + LOG(log_error, logtype_default, "cnid_add: Unable to lookup rootinfo: %s", db_strerror(rc)); + errno = CNID_ERR_DB; + goto cleanup; + } + + memset(&rootinfo_key, 0, sizeof(rootinfo_key)); + memset(&rootinfo_data, 0, sizeof(rootinfo_data)); + rootinfo_data.data = &hint; + rootinfo_data.size = sizeof(hint); + rootinfo_key.data = ROOTINFO_KEY; + rootinfo_key.size = ROOTINFO_KEYLEN; + + switch (rc = cursor->c_put(cursor, &rootinfo_key, &rootinfo_data, flag)) { + case 0: + break; + default: + LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s", db_strerror(rc)); + errno = CNID_ERR_DB; + goto cleanup; + } + if ((rc = cursor->c_close(cursor)) != 0) { + LOG(log_error, logtype_default, "get_cnid: Unable to close cursor: %s", db_strerror(rc)); + errno = CNID_ERR_DB; + return CNID_INVALID; + } + return hint; +cleanup: + if ((rc = cursor->c_close(cursor)) != 0) { + LOG(log_error, logtype_default, "get_cnid: Unable to close cursor: %s", db_strerror(rc)); + return CNID_INVALID; + } + return CNID_INVALID; +} +#endif /* CNID_DB_CDB */ + +/* ------------------------ */ +cnid_t cnid_add(void *CNID, const struct stat *st, + const cnid_t did, const char *name, const int len, + cnid_t hint) +{ + CNID_private *db; + DBT key, data; + cnid_t id; + int rc; + + if (!(db = CNID) || !st || !name) { + errno = CNID_ERR_PARAM; + return CNID_INVALID; + } + + /* Do a lookup. */ + id = cnid_lookup(db, st, did, name, len); + /* ... Return id if it is valid, or if Rootinfo is read-only. */ + if (id || (db->flags & CNIDFLAG_DB_RO)) { +#ifdef DEBUG + LOG(log_info, logtype_default, "cnid_add: Looked up did %u, name %s as %u", ntohl(did), name, ntohl(id)); +#endif + return id; + } + + /* Initialize our DBT data structures. */ + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + + /* Just tickle hint, and the key will change (gotta love pointers). */ + key.data = &hint; + key.size = sizeof(hint); + + if ((data.data = make_cnid_data(st, did, name, len)) == NULL) { + LOG(log_error, logtype_default, "cnid_add: Path name is too long"); + errno = CNID_ERR_PATH; + return CNID_INVALID; + } + + data.size = CNID_HEADER_LEN + len + 1; + + /* Start off with the hint. It should be in network byte order. + * We need to make sure that somebody doesn't add in restricted + * cnid's to the database. */ + if (ntohl(hint) >= CNID_START) { + /* If the key doesn't exist, add it in. Don't fiddle with nextID. */ + rc = add_cnid(db, &key, &data); + switch (rc) { + case DB_KEYEXIST: /* Need to use RootInfo after all. */ + break; + default: + LOG(log_error, logtype_default, "cnid_add: Unable to add CNID %u: %s", ntohl(hint), db_strerror(rc)); + errno = CNID_ERR_DB; + return CNID_INVALID; + case 0: +#ifdef DEBUG + LOG(log_info, logtype_default, "cnid_add: Used hint for did %u, name %s as %u", ntohl(did), name, ntohl(hint)); +#endif + return hint; + } + } + hint = get_cnid(db); + if (hint == 0) { + errno = CNID_ERR_DB; + return CNID_INVALID; + } + /* Now we need to add the CNID data to the databases. */ rc = add_cnid(db, &key, &data); if (rc) { @@ -288,14 +365,6 @@ retry: #endif return hint; - -cleanup_abort: -#ifndef CNID_DB_CDB - txn_abort(tid); -#endif /* CNID_DB_CDB */ - - errno = CNID_ERR_DB; - return CNID_INVALID; } #endif /* CNID_DB */ diff --git a/libatalk/cnid/cnid_open.c b/libatalk/cnid/cnid_open.c index 0f8e9244..43a92a23 100644 --- a/libatalk/cnid/cnid_open.c +++ b/libatalk/cnid/cnid_open.c @@ -1,5 +1,5 @@ /* - * $Id: cnid_open.c,v 1.50 2003-01-29 20:31:45 jmarcus Exp $ + * $Id: cnid_open.c,v 1.51 2003-03-07 14:51:51 didg Exp $ * * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -117,6 +117,31 @@ DB_INIT_LOG | DB_INIT_TXN) #define MAXITER 0xFFFF /* maximum number of simultaneously open CNID * databases. */ +/* ----------------------- + * bandaid for LanTest performance pb. for now not used, cf. ifdef 0 below +*/ +static int my_yield(void) +{ + struct timeval t; + int ret; + + t.tv_sec = 0; + t.tv_usec = 1000; + ret = select(0, NULL, NULL, NULL, &t); + return 0; +} + +/* --------------- */ +static int my_open(DB *p, const char *f, const char *d, DBTYPE t, u_int32_t flags, int mode) +{ +#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) + return p->open(p, NULL, f, d, t, flags, mode); +#else + return p->open(p, f, d, t, flags, mode); +#endif +} + +/* --------------- */ /* the first compare that's always done. */ static __inline__ int compare_did(const DBT *a, const DBT *b) { @@ -328,13 +353,7 @@ char path[MAXPATHLEN + 1]; } /*db->db_didname->set_bt_compare(db->db_didname, &compare_unix);*/ -#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - if ((rc = db->db_didname->open(db->db_didname, NULL, DBDIDNAME, NULL, - DB_HASH, open_flag, 0666 & ~mask))) { -#else - if ((rc = db->db_didname->open(db->db_didname, DBDIDNAME, NULL, - DB_HASH, open_flag, 0666 & ~mask))) { -#endif /* DB_VERSION_MAJOR >= 4 */ + if ((rc = my_open(db->db_didname, DBDIDNAME, NULL, DB_HASH, open_flag, 0666 & ~mask))) { LOG(log_error, logtype_default, "cnid_open: Failed to open did/name database: %s", db_strerror(rc)); goto fail_appinit; @@ -360,7 +379,6 @@ char path[MAXPATHLEN + 1]; DB_NOOVERWRITE))) { LOG(log_error, logtype_default, "cnid_open: Error putting new version: %s", db_strerror(ret)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } } @@ -369,7 +387,6 @@ dbversion_retry: if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: txn_begin: failed to check db version: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } @@ -379,7 +396,6 @@ dbversion_retry: case DB_LOCK_DEADLOCK: if ((ret = txn_abort(tid)) != 0) { LOG(log_error, logtype_default, "cnid_open: txn_abort: %s", db_strerror(ret)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } goto dbversion_retry; @@ -397,7 +413,6 @@ dbversion_retry: if ((ret = txn_abort(tid)) != 0) { LOG(log_error, logtype_default, "cnid_open: txn_abort: %s", db_strerror(ret)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } goto dbversion_retry; @@ -408,7 +423,6 @@ dbversion_retry: txn_abort(tid); LOG(log_error, logtype_default, "cnid_open: Error putting new version: %s", db_strerror(ret)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } } @@ -417,7 +431,6 @@ dbversion_retry: txn_abort(tid); LOG(log_error, logtype_default, "cnid_open: Failed to check db version: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } } @@ -425,7 +438,6 @@ dbversion_retry: if ((rc = txn_commit(tid, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: Failed to commit db version: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } #endif /* CNID_DB_CDB */ @@ -443,19 +455,13 @@ dbversion_retry: if ((rc = db_create(&db->db_macname, db->dbenv, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: Failed to create did/macname database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } db->db_macname->set_bt_compare(db->db_macname, &compare_mac); -#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - if ((rc = db->db_macname->open(db->db_macname, NULL, DBMACNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) { -#else - if ((rc = db->db_macname->open(db->db_macname, DBMACNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) { -#endif /* DB_VERSION_MAJOR >= 4 */ + if ((rc = my_open(db->db_macname, DBMACNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask))) { LOG(log_error, logtype_default, "cnid_open: Failed to open did/macname database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); goto fail_appinit; } @@ -463,21 +469,13 @@ dbversion_retry: if ((rc = db_create(&db->db_shortname, db->dbenv, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: Failed to create did/shortname database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); - db->db_macname->close(db->db_macname, 0); goto fail_appinit; } db->db_shortname->set_bt_compare(db->db_shortname, &compare_mac); -#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - if ((rc = db->db_shortname->open(db->db_shortname, NULL, DBSHORTNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) { -#else - if ((rc = db->db_shortname->open(db->db_shortname, DBSHORTNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) { -#endif /* DB_VERSION_MAJOR >= 4 */ + if ((rc = my_open(db->db_shortname, DBSHORTNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask))) { LOG(log_error, logtype_default, "cnid_open: Failed to open did/shortname database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); - db->db_macname->close(db->db_macname, 0); goto fail_appinit; } @@ -485,23 +483,13 @@ dbversion_retry: if ((rc = db_create(&db->db_longname, db->dbenv, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: Failed to create did/longname database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); goto fail_appinit; } db->db_longname->set_bt_compare(db->db_longname, &compare_unicode); -#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - if ((rc = db->db_longname->open(db->db_longname, NULL, DBLONGNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) { -#else - if ((rc = db->db_longname->open(db->db_longname, DBLONGNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask)) != 0) { -#endif /* DB_VERSION_MAJOR >= 4 */ + if ((rc = my_open(db->db_longname, DBLONGNAME, NULL, DB_BTREE, open_flag, 0666 & ~mask))) { LOG(log_error, logtype_default, "cnid_open: Failed to open did/longname database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); goto fail_appinit; } #endif /* EXTENDED_DB */ @@ -510,28 +498,12 @@ dbversion_retry: if ((rc = db_create(&db->db_devino, db->dbenv, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: Failed to create dev/ino database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); -#ifdef EXTENDED_DB - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); - db->db_longname->close(db->db_longname, 0); -#endif /* EXTENDED_DB */ goto fail_appinit; } -#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - if ((rc = db->db_devino->open(db->db_devino, NULL, DBDEVINO, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) { -#else - if ((rc = db->db_devino->open(db->db_devino, DBDEVINO, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) { -#endif /* DB_VERSION_MAJOR >= 4 */ + if ((rc = my_open(db->db_devino, DBDEVINO, NULL, DB_HASH, open_flag, 0666 & ~mask))) { LOG(log_error, logtype_default, "cnid_open: Failed to open devino database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); -#ifdef EXTENDED_DB - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); - db->db_longname->close(db->db_longname, 0); -#endif /* EXTENDED_DB */ goto fail_appinit; } @@ -539,31 +511,12 @@ dbversion_retry: if ((rc = db_create(&db->db_cnid, db->dbenv, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: Failed to create cnid database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); -#ifdef EXTENDED_DB - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); - db->db_longname->close(db->db_longname, 0); -#endif /* EXTENDED_DB */ - db->db_devino->close(db->db_devino, 0); goto fail_appinit; } - -#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - if ((rc = db->db_cnid->open(db->db_cnid, NULL, DBCNID, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) { -#else - if ((rc = db->db_cnid->open(db->db_cnid, DBCNID, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) { -#endif /* DB_VERSION_MAJOR >= 4 */ + if ((rc = my_open(db->db_cnid, DBCNID, NULL, DB_HASH, open_flag, 0666 & ~mask))) { LOG(log_error, logtype_default, "cnid_open: Failed to open dev/ino database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); -#ifdef EXTENDED_DB - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); - db->db_longname->close(db->db_longname, 0); -#endif /* EXTENDED_DB */ - db->db_devino->close(db->db_devino, 0); goto fail_appinit; } @@ -571,42 +524,31 @@ dbversion_retry: /* filename mangling database. Use a hash for this one. */ if ((rc = db_create(&db->db_mangle, db->dbenv, 0)) != 0) { LOG(log_error, logtype_default, "cnid_open: Failed to create mangle database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); - db->db_devino->close(db->db_devino, 0); - db->db_cnid->close(db->db_cnid, 0); -#ifdef EXTENDED_DB - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); - db->db_longname->close(db->db_longname, 0); -#endif /* EXTENDED_DB */ goto fail_appinit; } -#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - if ((rc = db->db_mangle->open(db->db_mangle, NULL, DBMANGLE, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) { -#else - if ((rc = db->db_mangle->open(db->db_mangle, DBMANGLE, NULL, DB_HASH, open_flag, 0666 & ~mask)) != 0) { -#endif /* DB_VERSION_MAJOR >= 4 */ + if ((rc = my_open(db->db_mangle, DBMANGLE, NULL, DB_HASH, open_flag, 0666 & ~mask))) { LOG(log_error, logtype_default, "cnid_open: Failed to open mangle database: %s", db_strerror(rc)); - db->db_didname->close(db->db_didname, 0); - db->db_devino->close(db->db_devino, 0); - db->db_cnid->close(db->db_cnid, 0); -#ifdef EXTENDED_DB - db->db_macname->close(db->db_macname, 0); - db->db_shortname->close(db->db_shortname, 0); - db->db_longname->close(db->db_longname, 0); -#endif /* EXTENDED_DB */ goto fail_appinit; } #endif /* FILE_MANGLING */ /* Print out the version of BDB we're linked against. */ - LOG(log_info, logtype_default, "CNID DB initialized using %s", - db_version(NULL, NULL, NULL)); - + LOG(log_info, logtype_default, "CNID DB initialized using %s", db_version(NULL, NULL, NULL)); +#if 0 + db_env_set_func_yield(my_yield); +#endif return db; fail_appinit: + if (db->db_didname) db->db_didname->close(db->db_didname, 0); + if (db->db_devino) db->db_devino->close(db->db_devino, 0); + if (db->db_cnid) db->db_cnid->close(db->db_cnid, 0); +#ifdef EXTENDED_DB + if (db->db_macname) db->db_macname->close(db->db_macname, 0); + if (db->db_shortname) db->db_shortname->close(db->db_shortname, 0); + if (db->db_longname) db->db_longname->close(db->db_longname, 0); +#endif /* EXTENDED_DB */ LOG(log_error, logtype_default, "cnid_open: Failed to setup CNID DB environment"); db->dbenv->close(db->dbenv, 0);