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.
char buf[1024];
int lockfile_fd;
struct stat statbuf;
char buf[1024];
int lockfile_fd;
struct stat statbuf;
snprintf(buf, sizeof(buf) - 1, "%s/%s", config.db_dir,
DB4_UPGRADE_FILE);
snprintf(buf, sizeof(buf) - 1, "%s/%s", config.db_dir,
DB4_UPGRADE_FILE);
}
}
snprintf(buf, sizeof(buf) - 1, "%d", getpid());
}
}
snprintf(buf, sizeof(buf) - 1, "%d", getpid());
- write(lockfile_fd, buf, strlen(buf));
+ written = write(lockfile_fd, buf, strlen(buf));
+ 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);
logthing(LOGTHING_NOTICE, "Upgrading DB4 database");
ret = db_env_create(&privctx->dbenv, 0);