X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb_db4.c;h=b2d34c5360018d1ff88dca9dd83bba92a2c0d218;hb=ced2e52d6466e53a9e7d1cc1d1b606e902ba592b;hp=20a12fdc31f74c25d641c87dfa1bb29527282472;hpb=d76beb26081e5363c6263b6561a9e54ffb50d216;p=onak.git diff --git a/keydb_db4.c b/keydb_db4.c index 20a12fd..b2d34c5 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -169,6 +169,7 @@ static int db4_upgradedb(struct onak_db4_dbctx *privctx) char buf[1024]; int lockfile_fd; struct stat statbuf; + ssize_t written; snprintf(buf, sizeof(buf) - 1, "%s/%s", config.db_dir, DB4_UPGRADE_FILE); @@ -184,8 +185,16 @@ static int db4_upgradedb(struct onak_db4_dbctx *privctx) } } snprintf(buf, sizeof(buf) - 1, "%d", getpid()); - write(lockfile_fd, buf, strlen(buf)); + written = write(lockfile_fd, buf, strlen(buf)); close(lockfile_fd); + if (written != strlen(buf)) { + logthing(LOGTHING_CRITICAL, "Couldn't write PID to lockfile: " + "%s", strerror(errno)); + snprintf(buf, sizeof(buf) - 1, "%s/%s", config.db_dir, + DB4_UPGRADE_FILE); + unlink(buf); + return -1; + } logthing(LOGTHING_NOTICE, "Upgrading DB4 database"); ret = db_env_create(&privctx->dbenv, 0); @@ -772,7 +781,9 @@ static int db4_delete_key(struct onak_dbctx *dbctx, } if (db4_fetch_key_id(dbctx, keyid, &publickey, true) == 0) { - db4_endtrans(dbctx); + if (!intrans) { + db4_endtrans(dbctx); + } return 1; } @@ -1124,6 +1135,16 @@ static int db4_delete_key(struct onak_dbctx *dbctx, publickey = NULL; if (!deadlock) { + key.data = fingerprint.fp; + key.size = fingerprint.length; + + keydb_fp(privctx, &fingerprint)->del(keydb_fp(privctx, + &fingerprint), + privctx->txn, + &key, + 0); /* flags */ + + /* Delete old style 64 bit keyid */ key.data = &keyid; key.size = sizeof(keyid); @@ -1685,12 +1706,14 @@ struct onak_dbctx *keydb_db4_init(bool readonly) * Up the number of locks we're allowed at once. We base this on * the maximum number of keys we're going to return. */ - maxlocks = config.maxkeys * 16; - if (maxlocks < 1000) { - maxlocks = 1000; + if (ret == 0) { + maxlocks = config.maxkeys * 16; + if (maxlocks < 1000) { + maxlocks = 1000; + } + privctx->dbenv->set_lk_max_locks(privctx->dbenv, maxlocks); + privctx->dbenv->set_lk_max_objects(privctx->dbenv, maxlocks); } - privctx->dbenv->set_lk_max_locks(privctx->dbenv, maxlocks); - privctx->dbenv->set_lk_max_objects(privctx->dbenv, maxlocks); /* * Enable deadlock detection so that we don't block indefinitely on