pr-poll-loop: Fix set_events_cb return code

When events is set to 0 and set_events return -2 it was changed to -1.
Solution is to check, if return code was 0 and only if so, change return
code to -1 if events is 0.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
This commit is contained in:
Jan Friesse 2020-08-31 10:08:45 +02:00
parent 6bf5f6c011
commit 07a7e8a7ab
2 changed files with 17 additions and 1 deletions

View File

@ -338,7 +338,7 @@ int prepare_poll_array(struct pr_poll_loop *poll_loop)
return (-2);
}
if (events == 0) {
if (res == 0 && events == 0) {
/*
* Empty events -> do not add entry
*/

View File

@ -523,6 +523,22 @@ test_fd_basics(struct pr_poll_loop *poll_loop)
assert(fd_set_events_cb1_return_called == 1);
timer_list_delete(pr_poll_loop_get_timer_list(poll_loop), timeout_timer);
/*
* Remove entry and try with zero events and -2 return callback
*/
assert(pr_poll_loop_del_fd(poll_loop, pipe_fd1[0]) == 0);
assert(pr_poll_loop_add_fd(poll_loop, pipe_fd1[0], 0, fd_set_events_cb1_return,
NULL, NULL, NULL, (void *)&fd_set_events_cb1_return_called, NULL) == 0);
fd_set_events_cb1_return_called = 0;
assert((timeout_timer = timer_list_add(
pr_poll_loop_get_timer_list(poll_loop), TIMER_TIMEOUT, timeout_cb, NULL, NULL)) != NULL);
assert(pr_poll_loop_exec(poll_loop) == -1);
assert(fd_set_events_cb1_return_called == 1);
timer_list_delete(pr_poll_loop_get_timer_list(poll_loop), timeout_timer);
/*
* Remove entry and try different cb
*/