/*
- * $Id: cnid_add.c,v 1.6 2001-08-31 14:58:48 rufustfirefly Exp $
+ * $Id: cnid_add.c,v 1.7 2001-09-04 13:49:54 rufustfirefly Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
{
DBT altkey, altdata;
DB_TXN *tid;
+ /* We create rc here because using rc is bad. Why? Well, if you
+ * use rc once, then call another function which resets it, you're
+ * screwed. */
+ int rc = 0;
memset(&altkey, 0, sizeof(altkey));
memset(&altdata, 0, sizeof(altdata));
retry:
- if ((errno = txn_begin(db->dbenv, ptid, &tid,0))) {
- return errno;
+ if ((rc = txn_begin(db->dbenv, ptid, &tid,0))) {
+ return rc;
}
/* main database */
- if ((errno = db->db_cnid->put(db->db_cnid, tid,
+ if ((rc = db->db_cnid->put(db->db_cnid, tid,
key, data, DB_NOOVERWRITE))) {
txn_abort(tid);
- if (errno == DB_LOCK_DEADLOCK)
+ if (rc == DB_LOCK_DEADLOCK)
goto retry;
- return errno;
+ return rc;
}
/* dev/ino database */
altkey.size = CNID_DEVINO_LEN;
altdata.data = key->data;
altdata.size = key->size;
- if ((errno = db->db_devino->put(db->db_devino, tid,
+ if ((rc = db->db_devino->put(db->db_devino, tid,
&altkey, &altdata, 0))) {
txn_abort(tid);
- if (errno == DB_LOCK_DEADLOCK)
+ if (rc == DB_LOCK_DEADLOCK)
goto retry;
- return errno;
+ return rc;
}
/* did/name database */
altkey.data = (char *) data->data + CNID_DEVINO_LEN;
altkey.size = data->size - CNID_DEVINO_LEN;
- if ((errno = db->db_didname->put(db->db_didname, tid,
+ if ((rc = db->db_didname->put(db->db_didname, tid,
&altkey, &altdata, 0))) {
txn_abort(tid);
- if (errno == DB_LOCK_DEADLOCK)
+ if (rc == DB_LOCK_DEADLOCK)
goto retry;
- return errno;
+ return rc;
}
return txn_commit(tid, 0);
DBT rootinfo_key, rootinfo_data;
DB_TXN *tid;
cnid_t id, save;
+ int rc = 0;
int debug = 0;
* cnid's to the database. */
if (ntohl(hint) >= CNID_START) {
/* if the key doesn't exist, add it in. don't fiddle with nextID. */
- errno = add_cnid(db, NULL, &key, &data);
- switch (errno) {
+ rc = add_cnid(db, NULL, &key, &data);
+ switch (rc) {
case DB_KEYEXIST: /* need to use RootInfo after all. */
break;
default:
/* Abort and retry the modification. */
if (0) {
-retry: if ((errno = txn_abort(tid)) != 0)
- syslog(LOG_ERR, "cnid_add: txn_begin failed (%d)", errno);
+retry: if ((rc = txn_abort(tid)) != 0)
+ syslog(LOG_ERR, "cnid_add: txn_begin failed (%d)", rc);
/* FALLTHROUGH */
}
/* Begin the transaction. */
- if ((errno = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
- syslog(LOG_ERR, "cnid_add: txn_begin failed (%d)", errno);
+ if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
+ syslog(LOG_ERR, "cnid_add: txn_begin failed (%d)", rc);
goto cleanup_err;
}
rootinfo_key.size = ROOTINFO_KEYLEN;
/* Get the key. */
- switch (errno = db->db_didname->get(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) {
+ switch (rc = db->db_didname->get(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) {
case DB_LOCK_DEADLOCK:
goto retry;
case 0:
syslog(LOG_ERR, "cnid_add: using CNID_START for did %d, name %s as %d", did, name, hint);
break;
default:
- syslog(LOG_ERR, "cnid_add: unable to lookup rootinfo (%d)", errno);
+ syslog(LOG_ERR, "cnid_add: unable to lookup rootinfo (%d)", rc);
goto cleanup_abort;
}
* wrap-around. NOTE: i do it this way so that we can go back and
* fill in holes. */
save = id = ntohl(hint);
- while ((errno = add_cnid(db, tid, &key, &data))) {
+ while ((rc = add_cnid(db, tid, &key, &data))) {
/* don't use any of the special CNIDs */
if (++id < CNID_START)
id = CNID_START;
- if ((errno != DB_KEYEXIST) || (save == id)) {
+ if ((rc != DB_KEYEXIST) || (save == id)) {
syslog(LOG_ERR, "cnid_add: unable to add CNID(%x)", hint);
hint = 0;
goto cleanup_abort;
rootinfo_data.data = &hint;
rootinfo_data.size = sizeof(hint);
- switch (errno = db->db_didname->put(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) {
+ switch (rc = db->db_didname->put(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) {
case DB_LOCK_DEADLOCK:
goto retry;
case 0:
break;
default:
- syslog(LOG_ERR, "cnid_add: unable to update rootinfo (%d)", errno);
+ syslog(LOG_ERR, "cnid_add: unable to update rootinfo (%d)", rc);
goto cleanup_abort;
}
cleanup_commit:
/* The transaction finished, commit it. */
- if ((errno = txn_commit(tid, 0)) != 0) {
- syslog(LOG_ERR, "cnid_add: txn_commit failed (%d)", errno);
+ if ((rc = txn_commit(tid, 0)) != 0) {
+ syslog(LOG_ERR, "cnid_add: txn_commit failed (%d)", rc);
goto cleanup_err;
}
/*
- * $Id: cnid_open.c,v 1.6 2001-08-31 14:58:48 rufustfirefly Exp $
+ * $Id: cnid_open.c,v 1.7 2001-09-04 13:49:54 rufustfirefly Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
#define DBVERSION DBVERSION1
#define DBOPTIONS (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
-DB_INIT_LOG | DB_INIT_TXN | DB_TXN_NOSYNC | DB_RECOVER)
+DB_INIT_LOG | DB_INIT_TXN | DB_RECOVER)
#define MAXITER 0xFFFF /* maximum number of simultaneously open CNID
* databases. */
/* sort did's and then names. this is for unix paths.
* i.e., did/unixname lookups. */
-static int compare_unix(const DBT *a, const DBT *b)
+static int compare_unix(DB* db, const DBT *a, const DBT *b)
{
u_int8_t *sa, *sb;
int len, ret;
goto fail_lock;
}
+ /* Check to see if a DBENV already exists. If it does, join it. */
+ if (db->dbenv->open(db->dbenv, path, DB_JOINENV, 0666)) {
if (db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666)) {
/* try with a shared memory pool */
open_flag = DB_RDONLY;
syslog(LOG_INFO, "cnid_open: read-only CNID database");
}
+ }
/* did/name reverse mapping. we use a btree for this one. */
if (db_create(&db->db_didname, db->dbenv, 0))