Skip to content
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

in_winevtlog: Display error on invalid subscription state #8544

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. err code = %d", GetLastError());
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
Loading