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);
}
}
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);
}
if (db4_fetch_key_id(dbctx, keyid, &publickey, true) == 0) {
- db4_endtrans(dbctx);
+ if (!intrans) {
+ db4_endtrans(dbctx);
+ }
return 1;
}
DB_GET_BOTH);
if (ret == 0) {
- ret = cursor->c_del(cursor, 0);
+ cursor->c_del(cursor, 0);
}
/* New style just uses the fingerprint as the data */
DB_GET_BOTH);
if (ret == 0) {
- ret = cursor->c_del(cursor, 0);
+ cursor->c_del(cursor, 0);
}
/* New style mapping to fingerprint */
DB_GET_BOTH);
if (ret == 0) {
- ret = cursor->c_del(cursor, 0);
+ cursor->c_del(cursor, 0);
}
/* Remove 32 bit keyid -> fingerprint mapping */
DB_GET_BOTH);
if (ret == 0) {
- ret = cursor->c_del(cursor, 0);
+ cursor->c_del(cursor, 0);
}
/* Then delete new style fingerprint mapping */
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);