-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Cppcheck/v1 #11946
Cppcheck/v1 #11946
Changes from all commits
0b259cd
0a5de98
80ed2e3
8cd1d31
c245e70
bd72dc0
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 |
---|---|---|
|
@@ -2075,7 +2075,7 @@ typedef struct Thread_ { | |
|
||
SCTime_t pktts; /**< current packet time of this thread | ||
* (offline mode) */ | ||
uint32_t sys_sec_stamp; /**< timestamp in seconds of the real system | ||
SCTime_t sys_sec_stamp; /**< timestamp in real system | ||
* time when the pktts was last updated. */ | ||
} Thread; | ||
|
||
|
@@ -2199,14 +2199,24 @@ void TmThreadsSetThreadTimestamp(const int id, const SCTime_t ts) | |
int idx = id - 1; | ||
Thread *t = &thread_store.threads[idx]; | ||
t->pktts = ts; | ||
struct timeval systs; | ||
gettimeofday(&systs, NULL); | ||
t->sys_sec_stamp = (uint32_t)systs.tv_sec; | ||
struct timeval tv; | ||
gettimeofday(&tv, NULL); | ||
SCTime_t now = SCTIME_FROM_TIMEVAL(&tv); | ||
|
||
if (t->sys_sec_stamp.secs != 0) { | ||
SCTime_t tmpts = SCTIME_ADD_SECS(t->sys_sec_stamp, 3); | ||
if (SCTIME_CMP_LT(tmpts, now)) { | ||
SCLogNotice("%s: thread slept for %u secs", t->name, (uint32_t)(now.secs - tmpts.secs)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure actually, it's not necessarily an issue. In a large pcap that starts with a single flow you might see this once packets for other flows are processed. I'll turn it into debug for now. |
||
} | ||
} | ||
|
||
t->sys_sec_stamp = SCTIME_FROM_TIMEVAL(&tv); | ||
SCMutexUnlock(&thread_store_lock); | ||
} | ||
|
||
bool TmThreadsTimeSubsysIsReady(void) | ||
{ | ||
static SCTime_t nullts; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
bool ready = true; | ||
SCMutexLock(&thread_store_lock); | ||
for (size_t s = 0; s < thread_store.threads_size; s++) { | ||
|
@@ -2215,7 +2225,7 @@ bool TmThreadsTimeSubsysIsReady(void) | |
break; | ||
if (t->type != TVT_PPT) | ||
continue; | ||
if (t->sys_sec_stamp == 0) { | ||
if (SCTIME_CMP_EQ(t->sys_sec_stamp, nullts)) { | ||
ready = false; | ||
break; | ||
} | ||
|
@@ -2236,19 +2246,20 @@ void TmThreadsInitThreadsTimestamp(const SCTime_t ts) | |
if (t->type != TVT_PPT) | ||
continue; | ||
t->pktts = ts; | ||
t->sys_sec_stamp = (uint32_t)systs.tv_sec; | ||
t->sys_sec_stamp = SCTIME_FROM_TIMEVAL(&systs); | ||
} | ||
SCMutexUnlock(&thread_store_lock); | ||
} | ||
|
||
void TmThreadsGetMinimalTimestamp(struct timeval *ts) | ||
{ | ||
struct timeval local = { 0 }; | ||
static struct timeval nullts; | ||
static SCTime_t nullts; | ||
bool set = false; | ||
size_t s; | ||
struct timeval systs; | ||
gettimeofday(&systs, NULL); | ||
struct timeval tv; | ||
gettimeofday(&tv, NULL); | ||
SCTime_t systs = SCTIME_FROM_TIMEVAL(&tv); | ||
|
||
SCMutexLock(&thread_store_lock); | ||
for (s = 0; s < thread_store.threads_size; s++) { | ||
|
@@ -2258,11 +2269,10 @@ void TmThreadsGetMinimalTimestamp(struct timeval *ts) | |
/* only packet threads set timestamps based on packets */ | ||
if (t->type != TVT_PPT) | ||
continue; | ||
struct timeval pkttv = { .tv_sec = SCTIME_SECS(t->pktts), | ||
.tv_usec = SCTIME_USECS(t->pktts) }; | ||
if (!(timercmp(&pkttv, &nullts, ==))) { | ||
if (SCTIME_CMP_NEQ(t->pktts, nullts)) { | ||
SCTime_t sys_sec_stamp = SCTIME_ADD_SECS(t->sys_sec_stamp, 1); | ||
/* ignore sleeping threads */ | ||
if (t->sys_sec_stamp + 1 < (uint32_t)systs.tv_sec) | ||
if (SCTIME_CMP_LT(sys_sec_stamp, systs)) | ||
continue; | ||
|
||
if (!set) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ typedef struct VarNameStore_ { | |
HashListTable *names; | ||
HashListTable *ids; | ||
uint32_t max_id; | ||
struct timeval free_after; | ||
SCTime_t free_after; | ||
TAILQ_ENTRY(VarNameStore_) next; | ||
} VarNameStore; | ||
typedef VarNameStore *VarNameStorePtr; | ||
|
@@ -260,13 +260,11 @@ int VarNameStoreActivate(void) | |
if (new_active) { | ||
VarNameStore *old_active = SC_ATOMIC_GET(active); | ||
if (old_active) { | ||
struct timeval ts, add; | ||
struct timeval ts; | ||
memset(&ts, 0, sizeof(ts)); | ||
memset(&add, 0, sizeof(add)); | ||
gettimeofday(&ts, NULL); | ||
add.tv_sec = 60; | ||
timeradd(&ts, &add, &ts); | ||
old_active->free_after = ts; | ||
SCTime_t free_after = SCTIME_ADD_SECS(SCTIME_FROM_TIMEVAL(&ts), 60); | ||
old_active->free_after = free_after; | ||
|
||
TAILQ_INSERT_TAIL(&free_list, old_active, next); | ||
SCLogDebug("old active is stored in free list"); | ||
|
@@ -275,16 +273,17 @@ int VarNameStoreActivate(void) | |
SC_ATOMIC_SET(active, new_active); | ||
SCLogDebug("new store active"); | ||
|
||
struct timeval now; | ||
memset(&now, 0, sizeof(now)); | ||
gettimeofday(&now, NULL); | ||
struct timeval tv; | ||
memset(&tv, 0, sizeof(tv)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have it in other places, see
However I agree it's probably not needed as there are many more places were it's not done. Not sure how I developed this as a half baked pattern. |
||
gettimeofday(&tv, NULL); | ||
SCTime_t now = SCTIME_FROM_TIMEVAL(&tv); | ||
|
||
VarNameStore *s = NULL; | ||
while ((s = TAILQ_FIRST(&free_list))) { | ||
char timebuf[64]; | ||
CreateIsoTimeString(SCTIME_FROM_TIMEVAL(&s->free_after), timebuf, sizeof(timebuf)); | ||
CreateIsoTimeString(s->free_after, timebuf, sizeof(timebuf)); | ||
|
||
if (!timercmp(&now, &s->free_after, >)) { | ||
if (SCTIME_CMP_LTE(now, s->free_after)) { | ||
SCLogDebug("not yet freeing store %p before %s", s, timebuf); | ||
break; | ||
} | ||
|
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.
Is there a reason for using ~4 seconds == long time?
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.
it's ore a left over of some debugging where I wanted to know the effect of inactive threads on the timestamp the FM used. Turned it into debug.