]> the.earth.li Git - onak.git/blobdiff - keydb_db4.c
Check return value when writing PID to DB4 upgrade lock file
[onak.git] / keydb_db4.c
index 3e4a039e1cc0058a5512ecf17a37654fdbab4335..369788ea6133c06f92d2b4567be8693f65a8984e 100644 (file)
@@ -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;
        }
 
@@ -826,7 +837,7 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
                                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 */
@@ -898,7 +909,7 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
                        DB_GET_BOTH);
 
                if (ret == 0) {
-                       ret = cursor->c_del(cursor, 0);
+                       cursor->c_del(cursor, 0);
                }
 
                /* New style mapping to fingerprint */
@@ -993,7 +1004,7 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
                                DB_GET_BOTH);
 
                        if (ret == 0) {
-                               ret = cursor->c_del(cursor, 0);
+                               cursor->c_del(cursor, 0);
                        }
 
                        /* Remove 32 bit keyid -> fingerprint mapping */
@@ -1085,7 +1096,7 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
                                DB_GET_BOTH);
 
                        if (ret == 0) {
-                               ret = cursor->c_del(cursor, 0);
+                               cursor->c_del(cursor, 0);
                        }
 
                        /* Then delete new style fingerprint mapping */
@@ -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);