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

Raise an exception if an event signal notifies a failure state on EvtSubscribe #44

Merged
merged 5 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
ruby: [ '3.0', '3.1', '3.2' ]
os:
- ubuntu-latest
name: Ruby ${{ matrix.ruby }} building fat gem testing on ${{ matrix.os }}
Expand Down
2 changes: 2 additions & 0 deletions ext/winevt/winevt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ VALUE rb_cSubscribe;
VALUE rb_eWinevtQueryError;
VALUE rb_eChannelNotFoundError;
VALUE rb_eRemoteHandlerError;
VALUE rb_eSubscribeHandlerError;

static ID id_call;

Expand All @@ -20,6 +21,7 @@ Init_winevt(void)
rb_eWinevtQueryError = rb_define_class_under(rb_cQuery, "Error", rb_eStandardError);
rb_eChannelNotFoundError = rb_define_class_under(rb_cEventLog, "ChannelNotFoundError", rb_eStandardError);
rb_eRemoteHandlerError = rb_define_class_under(rb_cSubscribe, "RemoteHandlerError", rb_eRuntimeError);
rb_eSubscribeHandlerError = rb_define_class_under(rb_cSubscribe, "SubscribeHandlerError", rb_eRuntimeError);

Init_winevt_channel(rb_cEventLog);
Init_winevt_bookmark(rb_cEventLog);
Expand Down
1 change: 1 addition & 0 deletions ext/winevt/winevt_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern VALUE rb_cSubscribe;
extern VALUE rb_eWinevtQueryError;
extern VALUE rb_eChannelNotFoundError;
extern VALUE rb_eRemoteHandlerError;
extern VALUE rb_eSubscribeHandlerError;
extern VALUE rb_cLocale;
extern VALUE rb_cSession;

Expand Down
13 changes: 12 additions & 1 deletion ext/winevt/winevt_subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ rb_winevt_subscribe_subscribe(int argc, VALUE* argv, VALUE self)
struct WinevtSession* winevtSession;
struct WinevtSubscribe* winevtSubscribe;

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

TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
Expand Down Expand Up @@ -341,6 +341,8 @@ rb_winevt_subscribe_next(VALUE self)
EVT_HANDLE hEvents[SUBSCRIBE_ARRAY_SIZE];
ULONG count = 0;
DWORD status = ERROR_SUCCESS;
DWORD dwWait = 0;

struct WinevtSubscribe* winevtSubscribe;

TypedData_Get_Struct(
Expand All @@ -355,6 +357,13 @@ rb_winevt_subscribe_next(VALUE self)
return Qfalse;
}

dwWait = WaitForSingleObject(winevtSubscribe->signalEvent, 0);
cosmo0920 marked this conversation as resolved.
Show resolved Hide resolved
if (dwWait == WAIT_FAILED) {
raise_system_error(rb_eSubscribeHandlerError, GetLastError());
} else if (dwWait != WAIT_OBJECT_0) {
return Qfalse;
}

if (!EvtNext(winevtSubscribe->subscription,
SUBSCRIBE_ARRAY_SIZE,
hEvents,
Expand All @@ -368,6 +377,8 @@ rb_winevt_subscribe_next(VALUE self)
if (ERROR_NO_MORE_ITEMS != status) {
return Qfalse;
}

ResetEvent(winevtSubscribe->signalEvent);
}

if (status == ERROR_SUCCESS) {
Expand Down
Loading