Skip to content

Commit

Permalink
in_winevtlog: Display error on invalid subscription state
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Mar 2, 2024
1 parent 9d9ac68 commit 271fcc3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plugins/in_winevtlog/winevtlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct winevtlog_channel *winevtlog_subscribe(const char *channel, int read_exis
}
ch->query = NULL;

signal_event = CreateEvent(NULL, FALSE, FALSE, NULL);
signal_event = CreateEvent(NULL, TRUE, TRUE, NULL);

// channel : To wide char
len = MultiByteToWideChar(CP_UTF8, 0, channel, -1, NULL, 0);
Expand Down Expand Up @@ -492,6 +492,7 @@ static int winevtlog_next(struct winevtlog_channel *ch, int hit_threshold)
DWORD status = ERROR_SUCCESS;
BOOL has_next = FALSE;
int i;
DWORD wait = 0;

/* If subscription handle is NULL, it should return false. */
if (!ch->subscription) {
Expand All @@ -503,6 +504,15 @@ static int winevtlog_next(struct winevtlog_channel *ch, int hit_threshold)
return FLB_FALSE;
}

wait = WaitForSingleObject(ch->signal_event, 0);
if (wait == WAIT_FAILED) {
flb_error("subscription is invalid");
return FLB_FALSE;
}
else if (wait != WAIT_OBJECT_0) {
return FLB_FALSE;
}

has_next = EvtNext(ch->subscription, SUBSCRIBE_ARRAY_SIZE,
events, INFINITE, 0, &count);

Expand All @@ -514,6 +524,8 @@ static int winevtlog_next(struct winevtlog_channel *ch, int hit_threshold)
if (ERROR_NO_MORE_ITEMS != status) {
return FLB_FALSE;
}

ResetEvent(ch->signal_event);
}

if (status == ERROR_SUCCESS) {
Expand Down

0 comments on commit 271fcc3

Please sign in to comment.