diff --git a/backup_logs/include/backup_logs.h b/backup_logs/include/backup_logs.h index da5ba3287..fb7e04792 100644 --- a/backup_logs/include/backup_logs.h +++ b/backup_logs/include/backup_logs.h @@ -1,8 +1,8 @@ /* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: + * If not stated otherwise in this file or this component's LICENSE + * file the following copyright and licenses apply: * - * Copyright 2026 RDK Management + * Copyright 2024 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 */ #ifndef BACKUP_LOGS_H diff --git a/backup_logs/src/backup_engine.c b/backup_logs/src/backup_engine.c index a7ef50a48..203a49eb8 100644 --- a/backup_logs/src/backup_engine.c +++ b/backup_logs/src/backup_engine.c @@ -44,6 +44,26 @@ /* RDK Logging component name for Backup Logs */ +/* Backup-specific symlink-aware file existence check + * This function checks if a file or symlink exists, regardless of whether the symlink target exists + * Uses lstat() instead of stat() to examine the symlink itself, not its target + */ +static int backup_file_exists_check(const char *file_name) { + if (!file_name) { + return -1; // Invalid parameter + } + + struct stat sfile; + memset(&sfile, 0, sizeof(sfile)); + + /* Use lstat() to check the file/symlink itself, not the target */ + if (lstat(file_name, &sfile) != 0) { + return -1; // File/symlink doesn't exist + } + + return 0; // File or symlink exists +} + /* Helper function to move log files matching patterns */ int move_log_files_by_pattern(const char* source_dir, const char* dest_dir) { @@ -70,8 +90,8 @@ int move_log_files_by_pattern(const char* source_dir, const char* dest_dir) { continue; } - /* Check if it's a regular file */ - if (filePresentCheck(source_file) != 0) { + /* Check if it's a file or symlink (using symlink-aware check) */ + if (backup_file_exists_check(source_file) != 0) { continue; } @@ -132,7 +152,7 @@ int backup_execute_hdd_enabled_strategy(const backup_config_t* config) { strcat(syslog_path, "/"); strcat(syslog_path, sysLog); - if (filePresentCheck(syslog_path) != 0) { + if (backup_file_exists_check(syslog_path) != 0) { RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "First time backup - moving logs to %s\n", config->prev_log_path); /* First time - move logs directly to PREV_LOG_PATH */ move_log_files_by_pattern(config->log_path, config->prev_log_path); @@ -279,17 +299,17 @@ int backup_execute_hdd_disabled_strategy(const backup_config_t* config) { strcpy(prev_log_path_slash, config->prev_log_path); strcat(prev_log_path_slash, "/"); /* HDD disabled backup rotation logic */ - if (filePresentCheck(syslog_path) != 0) { + if (backup_file_exists_check(syslog_path) != 0) { /* First time - move all logs directly */ RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "First time HDD-disabled backup - moving all logs\n"); backup_and_recover_logs(log_path_slash, prev_log_path_slash, BACKUP_OP_MOVE, "", ""); - } else if (filePresentCheck(bak1_path) != 0) { + } else if (backup_file_exists_check(bak1_path) != 0) { RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "Moving logs to bak1_ prefix\n"); backup_and_recover_logs(log_path_slash, prev_log_path_slash, BACKUP_OP_MOVE, "", "bak1_"); - } else if (filePresentCheck(bak2_path) != 0) { + } else if (backup_file_exists_check(bak2_path) != 0) { RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "Moving logs to bak2_ prefix\n"); backup_and_recover_logs(log_path_slash, prev_log_path_slash, BACKUP_OP_MOVE, "", "bak2_"); - } else if (filePresentCheck(bak3_path) != 0) { + } else if (backup_file_exists_check(bak3_path) != 0) { RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "Moving logs to bak3_ prefix\n"); backup_and_recover_logs(log_path_slash, prev_log_path_slash, BACKUP_OP_MOVE, "", "bak3_"); } else { diff --git a/backup_logs/src/backup_logs.c b/backup_logs/src/backup_logs.c index dc608e773..ffd0764cd 100644 --- a/backup_logs/src/backup_logs.c +++ b/backup_logs/src/backup_logs.c @@ -1,8 +1,8 @@ /* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: + * If not stated otherwise in this file or this component's LICENSE + * file the following copyright and licenses apply: * - * Copyright 2026 RDK Management + * Copyright 2024 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 */ #include @@ -22,6 +24,8 @@ #include #include #include +#include +#include @@ -264,6 +268,10 @@ int backup_logs_cleanup(backup_config_t *config) { /* Main entry point */ int backup_logs_main(int argc, char *argv[]) { + /* Start timing the program execution */ + struct timespec program_start, program_end; + clock_gettime(CLOCK_MONOTONIC, &program_start); + RDK_LOG(RDK_LOG_DEBUG, LOG_BACKUP_LOGS, "Starting backup_logs main function with %d arguments\n", argc); /* Suppress unused parameter warnings */ @@ -301,7 +309,10 @@ int backup_logs_main(int argc, char *argv[]) { return EXIT_FAILURE; } - RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "Backup process completed successfully\n"); + /* Calculate and log total execution time */ + clock_gettime(CLOCK_MONOTONIC, &program_end); + double total_time = (program_end.tv_sec - program_start.tv_sec) + (program_end.tv_nsec - program_start.tv_nsec) / 1000000000.0; + RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "Backup process completed successfully - Total runtime: %.3f seconds\n", total_time); return EXIT_SUCCESS; } #ifndef GTEST_ENABLE