Fix store session backup

This commit is contained in:
suvendhu 2023-03-28 20:48:05 +05:30
parent 195fcb32c2
commit efbae1c8c2
4 changed files with 16 additions and 3 deletions

View file

@ -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;

View file

@ -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);
}

2
cwmp.c
View file

@ -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);

View file

@ -22,6 +22,8 @@
#define CWMP_BACKUP_SESSION "<cwmp></cwmp>"
#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__ */