From b2f2bc60555e2d953069c40d8d3cdecfcec9ac29 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Sun, 5 Jan 2014 17:50:55 +0000 Subject: [PATCH] Check return value when writing PID to DB4 upgrade lock file When writing our PID to the lock file for upgrading the DB4 version we didn't check it was actually successful. This doesn't matter in general (because it's the existence or not of the file we care about) but catch it and error out appropriate anyway. --- keydb_db4.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/keydb_db4.c b/keydb_db4.c index b36ce3f..369788e 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); -- 2.39.2