From bc499b69e868b2a2777aa908162cceb36531cb15 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Tue, 28 Jul 2026 03:21:22 +0530 Subject: [PATCH 01/35] Update uploadstblogs_types.h --- uploadstblogs/include/uploadstblogs_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/uploadstblogs/include/uploadstblogs_types.h b/uploadstblogs/include/uploadstblogs_types.h index d2ef38fd..55114ef0 100755 --- a/uploadstblogs/include/uploadstblogs_types.h +++ b/uploadstblogs/include/uploadstblogs_types.h @@ -145,6 +145,7 @@ typedef struct { TriggerType trigger_type; /**< Trigger type (TRIGGER_SCHEDULED, TRIGGER_ONDEMAND, etc.) */ bool rrd_flag; /**< RRD flag */ const char* rrd_file; /**< RRD upload log file path (optional) */ + bool uploadlogsnow_mode; /**< When true, execute UploadLogsNow workflow */ } UploadSTBLogsParams; From 7925ecdccc88a178da2b9757e998582c78dabfca Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Tue, 28 Jul 2026 03:23:18 +0530 Subject: [PATCH 02/35] Update uploadstblogs.c --- uploadstblogs/src/uploadstblogs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/uploadstblogs/src/uploadstblogs.c b/uploadstblogs/src/uploadstblogs.c index 7f29b2eb..fc1ef458 100755 --- a/uploadstblogs/src/uploadstblogs.c +++ b/uploadstblogs/src/uploadstblogs.c @@ -281,6 +281,24 @@ int uploadstblogs_run(const UploadSTBLogsParams* params) strncpy(ctx.rrd_file, params->rrd_file, sizeof(ctx.rrd_file) - 1); } + ctx.uploadlogsnow_mode = params->uploadlogsnow_mode; + + /* Handle UploadLogsNow mode */ + if (ctx.uploadlogsnow_mode) { + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, + "[%s:%d] UploadLogsNow mode detected via API, executing custom workflow\n", + __FUNCTION__, __LINE__); + + ret = execute_uploadlogsnow_workflow(&ctx); + +#ifdef T2_EVENT_ENABLED + t2_uninit(); +#endif + cleanup_iarm_connection(); + release_lock(); + return ret; + } + /* Validate system prerequisites */ if (!validate_system(&ctx)) { fprintf(stderr, "System validation failed\n"); From 0f095f6f300972e1bbab0b7d26de56c06e816816 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Tue, 28 Jul 2026 06:59:51 +0530 Subject: [PATCH 03/35] Update Makefile.am --- uploadstblogs/src/Makefile.am | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/uploadstblogs/src/Makefile.am b/uploadstblogs/src/Makefile.am index aa82bd8d..b68645bc 100755 --- a/uploadstblogs/src/Makefile.am +++ b/uploadstblogs/src/Makefile.am @@ -41,5 +41,9 @@ logupload_CFLAGS = -Wall -DEN_MAINTENANCE_MANAGER -DIARM_ENABLED -DT2_EVENT_ENAB logupload_LDADD = libuploadstblogs.la -lrdkloggers -lfwutils -lt2utils -ltelemetry_msgsender - +# Install public headers for external consumers (e.g. tr69hostif) +uploadstblogsincludedir = $(includedir)/uploadstblogs +uploadstblogsinclude_HEADERS = \ + $(top_srcdir)/uploadstblogs/include/uploadstblogs.h \ + $(top_srcdir)/uploadstblogs/include/uploadstblogs_types.h From a5591a8881e64b24bbb5e9cdcc90a7b7b2a1a27a Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Tue, 28 Jul 2026 11:11:14 +0530 Subject: [PATCH 04/35] Update uploadstblogs.h --- uploadstblogs/include/uploadstblogs.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/uploadstblogs/include/uploadstblogs.h b/uploadstblogs/include/uploadstblogs.h index 3cb16fa2..41b2b7ae 100755 --- a/uploadstblogs/include/uploadstblogs.h +++ b/uploadstblogs/include/uploadstblogs.h @@ -28,6 +28,10 @@ #ifndef UPLOADSTBLOGS_H #define UPLOADSTBLOGS_H +#ifdef __cplusplus +extern "C" { +#endif + #include "uploadstblogs_types.h" /** @@ -117,4 +121,8 @@ int uploadstblogs_execute(int argc, char** argv); */ int main(int argc, char** argv); +#ifdef __cplusplus +} +#endif + #endif /* UPLOADSTBLOGS_H */ From 5e5f820a47fbfea8fa904974c52de0b0c2e3f433 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 16:01:00 +0530 Subject: [PATCH 05/35] Update context_manager.c --- uploadstblogs/src/context_manager.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/uploadstblogs/src/context_manager.c b/uploadstblogs/src/context_manager.c index a713ed2e..1906cff3 100755 --- a/uploadstblogs/src/context_manager.c +++ b/uploadstblogs/src/context_manager.c @@ -155,13 +155,19 @@ bool is_codebig_blocked(int block_time) bool init_context(RuntimeContext* ctx) { // Initialize RDK Logger + rdk_LogOutput_File filelog; + strncpy(filelog.fileName, "dcmscript.log", sizeof(filelog.fileName)-1); + filelog.fileName[sizeof(filelog.fileName) - 1] = '\0'; + strncpy(filelog.fileLocation, "/opt/logs/", sizeof(filelog.fileLocation)-1); + filelog.fileLocation[sizeof(filelog.fileLocation) - 1] = '\0'; + /* Extended initialization with programmatic configuration */ rdk_logger_ext_config_t config = { .pModuleName = "LOG.RDK.UPLOADSTB", /* Module name */ .loglevel = RDK_LOG_INFO, /* Default log level */ - .output = RDKLOG_OUTPUT_CONSOLE, /* Output to console (stdout/stderr) */ + .output = RDKLOG_OUTPUT_FILE, .format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */ - .pFilePolicy = NULL /* Not using file output, so NULL */ + .pFilePolicy = &filelog /* using file output */ }; if (rdk_logger_ext_init(&config) != RDK_SUCCESS) { From 8d2ff1976b8f636c6b2241e76d6e3ba77175d85a Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 16:05:47 +0530 Subject: [PATCH 06/35] Update dcm_utils.c --- dcm_utils.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/dcm_utils.c b/dcm_utils.c index a48e0d18..f8e93b65 100644 --- a/dcm_utils.c +++ b/dcm_utils.c @@ -47,9 +47,31 @@ INT32 g_rdk_logger_enabled = 0; void DCMLOGInit() { #ifdef RDK_LOGGER_ENABLED - if (0 == rdk_logger_init(DEBUG_INI_NAME)) { + // Initialize RDK Logger + rdk_LogOutput_File filelog; + strncpy(filelog.fileName, "dcmscript.log", sizeof(filelog.fileName)-1); + filelog.fileName[sizeof(filelog.fileName) - 1] = '\0'; + strncpy(filelog.fileLocation, "/opt/logs/", sizeof(filelog.fileLocation)-1); + filelog.fileLocation[sizeof(filelog.fileLocation) - 1] = '\0'; + + /* Extended initialization with programmatic configuration */ + rdk_logger_ext_config_t config = { + .pModuleName = "LOG.RDK.UPLOADSTB", /* Module name */ + .loglevel = RDK_LOG_INFO, /* Default log level */ + .output = RDKLOG_OUTPUT_CONSOLE, /* Output to console (stdout/stderr) */ + .output = RDKLOG_OUTPUT_FILE, + .format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */ + .pFilePolicy = NULL /* Not using file output, so NULL */ + .pFilePolicy = &filelog /* using file output */ + }; + + if (rdk_logger_ext_init(&config) != RDK_SUCCESS) { + printf("UPLOADSTB : ERROR - Extended logger init failed\n"); + } + else { g_rdk_logger_enabled = 1; } + #endif } From 41c1e37df3c236d38c02f3c2ad82e9fba98fe764 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 16:06:46 +0530 Subject: [PATCH 07/35] Update dcm_utils.c --- dcm_utils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dcm_utils.c b/dcm_utils.c index f8e93b65..2075c529 100644 --- a/dcm_utils.c +++ b/dcm_utils.c @@ -33,6 +33,7 @@ #include #include #include +#include "rdk_logger.h" #include "dcm_types.h" #include "dcm_utils.h" From 21010cccb4d8e5843085e06d3b1275885adf61cc Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 16:15:42 +0530 Subject: [PATCH 08/35] Update dcm_utils.c --- dcm_utils.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dcm_utils.c b/dcm_utils.c index 2075c529..f2d691d0 100644 --- a/dcm_utils.c +++ b/dcm_utils.c @@ -57,13 +57,11 @@ void DCMLOGInit() /* Extended initialization with programmatic configuration */ rdk_logger_ext_config_t config = { - .pModuleName = "LOG.RDK.UPLOADSTB", /* Module name */ - .loglevel = RDK_LOG_INFO, /* Default log level */ - .output = RDKLOG_OUTPUT_CONSOLE, /* Output to console (stdout/stderr) */ + .pModuleName = "LOG.RDK.DCM", /* Module name */ + .loglevel = RDK_LOG_INFO, /* Default log level */ .output = RDKLOG_OUTPUT_FILE, - .format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */ - .pFilePolicy = NULL /* Not using file output, so NULL */ - .pFilePolicy = &filelog /* using file output */ + .format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */ + .pFilePolicy = &filelog /* using file output */ }; if (rdk_logger_ext_init(&config) != RDK_SUCCESS) { From 0ab199bab05cbb1797e7081c0128c674d681e6c3 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:03:18 +0530 Subject: [PATCH 09/35] Update strategy_handler.c --- uploadstblogs/src/strategy_handler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/uploadstblogs/src/strategy_handler.c b/uploadstblogs/src/strategy_handler.c index 9a0086a2..d394d057 100755 --- a/uploadstblogs/src/strategy_handler.c +++ b/uploadstblogs/src/strategy_handler.c @@ -23,10 +23,12 @@ */ #include +#include +#include #include "strategy_handler.h" #include "cleanup_handler.h" +#include "file_operations.h" #include "rdk_debug.h" -#include // Forward declarations of strategy handlers extern const StrategyHandler ondemand_strategy_handler; @@ -71,8 +73,10 @@ int execute_strategy_workflow(RuntimeContext* ctx, SessionState* session) return -1; } - // Remove stale .tgz archives from log path before any strategy runs. + // Pre-strategy cleanup (script lines 967-984) cleanup_old_archives(ctx->log_path); + clear_old_packet_captures(ctx->log_path); + remove_stale_timestamped_files(ctx->log_path); // Verify context has valid data RDK_LOG(RDK_LOG_DEBUG, LOG_UPLOADSTB, "[%s:%d] Context check: ctx=%p, MAC='%s', device_type='%s'\n", From e4823f3b2862da305f744e4e34fdbd8ff1fc7d9c Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:03:48 +0530 Subject: [PATCH 10/35] Update strategies.c --- uploadstblogs/src/strategies.c | 183 +++++++++++++++++++++++++++++++-- 1 file changed, 175 insertions(+), 8 deletions(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index 60e40312..7e05ca43 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -366,13 +366,167 @@ const StrategyHandler dcm_strategy_handler = { .cleanup_phase = dcm_cleanup }; +/* Copy regular files (not directories) from LOG_PATH to DCM_LOG_PATH. + * Equivalent to script copyOptLogsFiles(). */ +static int copy_opt_logs_files(const char* src_dir, const char* dest_dir) +{ + DIR* dir = opendir(src_dir); + if (!dir) { + RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, + "[%s:%d] Failed to open source dir: %s\n", __FUNCTION__, __LINE__, src_dir); + return -1; + } + + struct dirent* entry; + int count = 0; + char src_path[MAX_PATH_LENGTH]; + char dest_path[MAX_PATH_LENGTH]; + + while ((entry = readdir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + if (entry->d_type == DT_DIR) + continue; + + snprintf(src_path, sizeof(src_path), "%s/%s", src_dir, entry->d_name); + snprintf(dest_path, sizeof(dest_path), "%s/%s", dest_dir, entry->d_name); + if (copy_file(src_path, dest_path)) + count++; + } + closedir(dir); + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, + "[%s:%d] Copied %d files from %s to %s\n", + __FUNCTION__, __LINE__, count, src_dir, dest_dir); + return count; +} + +/* Recursively copy directory contents from src to dest. */ +static int copy_dir_recursive(const char* src_dir, const char* dest_dir) +{ + DIR* dir = opendir(src_dir); + if (!dir) return -1; + + struct dirent* entry; + int count = 0; + char src_path[MAX_PATH_LENGTH]; + char dest_path[MAX_PATH_LENGTH]; + + while ((entry = readdir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + + snprintf(src_path, sizeof(src_path), "%s/%s", src_dir, entry->d_name); + snprintf(dest_path, sizeof(dest_path), "%s/%s", dest_dir, entry->d_name); + + if (entry->d_type == DT_DIR) { + create_directory(dest_path); + count += copy_dir_recursive(src_path, dest_path); + } else { + if (copy_file(src_path, dest_path)) + count++; + } + } + closedir(dir); + return count; +} + +/* Copy all files/directories from LOG_PATH to DCM_LOG_PATH, excluding + * dcm, PreviousLogs, PreviousLogs_backup. + * Equivalent to script copyAllFiles(). */ +static int copy_all_files_to_dcm(const char* src_dir, const char* dest_dir) +{ + static const char* exclude[] = {"dcm", "PreviousLogs_backup", "PreviousLogs", NULL}; + + DIR* dir = opendir(src_dir); + if (!dir) { + RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, + "[%s:%d] Failed to open source dir: %s\n", __FUNCTION__, __LINE__, src_dir); + return -1; + } + + struct dirent* entry; + int count = 0; + char src_path[MAX_PATH_LENGTH]; + char dest_path[MAX_PATH_LENGTH]; + + while ((entry = readdir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + + bool skip = false; + for (int i = 0; exclude[i]; i++) { + if (strcmp(entry->d_name, exclude[i]) == 0) { + skip = true; + break; + } + } + if (skip) continue; + + snprintf(src_path, sizeof(src_path), "%s/%s", src_dir, entry->d_name); + snprintf(dest_path, sizeof(dest_path), "%s/%s", dest_dir, entry->d_name); + + if (entry->d_type == DT_DIR) { + create_directory(dest_path); + count += copy_dir_recursive(src_path, dest_path); + } else { + if (copy_file(src_path, dest_path)) + count++; + } + } + closedir(dir); + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, + "[%s:%d] Copied %d items from %s to %s (with exclusions)\n", + __FUNCTION__, __LINE__, count, src_dir, dest_dir); + return count; +} + +/* Read DCM_UPLOAD_LIST, copy listed directories to DCM_LOG_PATH, clear list. + * Equivalent to script lines 1026-1032. */ +static int process_dcm_upload_list(RuntimeContext* ctx) +{ + char list_path[MAX_PATH_LENGTH]; + snprintf(list_path, sizeof(list_path), "%s/dcm_upload", ctx->log_path); + + FILE* fp = fopen(list_path, "r"); + if (!fp) return 0; + + char line[MAX_PATH_LENGTH]; + int count = 0; + + while (fgets(line, sizeof(line), fp)) { + size_t len = strlen(line); + if (len > 0 && line[len - 1] == '\n') line[len - 1] = '\0'; + if (strlen(line) == 0) continue; + + if (dir_exists(line)) { + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, + "[%s:%d] Copying batched logs from %s\n", __FUNCTION__, __LINE__, line); + copy_dir_recursive(line, ctx->dcm_log_path); + count++; + } + } + fclose(fp); + + // Clear the upload list after processing + if (count > 0) { + fp = fopen(list_path, "w"); + if (fp) fclose(fp); + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, + "[%s:%d] Processed %d entries from DCM upload list\n", + __FUNCTION__, __LINE__, count); + } + + return count; +} + /** * @brief Setup phase for DCM strategy * - * Shell script equivalent (uploadDCMLogs lines 698-705): - * 1. Change to DCM_LOG_PATH (files already there from batching) - * 2. Check upload_flag - * 3. Add timestamps to files in DCM_LOG_PATH + * Shell script equivalent (main flow lines 1022-1041 + uploadDCMLogs lines 698-705): + * 1. Clean and recreate DCM_LOG_PATH + * 2. Populate DCM_LOG_PATH: process DCM_UPLOAD_LIST + copy log files, or copy all files + * 3. Check upload_flag + * 4. Add timestamps to files in DCM_LOG_PATH */ static int dcm_setup(RuntimeContext* ctx, SessionState* session) { @@ -385,14 +539,27 @@ static int dcm_setup(RuntimeContext* ctx, SessionState* session) RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, "[%s:%d] DCM: Starting setup phase\n", __FUNCTION__, __LINE__); - // Check if DCM_LOG_PATH exists and has files - if (!dir_exists(ctx->dcm_log_path)) { - RDK_LOG(RDK_LOG_ERROR, LOG_UPLOADSTB, - "[%s:%d] DCM_LOG_PATH does not exist: %s\n", + // Clean and recreate DCM_LOG_PATH (script lines 961-965, 1023) + if (dir_exists(ctx->dcm_log_path)) { + remove_directory(ctx->dcm_log_path); + } + if (!create_directory(ctx->dcm_log_path)) { + RDK_LOG(RDK_LOG_ERROR, LOG_UPLOADSTB, + "[%s:%d] Failed to create DCM_LOG_PATH: %s\n", __FUNCTION__, __LINE__, ctx->dcm_log_path); return -1; } + // Populate DCM_LOG_PATH with log files (script main flow lines 1022-1041) + if (ctx->upload_on_reboot == 1) { + // copyAllFiles: copy LOG_PATH/* excluding dcm, PreviousLogs, PreviousLogs_backup + copy_all_files_to_dcm(ctx->log_path, ctx->dcm_log_path); + } else { + // Process DCM_UPLOAD_LIST: copy batched directories, then copy current opt logs + process_dcm_upload_list(ctx); + copy_opt_logs_files(ctx->log_path, ctx->dcm_log_path); + } + // Check upload_flag from DCMSettings.conf (matches script behavior) if (!read_dcm_upload_flag()) { RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, From e9db4d7f97687a6a8b97925757a766ee5ebc6ddd Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:04:14 +0530 Subject: [PATCH 11/35] Update cleanup_handler.c --- uploadstblogs/src/cleanup_handler.c | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/uploadstblogs/src/cleanup_handler.c b/uploadstblogs/src/cleanup_handler.c index 25087a4d..dce8bc82 100755 --- a/uploadstblogs/src/cleanup_handler.c +++ b/uploadstblogs/src/cleanup_handler.c @@ -296,6 +296,45 @@ int cleanup_old_archives(const char *log_path) return removed_count; } +int remove_stale_timestamped_files(const char *log_path) +{ + if (!log_path) { + return -1; + } + + DIR *dir = opendir(log_path); + if (!dir) { + return -1; + } + + int removed_count = 0; + struct dirent *entry; + char filepath[512]; + + while ((entry = readdir(dir)) != NULL) { + if (entry->d_type == DT_DIR) { + continue; + } + if (!is_timestamped_backup(entry->d_name)) { + continue; + } + if (strstr(entry->d_name, "logbackup") || strstr(entry->d_name, "moca.pcap")) { + continue; + } + + snprintf(filepath, sizeof(filepath), "%s/%s", log_path, entry->d_name); + RDK_LOG(RDK_LOG_DEBUG, LOG_UPLOADSTB, + "[%s:%d] Removing stale timestamped file: %s\n", + __FUNCTION__, __LINE__, filepath); + if (remove(filepath) == 0) { + removed_count++; + } + } + + closedir(dir); + return removed_count; +} + /* ========================== Upload Finalization Functions ========================== */ From 66d14c0a50eac8e56362acad863592d21cb0301b Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:04:55 +0530 Subject: [PATCH 12/35] Update cleanup_handler.h --- uploadstblogs/include/cleanup_handler.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/uploadstblogs/include/cleanup_handler.h b/uploadstblogs/include/cleanup_handler.h index 98bdaa3f..3a321d1a 100755 --- a/uploadstblogs/include/cleanup_handler.h +++ b/uploadstblogs/include/cleanup_handler.h @@ -130,4 +130,16 @@ int cleanup_old_archives(const char *log_path); */ bool is_timestamped_backup(const char *filename); +/** + * @brief Remove stale timestamped files from log directory + * + * Removes regular files matching timestamp pattern but excludes + * logbackup directories and moca.pcap files. + * Matches script: ls $LOG_PATH/*-*-*-*-*M-* | grep -v "logbackup" | grep -v "moca.pcap" + * + * @param log_path Log directory path + * @return Number of files removed + */ +int remove_stale_timestamped_files(const char *log_path); + #endif /* CLEANUP_HANDLER_H */ From d517ef41bdfa311dfb469cb8fd6244d816f513e2 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:44:42 +0530 Subject: [PATCH 13/35] Update cleanup_handler.h --- uploadstblogs/include/cleanup_handler.h | 1 - 1 file changed, 1 deletion(-) diff --git a/uploadstblogs/include/cleanup_handler.h b/uploadstblogs/include/cleanup_handler.h index 3a321d1a..78243929 100755 --- a/uploadstblogs/include/cleanup_handler.h +++ b/uploadstblogs/include/cleanup_handler.h @@ -135,7 +135,6 @@ bool is_timestamped_backup(const char *filename); * * Removes regular files matching timestamp pattern but excludes * logbackup directories and moca.pcap files. - * Matches script: ls $LOG_PATH/*-*-*-*-*M-* | grep -v "logbackup" | grep -v "moca.pcap" * * @param log_path Log directory path * @return Number of files removed From 5f2adfc61225453c767a29736b19a46393dfa775 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:50:28 +0530 Subject: [PATCH 14/35] Update strategies.c --- uploadstblogs/src/strategies.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index 7e05ca43..b70e84e6 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -484,7 +484,7 @@ static int copy_all_files_to_dcm(const char* src_dir, const char* dest_dir) * Equivalent to script lines 1026-1032. */ static int process_dcm_upload_list(RuntimeContext* ctx) { - char list_path[MAX_PATH_LENGTH]; + char list_path[MAX_PATH_LENGTH + sizeof("/dcm_upload")]; snprintf(list_path, sizeof(list_path), "%s/dcm_upload", ctx->log_path); FILE* fp = fopen(list_path, "r"); From f47d899ed7ccbb6fc02905acd34ddc2b78a3e3f5 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 19:07:08 +0530 Subject: [PATCH 15/35] Update archive_manager.c --- uploadstblogs/src/archive_manager.c | 63 +++++++++++++++++------------ 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/uploadstblogs/src/archive_manager.c b/uploadstblogs/src/archive_manager.c index 430d71b9..1dc99e68 100755 --- a/uploadstblogs/src/archive_manager.c +++ b/uploadstblogs/src/archive_manager.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "archive_manager.h" #include "file_operations.h" @@ -478,42 +479,36 @@ static unsigned int calculate_tar_checksum(struct tar_header* header) } /** - * @brief Write TAR header for a file + * @brief Write TAR header for a file or symlink */ -static int write_tar_header(gzFile gz, const char* filename, struct stat* st) +static int write_tar_header(gzFile gz, const char* filename, struct stat* st, const char* link_target) { struct tar_header header; memset(&header, 0, sizeof(header)); - // Filename (strip leading path for archive) strncpy(header.name, filename, sizeof(header.name) - 1); - - // File mode snprintf(header.mode, sizeof(header.mode), "%07o", (unsigned int)st->st_mode & 0777); - - // UID and GID snprintf(header.uid, sizeof(header.uid), "%07o", 0); snprintf(header.gid, sizeof(header.gid), "%07o", 0); - - // File size - snprintf(header.size, sizeof(header.size), "%011lo", (unsigned long)st->st_size); - - // Modification time snprintf(header.mtime, sizeof(header.mtime), "%011lo", (unsigned long)st->st_mtime); - - // Type flag (regular file) - header.typeflag = '0'; - - // Magic and version (ustar) memcpy(header.magic, "ustar", 5); header.magic[5] = '\0'; memcpy(header.version, "00", 2); + + if (S_ISLNK(st->st_mode)) { + header.typeflag = '2'; + snprintf(header.size, sizeof(header.size), "%011o", 0); + if (link_target) { + strncpy(header.linkname, link_target, sizeof(header.linkname) - 1); + } + } else { + header.typeflag = '0'; + snprintf(header.size, sizeof(header.size), "%011lo", (unsigned long)st->st_size); + } - // Calculate and write checksum unsigned int checksum = calculate_tar_checksum(&header); snprintf(header.checksum, sizeof(header.checksum), "%06o", checksum); - // Write header to gzip file if (gzwrite(gz, &header, sizeof(header)) != sizeof(header)) { return -1; } @@ -528,10 +523,9 @@ static int add_file_to_tar(gzFile gz, const char* filepath, const char* arcname) { struct stat st; - // Open file first with O_NOFOLLOW to prevent symlink attacks (TOCTOU fix) int fd = open(filepath, O_RDONLY | O_NOFOLLOW); if (fd < 0) { - if (errno != ELOOP) { // ELOOP = symlink detected + if (errno != ELOOP) { RDK_LOG(RDK_LOG_ERROR, LOG_UPLOADSTB, "[%s:%d] Failed to open file: %s (errno=%d)\n", __FUNCTION__, __LINE__, filepath, errno); @@ -554,7 +548,7 @@ static int add_file_to_tar(gzFile gz, const char* filepath, const char* arcname) } // Write TAR header - if (write_tar_header(gz, arcname, &st) != 0) { + if (write_tar_header(gz, arcname, &st, NULL) != 0) { RDK_LOG(RDK_LOG_ERROR, LOG_UPLOADSTB, "[%s:%d] Failed to write TAR header\n", __FUNCTION__, __LINE__); close(fd); @@ -601,8 +595,14 @@ static int add_file_to_tar(gzFile gz, const char* filepath, const char* arcname) */ static int add_directory_to_tar(gzFile gz, const char* dirpath, const char* base_path, const char* exclude_file) { - DIR* dir = opendir(dirpath); + int dirfd = open(dirpath, O_RDONLY | O_DIRECTORY); + if (dirfd < 0) { + return -1; + } + + DIR* dir = fdopendir(dirfd); if (!dir) { + close(dirfd); return -1; } @@ -623,7 +623,7 @@ static int add_directory_to_tar(gzFile gz, const char* dirpath, const char* base } struct stat st; - if (stat(fullpath, &st) != 0) { + if (fstatat(dirfd, entry->d_name, &st, AT_SYMLINK_NOFOLLOW) != 0) { continue; } @@ -634,13 +634,24 @@ static int add_directory_to_tar(gzFile gz, const char* dirpath, const char* base } if (S_ISDIR(st.st_mode)) { - // Recursively process subdirectory if (add_directory_to_tar(gz, fullpath, base_path, exclude_file) != 0) { closedir(dir); return -1; } + } else if (S_ISLNK(st.st_mode)) { + char target[PATH_MAX]; + ssize_t len = readlinkat(dirfd, entry->d_name, target, sizeof(target) - 1); + if (len < 0) { + RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, + "[%s:%d] Failed to readlink: %s\n", __FUNCTION__, __LINE__, fullpath); + continue; + } + target[len] = '\0'; + if (write_tar_header(gz, arcname, &st, target) != 0) { + RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, + "[%s:%d] Failed to add symlink: %s\n", __FUNCTION__, __LINE__, fullpath); + } } else if (S_ISREG(st.st_mode)) { - // Add file if (add_file_to_tar(gz, fullpath, arcname) != 0) { RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, "[%s:%d] Failed to add file: %s\n", __FUNCTION__, __LINE__, fullpath); From a5a69f6d3fa8e4a8e8cff74c1dd3b87472e50cab Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 19:36:29 +0530 Subject: [PATCH 16/35] Update strategies.c --- uploadstblogs/src/strategies.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index b70e84e6..82c04dae 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -625,10 +625,7 @@ static int dcm_archive(RuntimeContext* ctx, SessionState* session) "[%s:%d] Failed to create archive\n", __FUNCTION__, __LINE__); return -1; } - -#ifndef L2_TEST_ENABLED - sleep(60); -#endif + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, "[%s:%d] DCM: Archive phase complete\n", __FUNCTION__, __LINE__); From f70abd1ea39d579dd145da2dd64ad23e52d4aebf Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 19:46:39 +0530 Subject: [PATCH 17/35] Update backup_engine.c --- backup_logs/src/backup_engine.c | 35 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/backup_logs/src/backup_engine.c b/backup_logs/src/backup_engine.c index 57b7050a..ac416620 100644 --- a/backup_logs/src/backup_engine.c +++ b/backup_logs/src/backup_engine.c @@ -373,8 +373,14 @@ int backup_and_recover_logs(const char* source, const char* dest, return BACKUP_ERROR_INVALID_PARAM; } /* Open source directory */ - DIR* dir = opendir(source); + int dirfd = open(source, O_RDONLY | O_DIRECTORY); + if (dirfd < 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_BACKUP_LOGS, "Failed to open source directory: %s\n", source); + return BACKUP_ERROR_FILESYSTEM; + } + DIR* dir = fdopendir(dirfd); if (!dir) { + close(dirfd); RDK_LOG(RDK_LOG_ERROR, LOG_BACKUP_LOGS, "Failed to open source directory: %s\n", source); return BACKUP_ERROR_FILESYSTEM; } @@ -402,29 +408,24 @@ int backup_and_recover_logs(const char* source, const char* dest, continue; } - /* Check if it's a regular file (match shell script -type f). - * Use open(O_NOFOLLOW) + fstat() to eliminate TOCTOU (CWE-367): - * opening with O_NOFOLLOW refuses symlinks, and fstat() on the - * resulting fd operates on the same inode already held open, - * so no race window exists between the check and the use. */ + /* Use fstatat with AT_SYMLINK_NOFOLLOW on the directory fd (same pattern + * as archive_manager.c) to detect file type without TOCTOU races. + * Symlinks whose target is a regular file are allowed through. */ struct stat file_stat; - int check_fd = open(source_file, O_RDONLY | O_NOFOLLOW); - if (check_fd < 0) { - /* Skip if file cannot be opened (e.g. symlink or permission denied) */ + if (fstatat(dirfd, entry->d_name, &file_stat, AT_SYMLINK_NOFOLLOW) != 0) { continue; } - if (fstat(check_fd, &file_stat) != 0) { - close(check_fd); - continue; - } - close(check_fd); if (S_ISDIR(file_stat.st_mode)) { - /* Skip directories - we don't want to backup directories to PreviousLogs */ RDK_LOG(RDK_LOG_DEBUG, LOG_BACKUP_LOGS, "Skipping directory: %s\n", source_file); continue; } - if (!S_ISREG(file_stat.st_mode)) { - /* Skip non-regular files (symlinks, devices, etc.) */ + if (S_ISLNK(file_stat.st_mode)) { + /* Symlink: verify target is a regular file before allowing copy */ + struct stat target_stat; + if (fstatat(dirfd, entry->d_name, &target_stat, 0) != 0 || !S_ISREG(target_stat.st_mode)) { + continue; + } + } else if (!S_ISREG(file_stat.st_mode)) { continue; } From f9db5493667425fd4718e9f582a12d90744fbe5e Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sat, 1 Aug 2026 19:57:35 +0530 Subject: [PATCH 18/35] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- uploadstblogs/src/cleanup_handler.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/uploadstblogs/src/cleanup_handler.c b/uploadstblogs/src/cleanup_handler.c index dce8bc82..e7eff550 100755 --- a/uploadstblogs/src/cleanup_handler.c +++ b/uploadstblogs/src/cleanup_handler.c @@ -309,10 +309,15 @@ int remove_stale_timestamped_files(const char *log_path) int removed_count = 0; struct dirent *entry; - char filepath[512]; + int dfd = dirfd(dir); while ((entry = readdir(dir)) != NULL) { - if (entry->d_type == DT_DIR) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { + continue; + } + + struct stat st; + if (fstatat(dfd, entry->d_name, &st, AT_SYMLINK_NOFOLLOW) != 0 || !S_ISREG(st.st_mode)) { continue; } if (!is_timestamped_backup(entry->d_name)) { @@ -322,11 +327,10 @@ int remove_stale_timestamped_files(const char *log_path) continue; } - snprintf(filepath, sizeof(filepath), "%s/%s", log_path, entry->d_name); RDK_LOG(RDK_LOG_DEBUG, LOG_UPLOADSTB, "[%s:%d] Removing stale timestamped file: %s\n", - __FUNCTION__, __LINE__, filepath); - if (remove(filepath) == 0) { + __FUNCTION__, __LINE__, entry->d_name); + if (unlinkat(dfd, entry->d_name, 0) == 0) { removed_count++; } } From 1d93296d8b125ab9d4e0db7e53581d192181f3f3 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 09:02:03 +0530 Subject: [PATCH 19/35] Update dcm_utils.c --- dcm_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dcm_utils.c b/dcm_utils.c index f2d691d0..f9c3f6f9 100644 --- a/dcm_utils.c +++ b/dcm_utils.c @@ -67,9 +67,9 @@ void DCMLOGInit() if (rdk_logger_ext_init(&config) != RDK_SUCCESS) { printf("UPLOADSTB : ERROR - Extended logger init failed\n"); } - else { - g_rdk_logger_enabled = 1; - } +// else { +// g_rdk_logger_enabled = 1; +// } #endif } From 7b9e20424d8680d0637f52cd25f66380df0e4ed8 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 11:34:52 +0530 Subject: [PATCH 20/35] Update archive_manager.c --- uploadstblogs/src/archive_manager.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uploadstblogs/src/archive_manager.c b/uploadstblogs/src/archive_manager.c index 1dc99e68..7f44c61a 100755 --- a/uploadstblogs/src/archive_manager.c +++ b/uploadstblogs/src/archive_manager.c @@ -647,11 +647,15 @@ static int add_directory_to_tar(gzFile gz, const char* dirpath, const char* base continue; } target[len] = '\0'; + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, + "Processing file...%s\n", arcname); if (write_tar_header(gz, arcname, &st, target) != 0) { RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, "[%s:%d] Failed to add symlink: %s\n", __FUNCTION__, __LINE__, fullpath); } } else if (S_ISREG(st.st_mode)) { + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, + "Processing file...%s\n", arcname); if (add_file_to_tar(gz, fullpath, arcname) != 0) { RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, "[%s:%d] Failed to add file: %s\n", __FUNCTION__, __LINE__, fullpath); From 66b6d3177552205c8be03744e2477242c06963bc Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 12:39:01 +0530 Subject: [PATCH 21/35] Update strategies.c --- uploadstblogs/src/strategies.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index 82c04dae..6190e0b6 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -499,9 +499,17 @@ static int process_dcm_upload_list(RuntimeContext* ctx) if (strlen(line) == 0) continue; if (dir_exists(line)) { + /* cp -R $line $DCM_LOG_PATH copies the directory itself, not just contents */ + const char* basename = strrchr(line, '/'); + basename = basename ? basename + 1 : line; + + char dest_subdir[MAX_PATH_LENGTH]; + snprintf(dest_subdir, sizeof(dest_subdir), "%s/%s", ctx->dcm_log_path, basename); + create_directory(dest_subdir); + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, - "[%s:%d] Copying batched logs from %s\n", __FUNCTION__, __LINE__, line); - copy_dir_recursive(line, ctx->dcm_log_path); + "[%s:%d] Copying batched logs from %s to %s\n", __FUNCTION__, __LINE__, line, dest_subdir); + copy_dir_recursive(line, dest_subdir); count++; } } From 4b30fbb254ebfa2d99adf5c987070ad34f2d8fb7 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 13:41:40 +0530 Subject: [PATCH 22/35] Update strategies.c --- uploadstblogs/src/strategies.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index 6190e0b6..73163100 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -503,8 +503,13 @@ static int process_dcm_upload_list(RuntimeContext* ctx) const char* basename = strrchr(line, '/'); basename = basename ? basename + 1 : line; - char dest_subdir[MAX_PATH_LENGTH]; - snprintf(dest_subdir, sizeof(dest_subdir), "%s/%s", ctx->dcm_log_path, basename); + char dest_subdir[MAX_PATH_LENGTH + MAX_PATH_LENGTH]; + int n = snprintf(dest_subdir, sizeof(dest_subdir), "%s/%s", ctx->dcm_log_path, basename); + if (n < 0 || (size_t)n >= sizeof(dest_subdir)) { + RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, + "[%s:%d] Destination path too long, skipping: %s\n", __FUNCTION__, __LINE__, line); + continue; + } create_directory(dest_subdir); RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, From 1937867f29d821d0df5a3138fff2c75dd0b55673 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 14:21:39 +0530 Subject: [PATCH 23/35] Update strategies.c --- uploadstblogs/src/strategies.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index 73163100..38083b4c 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -568,8 +568,7 @@ static int dcm_setup(RuntimeContext* ctx, SessionState* session) // copyAllFiles: copy LOG_PATH/* excluding dcm, PreviousLogs, PreviousLogs_backup copy_all_files_to_dcm(ctx->log_path, ctx->dcm_log_path); } else { - // Process DCM_UPLOAD_LIST: copy batched directories, then copy current opt logs - process_dcm_upload_list(ctx); + // Copy current opt logs first, then batched directories copy_opt_logs_files(ctx->log_path, ctx->dcm_log_path); } @@ -581,7 +580,7 @@ static int dcm_setup(RuntimeContext* ctx, SessionState* session) return -1; // Signal to skip upload } - // Add timestamps to all files in DCM_LOG_PATH + // Add timestamps to files already in DCM_LOG_PATH (before adding batched dirs) RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, "[%s:%d] Adding timestamps to files in DCM_LOG_PATH\n", __FUNCTION__, __LINE__); @@ -591,7 +590,11 @@ static int dcm_setup(RuntimeContext* ctx, SessionState* session) RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, "[%s:%d] Failed to add timestamps to some files\n", __FUNCTION__, __LINE__); - // Continue anyway, not critical + } + + // Copy batched directories AFTER timestamping (they already have timestamps) + if (ctx->upload_on_reboot == 0) { + process_dcm_upload_list(ctx); } RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, From ec16066561004b13306e8dbcd4cd2fd9e4cb2f13 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 14:54:26 +0530 Subject: [PATCH 24/35] Update strategies.c --- uploadstblogs/src/strategies.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index 38083b4c..d521d464 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -510,6 +510,11 @@ static int process_dcm_upload_list(RuntimeContext* ctx) "[%s:%d] Destination path too long, skipping: %s\n", __FUNCTION__, __LINE__, line); continue; } + + /* Skip duplicate entries */ + if (dir_exists(dest_subdir)) { + continue; + } create_directory(dest_subdir); RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, @@ -520,10 +525,11 @@ static int process_dcm_upload_list(RuntimeContext* ctx) } fclose(fp); - // Clear the upload list after processing + // Always clear the upload list after reading (script: cat /dev/null > $DCM_UPLOAD_LIST) + fp = fopen(list_path, "w"); + if (fp) fclose(fp); + if (count > 0) { - fp = fopen(list_path, "w"); - if (fp) fclose(fp); RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, "[%s:%d] Processed %d entries from DCM upload list\n", __FUNCTION__, __LINE__, count); From def385d803d9452aded4b793a4ddfa1d1bcc2fda Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 15:06:31 +0530 Subject: [PATCH 25/35] Update uploadstblogs.c --- uploadstblogs/src/uploadstblogs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/uploadstblogs/src/uploadstblogs.c b/uploadstblogs/src/uploadstblogs.c index 18c20f43..203237bb 100755 --- a/uploadstblogs/src/uploadstblogs.c +++ b/uploadstblogs/src/uploadstblogs.c @@ -422,6 +422,14 @@ int uploadstblogs_execute(int argc, char** argv) return ret; } + /* Limit attempts to 1 when called from plugin (deepsleep) */ + if (ctx.trigger_type == TRIGGER_MANUAL) { + ctx.direct_max_attempts = 1; + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, "Called from Plugin with 1 attempt\n"); + } else { + RDK_LOG(RDK_LOG_INFO, LOG_UPLOADSTB, "Called with %d attempts\n", ctx.direct_max_attempts); + } + /* Verify context after parse_args */ RDK_LOG(RDK_LOG_DEBUG, LOG_UPLOADSTB, "[main] Context after parse_args: MAC='%s', device_type='%s'\n", From bd8319ab89402129a387c65404b438989fda859d Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 16:47:36 +0530 Subject: [PATCH 26/35] Update path_handler.c --- uploadstblogs/src/path_handler.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/uploadstblogs/src/path_handler.c b/uploadstblogs/src/path_handler.c index 162b97a2..996f94fd 100755 --- a/uploadstblogs/src/path_handler.c +++ b/uploadstblogs/src/path_handler.c @@ -28,6 +28,7 @@ #include "path_handler.h" #include "verification.h" #include "md5_utils.h" +#include "rbus_interface.h" #include "rdk_debug.h" // Include the upload library headers @@ -66,6 +67,11 @@ UploadResult execute_direct_path(RuntimeContext* ctx, SessionState* session) char *archive_filepath = session->archive_file; // Use endpoint_url from TR-181 if available, otherwise fall back to upload_http_link from CLI + // Fetch lazily here (not at init) to avoid 15s rbus timeout when provider isn't ready + if (strlen(ctx->endpoint_url) == 0) { + rbus_get_string_param("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LogUploadEndpoint.URL", + ctx->endpoint_url, sizeof(ctx->endpoint_url)); + } char *endpoint_url = (strlen(ctx->endpoint_url) > 0) ? ctx->endpoint_url : ctx->upload_http_link; From c91ca090bfeccc467f4df4ec345164f6b97bdd4f Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 16:50:57 +0530 Subject: [PATCH 27/35] Update context_manager.c --- uploadstblogs/src/context_manager.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/uploadstblogs/src/context_manager.c b/uploadstblogs/src/context_manager.c index 1906cff3..5630ab19 100755 --- a/uploadstblogs/src/context_manager.c +++ b/uploadstblogs/src/context_manager.c @@ -444,14 +444,9 @@ bool load_tr181_params(RuntimeContext* ctx) return false; } - // Load LogUploadEndpoint URL - // Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LogUploadEndpoint.URL - if (!rbus_get_string_param("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LogUploadEndpoint.URL", - ctx->endpoint_url, - sizeof(ctx->endpoint_url))) { - RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, "[%s:%d] Failed to get LogUploadEndpoint.URL\n", - __FUNCTION__, __LINE__); - } + // LogUploadEndpoint.URL is fetched lazily at upload time (path_handler.c) + // to avoid blocking init when the rbus provider isn't ready yet. + ctx->endpoint_url[0] = '\0'; // Load EncryptCloudUpload Enable flag (boolean parameter) // Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.EncryptCloudUpload.Enable From fc8e56516c46b370c24206c5f29b60a55eb7cc56 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 18:57:45 +0530 Subject: [PATCH 28/35] Update context_manager.c --- uploadstblogs/src/context_manager.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/uploadstblogs/src/context_manager.c b/uploadstblogs/src/context_manager.c index 5630ab19..1906cff3 100755 --- a/uploadstblogs/src/context_manager.c +++ b/uploadstblogs/src/context_manager.c @@ -444,9 +444,14 @@ bool load_tr181_params(RuntimeContext* ctx) return false; } - // LogUploadEndpoint.URL is fetched lazily at upload time (path_handler.c) - // to avoid blocking init when the rbus provider isn't ready yet. - ctx->endpoint_url[0] = '\0'; + // Load LogUploadEndpoint URL + // Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LogUploadEndpoint.URL + if (!rbus_get_string_param("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LogUploadEndpoint.URL", + ctx->endpoint_url, + sizeof(ctx->endpoint_url))) { + RDK_LOG(RDK_LOG_WARN, LOG_UPLOADSTB, "[%s:%d] Failed to get LogUploadEndpoint.URL\n", + __FUNCTION__, __LINE__); + } // Load EncryptCloudUpload Enable flag (boolean parameter) // Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.EncryptCloudUpload.Enable From e550aab9bd6023077c9f273b3338a1abfbbf8f34 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 18:58:40 +0530 Subject: [PATCH 29/35] Update path_handler.c --- uploadstblogs/src/path_handler.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/uploadstblogs/src/path_handler.c b/uploadstblogs/src/path_handler.c index 996f94fd..e6d8d29d 100755 --- a/uploadstblogs/src/path_handler.c +++ b/uploadstblogs/src/path_handler.c @@ -28,7 +28,6 @@ #include "path_handler.h" #include "verification.h" #include "md5_utils.h" -#include "rbus_interface.h" #include "rdk_debug.h" // Include the upload library headers @@ -67,11 +66,6 @@ UploadResult execute_direct_path(RuntimeContext* ctx, SessionState* session) char *archive_filepath = session->archive_file; // Use endpoint_url from TR-181 if available, otherwise fall back to upload_http_link from CLI - // Fetch lazily here (not at init) to avoid 15s rbus timeout when provider isn't ready - if (strlen(ctx->endpoint_url) == 0) { - rbus_get_string_param("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LogUploadEndpoint.URL", - ctx->endpoint_url, sizeof(ctx->endpoint_url)); - } char *endpoint_url = (strlen(ctx->endpoint_url) > 0) ? ctx->endpoint_url : ctx->upload_http_link; @@ -594,4 +588,3 @@ static UploadResult perform_s3_put_with_fallback(RuntimeContext* ctx, SessionSta } - From 7779baed72cad57ffcecca7daeb73b3723fd4e4e Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Sun, 2 Aug 2026 18:59:16 +0530 Subject: [PATCH 30/35] Update path_handler.c --- uploadstblogs/src/path_handler.c | 1 + 1 file changed, 1 insertion(+) diff --git a/uploadstblogs/src/path_handler.c b/uploadstblogs/src/path_handler.c index e6d8d29d..162b97a2 100755 --- a/uploadstblogs/src/path_handler.c +++ b/uploadstblogs/src/path_handler.c @@ -588,3 +588,4 @@ static UploadResult perform_s3_put_with_fallback(RuntimeContext* ctx, SessionSta } + From 4bc5585d4c972fcc5f50e5ffe064cc085f5d9f54 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Tue, 4 Aug 2026 17:24:46 +0530 Subject: [PATCH 31/35] Update strategies.c --- uploadstblogs/src/strategies.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index 232a1923..bf51b6e0 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -1598,4 +1598,5 @@ static int reboot_cleanup(RuntimeContext* ctx, SessionState* session, bool uploa __FUNCTION__, __LINE__, perm_log_path); return 0; -} \ No newline at end of file + +} From 74c66a763b69f7342a2a4bcefc1f7fd67b7c713b Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Tue, 4 Aug 2026 17:25:23 +0530 Subject: [PATCH 32/35] Update strategies.c --- uploadstblogs/src/strategies.c | 1 - 1 file changed, 1 deletion(-) diff --git a/uploadstblogs/src/strategies.c b/uploadstblogs/src/strategies.c index bf51b6e0..93c9319d 100644 --- a/uploadstblogs/src/strategies.c +++ b/uploadstblogs/src/strategies.c @@ -1598,5 +1598,4 @@ static int reboot_cleanup(RuntimeContext* ctx, SessionState* session, bool uploa __FUNCTION__, __LINE__, perm_log_path); return 0; - } From 2f1b57239de99df839c0059d70f6ab8d21654e39 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Tue, 4 Aug 2026 17:26:33 +0530 Subject: [PATCH 33/35] Update dcm_utils.c --- dcm_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dcm_utils.c b/dcm_utils.c index f9c3f6f9..f2d691d0 100644 --- a/dcm_utils.c +++ b/dcm_utils.c @@ -67,9 +67,9 @@ void DCMLOGInit() if (rdk_logger_ext_init(&config) != RDK_SUCCESS) { printf("UPLOADSTB : ERROR - Extended logger init failed\n"); } -// else { -// g_rdk_logger_enabled = 1; -// } + else { + g_rdk_logger_enabled = 1; + } #endif } From 0772d979424cbcfac2c406849b5f3f2426029314 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 5 Aug 2026 08:12:00 +0530 Subject: [PATCH 34/35] Update dcm_utils.c --- dcm_utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dcm_utils.c b/dcm_utils.c index f2d691d0..41ed65b3 100644 --- a/dcm_utils.c +++ b/dcm_utils.c @@ -59,9 +59,10 @@ void DCMLOGInit() rdk_logger_ext_config_t config = { .pModuleName = "LOG.RDK.DCM", /* Module name */ .loglevel = RDK_LOG_INFO, /* Default log level */ - .output = RDKLOG_OUTPUT_FILE, + //.output = RDKLOG_OUTPUT_FILE, + .output = RDKLOG_OUTPUT_CONSOLE, .format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */ - .pFilePolicy = &filelog /* using file output */ + .pFilePolicy = NULL /* using file output */ }; if (rdk_logger_ext_init(&config) != RDK_SUCCESS) { From d7b7bac520e4fcf99d3c09378a705c319d6ec022 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 5 Aug 2026 10:42:04 +0530 Subject: [PATCH 35/35] Update context_manager.c --- uploadstblogs/src/context_manager.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/uploadstblogs/src/context_manager.c b/uploadstblogs/src/context_manager.c index 1906cff3..9d27e813 100755 --- a/uploadstblogs/src/context_manager.c +++ b/uploadstblogs/src/context_manager.c @@ -165,9 +165,10 @@ bool init_context(RuntimeContext* ctx) rdk_logger_ext_config_t config = { .pModuleName = "LOG.RDK.UPLOADSTB", /* Module name */ .loglevel = RDK_LOG_INFO, /* Default log level */ - .output = RDKLOG_OUTPUT_FILE, + .output = RDKLOG_OUTPUT_CONSOLE, .format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */ - .pFilePolicy = &filelog /* using file output */ + .pFilePolicy = NULL + //.pFilePolicy = &filelog /* using file output */ }; if (rdk_logger_ext_init(&config) != RDK_SUCCESS) {