summaryrefslogtreecommitdiff
path: root/mgmtd/mgmt_history.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2024-01-25 19:59:22 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2024-01-27 19:02:52 +0100
commitbfd6d8ee19e94f9cc945e3847f1fd275bbc01b44 (patch)
tree4124cc71210fa6892189d56cc154819e735a4e31 /mgmtd/mgmt_history.c
parent567f5702c0ec53700388383030e55fee49459389 (diff)
lib, mgmtd: fix commit history location
Both of these belong in `/var/lib`, not `/var/run`. Rather hilariously, the history read in `mgmt_history_read_cmt_record_index` was always failing, because it was doing a `file_exists(MGMTD_COMMIT_FILE_PATH)` check. Which is the wrong macro - it's `.../commit-%s.json`, including the unprocessed `%s`, which would never exist. I guess noone ever tried if this actually works. Cool. On the plus side, this means I don't have to implement legacy compatibility for this, since it never worked to begin with. (SQLite3 DB location is also changed in this commit since it also uses `DAEMON_DB_DIR`.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'mgmtd/mgmt_history.c')
-rw-r--r--mgmtd/mgmt_history.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/mgmtd/mgmt_history.c b/mgmtd/mgmt_history.c
index ddc5a1844e..c97cb7f0fd 100644
--- a/mgmtd/mgmt_history.c
+++ b/mgmtd/mgmt_history.c
@@ -63,7 +63,7 @@ static struct mgmt_cmt_info_t *mgmt_history_new_cmt_info(void)
mgmt_time_to_string(&tv, true, new->time_str, sizeof(new->time_str));
mgmt_time_to_string(&tv, false, new->cmtid_str, sizeof(new->cmtid_str));
snprintf(new->cmt_json_file, sizeof(new->cmt_json_file),
- MGMTD_COMMIT_FILE_PATH, new->cmtid_str);
+ MGMTD_COMMIT_FILE_PATH(new->cmtid_str));
return new;
}
@@ -104,18 +104,21 @@ mgmt_history_find_cmt_record(const char *cmtid_str)
static bool mgmt_history_read_cmt_record_index(void)
{
+ char index_path[MAXPATHLEN];
FILE *fp;
struct mgmt_cmt_info_t cmt_info;
struct mgmt_cmt_info_t *new;
int cnt = 0;
- if (!file_exists(MGMTD_COMMIT_FILE_PATH))
- return false;
+ snprintf(index_path, sizeof(index_path), MGMTD_COMMIT_INDEX_FILE_PATH);
- fp = fopen(MGMTD_COMMIT_INDEX_FILE_NAME, "rb");
+ fp = fopen(index_path, "rb");
if (!fp) {
- zlog_err("Failed to open commit history %s for reading: %s",
- MGMTD_COMMIT_INDEX_FILE_NAME, safe_strerror(errno));
+ if (errno == ENOENT || errno == ENOTDIR)
+ return false;
+
+ zlog_err("Failed to open commit history %pSQq for reading: %m",
+ index_path);
return false;
}
@@ -132,9 +135,8 @@ static bool mgmt_history_read_cmt_record_index(void)
memcpy(new, &cmt_info, sizeof(struct mgmt_cmt_info_t));
mgmt_cmt_infos_add_tail(&mm->cmts, new);
} else {
- zlog_warn(
- "More records found in commit history file %s than expected",
- MGMTD_COMMIT_INDEX_FILE_NAME);
+ zlog_warn("More records found in commit history file %pSQq than expected",
+ index_path);
fclose(fp);
return false;
}
@@ -148,16 +150,19 @@ static bool mgmt_history_read_cmt_record_index(void)
static bool mgmt_history_dump_cmt_record_index(void)
{
+ char index_path[MAXPATHLEN];
FILE *fp;
int ret = 0;
struct mgmt_cmt_info_t *cmt_info;
struct mgmt_cmt_info_t cmt_info_set[10];
int cnt = 0;
- fp = fopen(MGMTD_COMMIT_INDEX_FILE_NAME, "wb");
+ snprintf(index_path, sizeof(index_path), MGMTD_COMMIT_INDEX_FILE_PATH);
+
+ fp = fopen(index_path, "wb");
if (!fp) {
- zlog_err("Failed to open commit history %s for writing: %s",
- MGMTD_COMMIT_INDEX_FILE_NAME, safe_strerror(errno));
+ zlog_err("Failed to open commit history %pSQq for writing: %m",
+ index_path);
return false;
}
@@ -176,7 +181,7 @@ static bool mgmt_history_dump_cmt_record_index(void)
fclose(fp);
if (ret != cnt) {
zlog_err("Failed to write full commit history, removing file");
- remove_file(MGMTD_COMMIT_INDEX_FILE_NAME);
+ remove_file(index_path);
return false;
}
return true;