diff options
Diffstat (limited to 'mgmtd/mgmt_history.c')
-rw-r--r-- | mgmtd/mgmt_history.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/mgmtd/mgmt_history.c b/mgmtd/mgmt_history.c index d406932..c97cb7f 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; @@ -261,7 +266,9 @@ failed_unlock: void mgmt_history_rollback_complete(bool success) { - vty_mgmt_resume_response(rollback_vty, success); + vty_mgmt_resume_response(rollback_vty, + success ? CMD_SUCCESS + : CMD_WARNING_CONFIG_FAILED); rollback_vty = NULL; } |