From 414b6ea8e29abd0f586c726361c2a4b5a607c181 Mon Sep 17 00:00:00 2001 From: jthomp007c Date: Tue, 16 Dec 2025 17:12:45 +0000 Subject: [PATCH 1/6] DELIA-69767: replace popen() with C functions, add ms to timestamps Reason for change: Somehow the execve calling cat in the popen() function is closing a file descriptor used by another thread Test Procedure: Standard NSM chamber testing Risks: Low Priority: P1 Signed-off-by: Jason Thomson --- .../commonlib/telemetry_busmessage_sender.c | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/source/commonlib/telemetry_busmessage_sender.c b/source/commonlib/telemetry_busmessage_sender.c index c5d43127..b1d085c1 100644 --- a/source/commonlib/telemetry_busmessage_sender.c +++ b/source/commonlib/telemetry_busmessage_sender.c @@ -85,13 +85,23 @@ static void EVENT_DEBUG(char* format, ...) logHandle = fopen(SENDER_LOG_FILE, "a+"); if(logHandle) { - time_t rawtime; - struct tm* timeinfo; + struct timespec ts; + struct tm timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - static char timeBuffer[20] = { '\0' }; - strftime(timeBuffer, sizeof(timeBuffer), "%Y-%m-%d %H:%M:%S", timeinfo); + if(clock_gettime(CLOCK_REALTIME, &ts) == -1) + { + fclose(logHandle); + pthread_mutex_unlock(&loggerMutex); + return; + } + + static char timeBuffer[24] = { '\0' }; + long msecs; + + localtime_r(&ts.tv_sec, &timeinfo); + msecs = ts.tv_nsec / 1000000; + strftime(timeBuffer, sizeof(timeBuffer), "%Y-%m-%d %H:%M:%S", &timeinfo); + snprintf(timeBuffer + strlen(timeBuffer), sizeof(timeBuffer) - strlen(timeBuffer), ".%03ld", msecs); fprintf(logHandle, "%s : ", timeBuffer); va_list argList; va_start(argList, format); @@ -316,7 +326,6 @@ void *cacheEventToFile(void *arg) fl.l_len = 0; fl.l_pid = 0; FILE *fs = NULL; - char path[100]; pthread_detach(pthread_self()); EVENT_ERROR("%s:%d, Caching the event to File\n", __func__, __LINE__); if(telemetry_data == NULL) @@ -353,12 +362,22 @@ void *cacheEventToFile(void *arg) EVENT_ERROR("%s: File open error %s\n", __FUNCTION__, T2_CACHE_FILE); goto unlock; } - fs = popen ("cat /tmp/t2_caching_file | wc -l", "r"); - if(fs != NULL) - { - fgets(path, 100, fs); - count = atoi ( path ); - pclose(fs); + + fs = fopen(T2_CACHE_FILE, "r"); + if (fs != NULL) { + while ((ch = fgetc(fs)) != EOF) { + if (ch == '\n') { + count++; + } + } + + if (ch != '\n' && lines == 0 && ftell(fs) > 0) { + count++; + } else if (ch != '\n' && ftell(fs) > 0) { + count++; + } + fclose(fs); + fs = NULL; } if(count < MAX_EVENT_CACHE) { From 297b0a9e48dfc66af1b03360d77d8efdf3e53aa3 Mon Sep 17 00:00:00 2001 From: jthomp007c Date: Tue, 16 Dec 2025 21:47:05 +0000 Subject: [PATCH 2/6] Fixing var errors --- source/commonlib/telemetry_busmessage_sender.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/commonlib/telemetry_busmessage_sender.c b/source/commonlib/telemetry_busmessage_sender.c index b1d085c1..be61b902 100644 --- a/source/commonlib/telemetry_busmessage_sender.c +++ b/source/commonlib/telemetry_busmessage_sender.c @@ -326,6 +326,7 @@ void *cacheEventToFile(void *arg) fl.l_len = 0; fl.l_pid = 0; FILE *fs = NULL; + char ch; pthread_detach(pthread_self()); EVENT_ERROR("%s:%d, Caching the event to File\n", __func__, __LINE__); if(telemetry_data == NULL) @@ -371,9 +372,8 @@ void *cacheEventToFile(void *arg) } } - if (ch != '\n' && lines == 0 && ftell(fs) > 0) { - count++; - } else if (ch != '\n' && ftell(fs) > 0) { + //If the file is not empty and does not contain a newline, call it one line + if (count == 0 && ftell(fs) > 0) { count++; } fclose(fs); From 597a786ca86f25abe8f12fbe5641d5aa68d87bc0 Mon Sep 17 00:00:00 2001 From: jthomp007c Date: Wed, 17 Dec 2025 15:12:52 +0000 Subject: [PATCH 3/6] Fixing coverity issue --- source/commonlib/telemetry_busmessage_sender.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/commonlib/telemetry_busmessage_sender.c b/source/commonlib/telemetry_busmessage_sender.c index be61b902..61c8d465 100644 --- a/source/commonlib/telemetry_busmessage_sender.c +++ b/source/commonlib/telemetry_busmessage_sender.c @@ -326,8 +326,7 @@ void *cacheEventToFile(void *arg) fl.l_len = 0; fl.l_pid = 0; FILE *fs = NULL; - char ch; - pthread_detach(pthread_self()); + int ch; EVENT_ERROR("%s:%d, Caching the event to File\n", __func__, __LINE__); if(telemetry_data == NULL) { From cccb5a6689e34227c4ec45981dec5ea48bdb69b2 Mon Sep 17 00:00:00 2001 From: Shibu Kakkoth Vayalambron Date: Wed, 17 Dec 2025 13:50:08 -0800 Subject: [PATCH 4/6] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- source/commonlib/telemetry_busmessage_sender.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/commonlib/telemetry_busmessage_sender.c b/source/commonlib/telemetry_busmessage_sender.c index 61c8d465..173d1bcd 100644 --- a/source/commonlib/telemetry_busmessage_sender.c +++ b/source/commonlib/telemetry_busmessage_sender.c @@ -95,7 +95,7 @@ static void EVENT_DEBUG(char* format, ...) return; } - static char timeBuffer[24] = { '\0' }; + char timeBuffer[24] = { '\0' }; long msecs; localtime_r(&ts.tv_sec, &timeinfo); From f2712f9e9c6a23d39ab10bda0e84f7ed103a63c9 Mon Sep 17 00:00:00 2001 From: PriyaDharshini_Kathiravan Date: Wed, 24 Dec 2025 10:54:41 +0000 Subject: [PATCH 5/6] Update telemetry_busmessage_sender.c --- source/commonlib/telemetry_busmessage_sender.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/commonlib/telemetry_busmessage_sender.c b/source/commonlib/telemetry_busmessage_sender.c index 173d1bcd..ae0396ff 100644 --- a/source/commonlib/telemetry_busmessage_sender.c +++ b/source/commonlib/telemetry_busmessage_sender.c @@ -55,7 +55,6 @@ static void *bus_handle = NULL; static bool isRFCT2Enable = false ; static bool isT2Ready = false; static bool isRbusEnabled = false ; -static int count = 0; static pthread_mutex_t initMtx = PTHREAD_MUTEX_INITIALIZER; static bool isMutexInitialized = false ; @@ -326,7 +325,9 @@ void *cacheEventToFile(void *arg) fl.l_len = 0; fl.l_pid = 0; FILE *fs = NULL; + pthread_detach(pthread_self()); int ch; + int count = 0; EVENT_ERROR("%s:%d, Caching the event to File\n", __func__, __LINE__); if(telemetry_data == NULL) { From 7b8118aab016a6cc08dd623a45be53a87e4b8b7a Mon Sep 17 00:00:00 2001 From: PriyaDharshini_Kathiravan Date: Wed, 24 Dec 2025 11:42:17 +0000 Subject: [PATCH 6/6] Resolve formatting errors in telemetry_busemessage_sender.c --- source/commonlib/telemetry_busmessage_sender.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/commonlib/telemetry_busmessage_sender.c b/source/commonlib/telemetry_busmessage_sender.c index ae0396ff..3734bc6c 100644 --- a/source/commonlib/telemetry_busmessage_sender.c +++ b/source/commonlib/telemetry_busmessage_sender.c @@ -93,7 +93,7 @@ static void EVENT_DEBUG(char* format, ...) pthread_mutex_unlock(&loggerMutex); return; } - + char timeBuffer[24] = { '\0' }; long msecs; @@ -365,15 +365,19 @@ void *cacheEventToFile(void *arg) } fs = fopen(T2_CACHE_FILE, "r"); - if (fs != NULL) { - while ((ch = fgetc(fs)) != EOF) { - if (ch == '\n') { + if (fs != NULL) + { + while ((ch = fgetc(fs)) != EOF) + { + if (ch == '\n') + { count++; } } - + //If the file is not empty and does not contain a newline, call it one line - if (count == 0 && ftell(fs) > 0) { + if (count == 0 && ftell(fs) > 0) + { count++; } fclose(fs);