From efbae1c8c29784a5de2b5ac17a4dbb91f676112a Mon Sep 17 00:00:00 2001 From: suvendhu Date: Tue, 28 Mar 2023 20:48:05 +0530 Subject: [PATCH] Fix store session backup --- backupSession.c | 9 +++++++++ common.c | 5 ++--- cwmp.c | 2 ++ inc/backupSession.h | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/backupSession.c b/backupSession.c index acc4842..2a40a77 100644 --- a/backupSession.c +++ b/backupSession.c @@ -191,6 +191,15 @@ void bkp_session_save() pthread_mutex_unlock(&mutex_backup_session); } +void copy_bkp_files_to_etc(void) +{ + if (file_exists(CWMP_BKP_FILE) && !file_exists(CWMP_ETC_BKP_FILE)) { + pthread_mutex_lock(&mutex_backup_session); + copy_file(CWMP_BKP_FILE, CWMP_ETC_BKP_FILE); + pthread_mutex_unlock(&mutex_backup_session); + } +} + mxml_node_t *bkp_session_insert(mxml_node_t *tree, char *name, char *value) { mxml_node_t *b; diff --git a/common.c b/common.c index c234aa9..42e0fc7 100755 --- a/common.c +++ b/common.c @@ -825,7 +825,6 @@ char *string_to_hex(const unsigned char *str, size_t size) int copy_file(char *source_file, char *target_file) { - char ch; FILE *source, *target; if (source_file == NULL || target_file == NULL) { CWMP_LOG(ERROR, "source file or target file is null: %p %p", source_file, target_file); @@ -843,8 +842,8 @@ int copy_file(char *source_file, char *target_file) return -1; } - ch = fgetc(source); - while( feof(source) != EOF) { + int ch = fgetc(source); + while (ch != EOF) { fputc(ch, target); ch = fgetc(source); } diff --git a/cwmp.c b/cwmp.c index bb9d417..172ee80 100644 --- a/cwmp.c +++ b/cwmp.c @@ -422,6 +422,8 @@ int run_session_end_func(void) cwmp_upload_diagnostics(); } + copy_bkp_files_to_etc(); + if (end_session_flag & END_SESSION_REBOOT) { CWMP_LOG(INFO, "Executing Reboot: end session request"); cwmp_reboot(commandKey); diff --git a/inc/backupSession.h b/inc/backupSession.h index b4e5b60..73ebf84 100644 --- a/inc/backupSession.h +++ b/inc/backupSession.h @@ -22,6 +22,8 @@ #define CWMP_BACKUP_SESSION "" #define CWMP_BKP_FILE "/var/run/icwmpd/icwmpd_backup_session.xml" +#define CWMP_ETC_BKP_FILE "/etc/icwmpd/icwmpd_backup_session.xml" + typedef enum backup_loading { ALL, @@ -67,4 +69,5 @@ void bkp_session_delete_du_state_change_complete(struct du_state_change_complete void bkp_session_delete_schedule_download(struct download *pschedule_download); void bkp_session_insert_du_state_change_complete(struct du_state_change_complete *pdu_state_change_complete); void bkp_tree_clean(void); +void copy_bkp_files_to_etc(void); #endif /* _BACKUPSESSION_H__ */