mheily / libkqueue

kqueue(2) compatibility library
Other
236 stars 77 forks source link

kevent return value incorrect in case of changelist error #108

Closed orbitz closed 3 years ago

orbitz commented 3 years ago

In the case that applying the changelist fails, the return value of of kqueue will be incorrect.

Code section that this applies to:

https://github.com/mheily/libkqueue/blob/master/src/common/kevent.c#L282-L315

The spec states that:

If an error occurs while processing an element of the changelist and there is enough room in the eventlist, then the event will be placed in the eventlist with EV_ERROR set in flags and the system error in data.

This is done correctly in kevent_copyin however line 295 is rv = 0;, kevent then assigns the number of triggered events to rv and finally rv is returned. This means only the number of triggered events is returned rather than the number of failures and triggered events.

I think the fix is quite simple: track number of failures.

I can do the fix, I just want to confirm my analysis is accurate.

mheily commented 3 years ago

I think your analysis is totally correct, and the proposed fix sounds reasonable. Thanks, and looking forward to seeing the PR.