diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df8475f..a155274b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,25 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [1.6.0](https://github.com/rdkcentral/telemetry/compare/1.5.2...1.6.0) + +- Resolve build errors in XE2-V2 builds [`#145`](https://github.com/rdkcentral/telemetry/pull/145) +- RDKB-60894 : crash with strnstr and memcmp_eq in T2 [`#144`](https://github.com/rdkcentral/telemetry/pull/144) +- RDK-57625: [RDK-E] Increase L2 Test Coverage For Telemetry [`#128`](https://github.com/rdkcentral/telemetry/pull/128) +- RDK-58420: crash [`#141`](https://github.com/rdkcentral/telemetry/pull/141) +- RDK-58420: Implement Log rotation logic for grep markers [`#135`](https://github.com/rdkcentral/telemetry/pull/135) +- RDK-58420: Optimize dca sub-module for log data scrapping [`f68badc`](https://github.com/rdkcentral/telemetry/commit/f68badc055ce35ba80c23a23e56d32eb766fd6b0) +- Update dca.c with temporary file approach [`9fc4930`](https://github.com/rdkcentral/telemetry/commit/9fc49306c65d51e21c471c36874270d7cf423faa) +- Update dca.c to resolve memcmp_crash [`34f7a90`](https://github.com/rdkcentral/telemetry/commit/34f7a90e84aad97ab43af5021c0e466c65e240f2) + #### [1.5.2](https://github.com/rdkcentral/telemetry/compare/1.5.1...1.5.2) +> 21 July 2025 + - RDK-58398:Fix curl dependency for some API's [`#136`](https://github.com/rdkcentral/telemetry/pull/136) - RDK-57323 : Add support for URL encoding for Xconf-client module [`#133`](https://github.com/rdkcentral/telemetry/pull/133) - Change persistence storage path for Pods [`#132`](https://github.com/rdkcentral/telemetry/pull/132) +- Changelog updates from release 1.5.2 [`2c92b1d`](https://github.com/rdkcentral/telemetry/commit/2c92b1df823123004834969c083c596f01a3bb75) #### [1.5.1](https://github.com/rdkcentral/telemetry/compare/1.5.0...1.5.1) diff --git a/source/bulkdata/profilexconf.c b/source/bulkdata/profilexconf.c index bc3495dc..1a3375ee 100644 --- a/source/bulkdata/profilexconf.c +++ b/source/bulkdata/profilexconf.c @@ -361,10 +361,11 @@ static void* CollectAndReportXconf(void* data) #ifdef PERSIST_LOG_MON_REF if(profile->checkPreviousSeek) { - T2Info("This is a Previous Logs Report sleep randomly for 1-100 sec\n"); srand(size + 1); - int random_sleep = (int) rand() % 99; - sleep(random_sleep); + int random_sleep = (int) rand() % 50; + sleep(random_sleep + 1); + // reducing the MAX sleep value from 100 -> 50 seconds to avoid conflict with regular execution + T2Info("This is a Previous Logs Report sleep randomly for 1-50 sec\n"); } #endif if(profile->protocol != NULL && strcmp(profile->protocol, "HTTP") == 0) @@ -554,7 +555,7 @@ T2ERROR ProfileXConf_init(bool checkPreviousSeek) { T2Info("Previous Seek is enabled so generate the Xconf report \n"); // Trigger a xconf report if previous seek is enabled and valid. - ProfileXConf_notifyTimeout(true, true); + ProfileXConf_notifyTimeout(true, false); } #endif populateCachedReportList(profile->name, profile->cachedReportList); diff --git a/source/ccspinterface/rbusInterface.c b/source/ccspinterface/rbusInterface.c index c1420aaa..683bb970 100644 --- a/source/ccspinterface/rbusInterface.c +++ b/source/ccspinterface/rbusInterface.c @@ -903,6 +903,7 @@ void publishReportUploadStatus(char* status) { T2Info("%s rbusMethod_SendAsyncResponse sent successfully \n", __FUNCTION__); } + onDemandReportCallBackHandler = NULL; // just a safety cleanup pthread_mutex_unlock(&asyncMutex); rbusValue_Release(value); rbusObject_Release(outParams); diff --git a/source/dcautil/dca.c b/source/dcautil/dca.c index 597cfa52..7ad6de1e 100644 --- a/source/dcautil/dca.c +++ b/source/dcautil/dca.c @@ -664,21 +664,21 @@ static int getLogFileDescriptor(GrepSeekProfile* gsProfile, const char* logPath, int fd = open(logFilePath, O_RDONLY); if (fd == -1) { - T2Error("Failed to open log file %s\n", logFilePath); + T2Debug("Failed to open log file %s\n", logFilePath); return -1; } struct stat sb; if (fstat(fd, &sb) == -1) { - T2Error("Error getting file size for %s\n", logFile); + T2Debug("Error getting file size for %s\n", logFile); close(fd); return -1; } if (sb.st_size == 0) { - T2Error("The size of the logfile is 0 for %s\n", logFile); + T2Debug("The size of the logfile is 0 for %s\n", logFile); close(fd); return -1; // Consistent error return value } @@ -686,7 +686,7 @@ static int getLogFileDescriptor(GrepSeekProfile* gsProfile, const char* logPath, // Check if the file size matches the seek value from the map if (sb.st_size == seek_value_from_map) { - T2Error("The logfile size matches the seek value (%ld) for %s\n", seek_value_from_map, logFile); + T2Info("The logfile size matches the seek value (%ld) for %s\n", seek_value_from_map, logFile); close(fd); return -1; // Consistent error return value } @@ -729,14 +729,14 @@ static int getRotatedLogFileDescriptor(const char* logPath, const char* logFile) int rd = open(rotatedlogFilePath, O_RDONLY); if (rd == -1) { - T2Error("Failed to open log file %s\n", rotatedlogFilePath); + T2Debug("Failed to open log file %s\n", rotatedlogFilePath); return -1; } struct stat rb; if (fstat(rd, &rb) == -1) { - T2Error("Error getting file size for %s\n", rotatedlogFilePath); + T2Debug("Error getting file size for %s\n", rotatedlogFilePath); close(rd); return -1; } @@ -744,7 +744,7 @@ static int getRotatedLogFileDescriptor(const char* logPath, const char* logFile) // Check if the file size is 0 if (rb.st_size == 0) { - T2Error("The size of the logfile is 0 for %s\n", rotatedlogFilePath); + T2Debug("The size of the logfile is 0 for %s\n", rotatedlogFilePath); close(rd); return -1; // Consistent error return value } @@ -816,67 +816,29 @@ static FileDescriptor* getFileDeltaInMemMapAndSearch(const int fd, const off_t s offset_in_page_size_multiple = 0; bytes_ignored = 0; } - //create a tmp file for main file fd - char tmp_fdmain[] = "/tmp/dca_tmpfile_fdmainXXXXXX"; - int tmp_fd = mkstemp(tmp_fdmain); - if (tmp_fd == -1) - { - T2Error("Failed to create temp file: %s\n", strerror(errno)); - return NULL; - } - unlink(tmp_fdmain); - off_t offset = 0; - ssize_t sent = sendfile(tmp_fd, fd, &offset, sb.st_size); - if (sent != sb.st_size) - { - T2Error("sendfile failed: %s\n", strerror(errno)); - close(tmp_fd); - return NULL; - } if(seek_value > sb.st_size || check_rotated == true) { int rd = getRotatedLogFileDescriptor(logPath, logFile); if (rd != -1 && fstat(rd, &rb) == 0 && rb.st_size > 0) { - char tmp_fdrotated[] = "/tmp/dca_tmpfile_fdrotatedXXXXXX"; - int tmp_rd = mkstemp(tmp_fdrotated); - if (tmp_rd == -1) - { - T2Error("Failed to create temp file: %s\n", strerror(errno)); - close(tmp_fd); - return NULL; - } - unlink(tmp_fdrotated); - offset = 0; - - sent = sendfile(tmp_rd, rd, &offset, rb.st_size); - if (sent != rb.st_size) - { - T2Error("sendfile failed: %s\n", strerror(errno)); - close(tmp_rd); - close(tmp_fd); - return NULL; - } - if(rb.st_size > seek_value) { rotated_fsize = rb.st_size - seek_value; main_fsize = sb.st_size; bytes_ignored_rotated = bytes_ignored; - addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, tmp_fd, 0); - addrrf = mmap(NULL, rb.st_size, PROT_READ, MAP_PRIVATE, tmp_rd, offset_in_page_size_multiple); + addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + addrrf = mmap(NULL, rb.st_size, PROT_READ, MAP_PRIVATE, rd, offset_in_page_size_multiple); } else { rotated_fsize = rb.st_size; main_fsize = sb.st_size - seek_value; bytes_ignored_main = bytes_ignored; - addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, tmp_fd, offset_in_page_size_multiple); - addrrf = mmap(NULL, rb.st_size, PROT_READ, MAP_PRIVATE, tmp_rd, 0); + addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, offset_in_page_size_multiple); + addrrf = mmap(NULL, rb.st_size, PROT_READ, MAP_PRIVATE, rd, 0); } - close(tmp_rd); close(rd); rd = -1; } @@ -886,7 +848,7 @@ static FileDescriptor* getFileDeltaInMemMapAndSearch(const int fd, const off_t s T2Debug("File size rounded to nearest page size used for offset read: %jd bytes\n", (intmax_t)offset_in_page_size_multiple); if(seek_value < sb.st_size) { - addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, tmp_fd, offset_in_page_size_multiple); + addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, offset_in_page_size_multiple); bytes_ignored_main = bytes_ignored; main_fsize = sb.st_size - seek_value; } @@ -894,31 +856,38 @@ static FileDescriptor* getFileDeltaInMemMapAndSearch(const int fd, const off_t s { T2Debug("Log file got rotated. Ignoring invalid mapping\n"); - close(tmp_fd); close(fd); + if(rd != -1) + { + close(rd); + rd = -1; + } return NULL; } } + if(rd != -1) + { + close(rd); + rd = -1; + } } else { T2Debug("File size rounded to nearest page size used for offset read: %jd bytes\n", (intmax_t)offset_in_page_size_multiple); if(seek_value < sb.st_size) { - addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, tmp_fd, offset_in_page_size_multiple); + addrcf = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, offset_in_page_size_multiple); bytes_ignored_main = bytes_ignored; main_fsize = sb.st_size - seek_value; } else { T2Debug("Log file got rotated. Ignoring invalid mapping\n"); - close(tmp_fd); close(fd); return NULL; } addrrf = NULL; } - close(tmp_fd); close(fd); if (addrcf == MAP_FAILED) @@ -940,6 +909,11 @@ static FileDescriptor* getFileDeltaInMemMapAndSearch(const int fd, const off_t s if (!fileDescriptor) { T2Error("Error allocating memory for FileDescriptor\n"); + munmap(addrcf, sb.st_size); + if(addrrf != NULL) + { + munmap(addrrf, rb.st_size); + } return NULL; } memset(fileDescriptor, 0, sizeof(FileDescriptor)); diff --git a/source/scheduler/scheduler.c b/source/scheduler/scheduler.c index d2e20384..bab6fa6a 100644 --- a/source/scheduler/scheduler.c +++ b/source/scheduler/scheduler.c @@ -164,19 +164,62 @@ void* TimeoutThread(void *arg) registerTriggerConditionConsumer(); T2Debug("TimeoutThread id is %d\n", (int)tProfile->tId); + // 1. Initialize condition variable attributes + pthread_condattr_t Profile_attr; + if (pthread_condattr_init(&Profile_attr) != 0) + { + T2Error("pthread_condattr_init failed"); + return NULL; + } + + //Set the clock source for the condition variable as CLOCK_MONOTONIC + // This is important to prevent timer from drifting because of systemtime drift ( such as NTP sync) + if (pthread_condattr_setclock(&Profile_attr, CLOCK_MONOTONIC) != 0) + { + T2Error("pthread_condattr_setclock failed \n"); + if (pthread_condattr_destroy(&Profile_attr) != 0) + { + T2Error("pthread_condattr_destroy failed \n"); + } + return NULL; + } + + //Initialize the condition variable with the attributes + if (pthread_cond_init(&tProfile->tCond, &Profile_attr) != 0) + { + T2Error("pthread_cond_init failed\n"); + if (pthread_condattr_destroy(&Profile_attr) != 0) + { + T2Error("pthread_condattr_destroy failed \n"); + } + return NULL; + } + + if (pthread_condattr_destroy(&Profile_attr) != 0) + { + T2Error("pthread_condattr_destroy failed \n"); + } + while(tProfile->repeat && !tProfile->terminated && tProfile->name) { memset(&_ts, 0, sizeof(struct timespec)); memset(&_now, 0, sizeof(struct timespec)); + if(pthread_mutex_lock(&tProfile->tMutex) != 0) { T2Error("tProfile Mutex lock failed\n"); return NULL; } - clock_gettime(CLOCK_REALTIME, &_now); - //update the timevalues for profiles - _ts.tv_sec = _now.tv_sec; + if( clock_gettime(CLOCK_MONOTONIC, &_now) == -1 ) + { + T2Error("clock_gettime failed\n"); + } + else + { + //update the timevalues for profiles + _ts.tv_sec = _now.tv_sec; + } if(tProfile->timeRef && strcmp(tProfile->timeRef, DEFAULT_TIME_REFERENCE) != 0) { diff --git a/source/t2parser/t2parser.c b/source/t2parser/t2parser.c index a8384e62..b2627464 100644 --- a/source/t2parser/t2parser.c +++ b/source/t2parser/t2parser.c @@ -354,7 +354,8 @@ static T2ERROR addParameter(Profile *profile, const char* name, const char* ref, } gMarker->skipFreq = skipFreq; gMarker->firstSeekFromEOF = firstSeekFromEOF; - if(strncmp("top_log.txt", fileName, sizeof("top_log.txt")) == 0) + + if(fileName != NULL && strncmp("top_log.txt", fileName, sizeof("top_log.txt")) == 0) { T2Debug("This is a TopMarker name :%s and value: %s add it to topmarker list \n", name, ref); Vector_PushBack(profile->topMarkerList, gMarker);