Closed orbitz closed 3 years ago
Have you got a reference for this behaviour?
The man pages on both macOS and FreeBSD have the following:
The kevent() system call returns the number of events placed in the
eventlist, up to the value given by nevents. 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. Otherwise, -1 will be re-
turned, and errno will be set to indicate the error condition. If the
time limit expires, then kevent() returns 0.
What's not really clear is the behaviour if insufficient space is available. I'd guess kevent
would return with event list only partially processed.
@arr2036 the behaviour is specified in the portion you quoted. But, your comment made me look over the code again and I realize I made a mistake which I have just fixed. I only update the kevent return value if kevent succeeded.
@orbitz overall I agree with the change, but there were multiple other (pre-existing) errors in the code. Changing the return code on its own wasn't enough. This change would have lead to the caller reading uninitialised struct kevent
entries as the pointer passed into kevent_copyout
wasn't advanced by the number of entries added by kevent_copyin
.
kevent_copyin
also failed to set the EV_ERROR flag in the kevents it produced, which is required for EV_RECEIPT
and if an error occurs.
Addresses issue #108