-
Notifications
You must be signed in to change notification settings - Fork 18
Topic/delia 69767 #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Topic/delia 69767 #225
Changes from all commits
414b6ea
297b0a9
597a786
cccb5a6
f2712f9
7b8118a
ccd5469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ; | ||
|
|
||
|
|
@@ -85,13 +84,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; | ||
| } | ||
|
|
||
| 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,8 +325,9 @@ void *cacheEventToFile(void *arg) | |
| fl.l_len = 0; | ||
| fl.l_pid = 0; | ||
| FILE *fs = NULL; | ||
| char path[100]; | ||
| 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) | ||
| { | ||
|
|
@@ -353,12 +363,25 @@ 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) | ||
|
|
||
| fs = fopen(T2_CACHE_FILE, "r"); | ||
| if (fs != NULL) | ||
| { | ||
| fgets(path, 100, fs); | ||
| count = atoi ( path ); | ||
| pclose(fs); | ||
| 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) | ||
| { | ||
| count++; | ||
| } | ||
| fclose(fs); | ||
| fs = NULL; | ||
| } | ||
| if(count < MAX_EVENT_CACHE) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snprintf call builds on top of the existing string in timeBuffer by using
strlen(timeBuffer)as the offset. While this works, it's more fragile than necessary. Consider using a single snprintf call with a combined format string, or at minimum verify the return value from strftime to ensure it succeeded before appending.