]> the.earth.li Git - onak.git/blobdiff - keydb_db4.c
Use common function for command sending in keyd client code
[onak.git] / keydb_db4.c
index b36ce3f65dba9e18408c0b86c6e6f35c72600f6b..b2d34c5360018d1ff88dca9dd83bba92a2c0d218 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);
@@ -1697,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