From ef3e4916ee4b26e65479c57c548a095240afb922 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:33:10 +0530 Subject: [PATCH 1/6] Update backup_logs.c --- backup_logs/src/backup_logs.c | 42 ++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/backup_logs/src/backup_logs.c b/backup_logs/src/backup_logs.c index dc608e773..b82f62fa9 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,9 @@ #include #include #include +#include +#include +#include @@ -38,6 +43,26 @@ #define BACKUP_LOGS_BUILD_DATE __DATE__ #define DEBUG_INI_NAME "/etc/debug.ini" +/* Backup-specific symlink-aware file existence check + * Unlike dcmUtilsFilePresentCheck which uses stat() and follows symlinks, + * this function uses lstat() to check the file/symlink itself regardless of target existence + */ +static int backup_filePresentCheck_symlink_aware(const char *file_name) { + if (!file_name) { + return -1; // Invalid parameter + } + + struct stat sfile; + memset(&sfile, 0, sizeof(sfile)); + + /* Use lstat() instead of stat() to check symlink itself, not its target */ + if (lstat(file_name, &sfile) != 0) { + return -1; // File/symlink doesn't exist + } + + return 0; // File/symlink exists (regardless of target validity) +} + /* Initialize backup system */ int backup_logs_init(backup_config_t *config) { RDK_LOG(RDK_LOG_DEBUG, LOG_BACKUP_LOGS, "Starting backup system initialization\n"); @@ -68,7 +93,7 @@ int backup_logs_init(backup_config_t *config) { if (rdk_logger_ext_init(&logger_config) != RDK_SUCCESS) { printf("BACKUP_LOGS : ERROR - Extended logger init failed\n"); } else { - RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "RDK Logger initialized with file output: /tmp/backup_logs.log\n"); + RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "RDK Logger initialized with file output: /opt/logs/backup_logs.log\n"); } #endif @@ -264,6 +289,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 +330,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 From d63426833823840bd04a3021e0e73ae0351f1a0b Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:33:41 +0530 Subject: [PATCH 2/6] Update backup_engine.c --- backup_logs/src/backup_engine.c | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) 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 { From 6ee21a34508edcc75c56ff4bf7f7e9c3a71c33d2 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:35:59 +0530 Subject: [PATCH 3/6] Update backup_logs.h --- backup_logs/include/backup_logs.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 From e0b542ab4d3af6849ecd0b808eef5755db60a4c2 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:51:42 +0530 Subject: [PATCH 4/6] Update backup_logs/src/backup_logs.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- backup_logs/src/backup_logs.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/backup_logs/src/backup_logs.c b/backup_logs/src/backup_logs.c index b82f62fa9..6398ba142 100644 --- a/backup_logs/src/backup_logs.c +++ b/backup_logs/src/backup_logs.c @@ -43,26 +43,6 @@ #define BACKUP_LOGS_BUILD_DATE __DATE__ #define DEBUG_INI_NAME "/etc/debug.ini" -/* Backup-specific symlink-aware file existence check - * Unlike dcmUtilsFilePresentCheck which uses stat() and follows symlinks, - * this function uses lstat() to check the file/symlink itself regardless of target existence - */ -static int backup_filePresentCheck_symlink_aware(const char *file_name) { - if (!file_name) { - return -1; // Invalid parameter - } - - struct stat sfile; - memset(&sfile, 0, sizeof(sfile)); - - /* Use lstat() instead of stat() to check symlink itself, not its target */ - if (lstat(file_name, &sfile) != 0) { - return -1; // File/symlink doesn't exist - } - - return 0; // File/symlink exists (regardless of target validity) -} - /* Initialize backup system */ int backup_logs_init(backup_config_t *config) { RDK_LOG(RDK_LOG_DEBUG, LOG_BACKUP_LOGS, "Starting backup system initialization\n"); From 9bb9f606564d754f877e081357b1ea6ce8ddd736 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:52:16 +0530 Subject: [PATCH 5/6] Update backup_logs/src/backup_logs.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- backup_logs/src/backup_logs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup_logs/src/backup_logs.c b/backup_logs/src/backup_logs.c index 6398ba142..a4befd06c 100644 --- a/backup_logs/src/backup_logs.c +++ b/backup_logs/src/backup_logs.c @@ -73,7 +73,7 @@ int backup_logs_init(backup_config_t *config) { if (rdk_logger_ext_init(&logger_config) != RDK_SUCCESS) { printf("BACKUP_LOGS : ERROR - Extended logger init failed\n"); } else { - RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "RDK Logger initialized with file output: /opt/logs/backup_logs.log\n"); + RDK_LOG(RDK_LOG_INFO, LOG_BACKUP_LOGS, "RDK Logger initialized with file output: /tmp/backup_logs.log\n"); } #endif From 1d910c2452628ca618ba8529df46ed83cbf989b1 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:52:38 +0530 Subject: [PATCH 6/6] Update backup_logs/src/backup_logs.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- backup_logs/src/backup_logs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/backup_logs/src/backup_logs.c b/backup_logs/src/backup_logs.c index a4befd06c..ffd0764cd 100644 --- a/backup_logs/src/backup_logs.c +++ b/backup_logs/src/backup_logs.c @@ -25,7 +25,6 @@ #include #include #include -#include #include