From: Jonathan McDowell Date: Tue, 22 Jul 2014 11:42:35 +0000 (+0100) Subject: Bail out if we can't change to the DB directory for the FS backend X-Git-Tag: onak-0.4.3~12 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=c398930c97141725346ed50e403490c6830feac4;p=onak.git Bail out if we can't change to the DB directory for the FS backend --- diff --git a/keydb_fs.c b/keydb_fs.c index 26eb99e..2779297 100644 --- a/keydb_fs.c +++ b/keydb_fs.c @@ -648,7 +648,15 @@ struct onak_dbctx *keydb_fs_init(bool readonly) mkdir(config.db_dir, 0777); privctx->lockfile_fd = open(buffer, O_RDWR | O_CREAT, 0600); } - chdir(config.db_dir); + if (chdir(config.db_dir) == -1) { + /* Shouldn't happen after the above */ + logthing(LOGTHING_CRITICAL, + "Couldn't change to database directory: %s", + strerror(errno)); + free(dbctx->priv); + free(dbctx); + return NULL; + } privctx->lockfile_fd = open(buffer, (privctx->lockfile_readonly) ? O_RDONLY : O_RDWR);