Răsfoiți Sursa

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>
Jan Friesse 5 ani în urmă
părinte
comite
07a7e8a7ab
2 a modificat fișierele cu 17 adăugiri și 1 ștergeri
  1. 1 1
      qdevices/pr-poll-loop.c
  2. 16 0
      qdevices/test-pr-poll-loop.c

+ 1 - 1
qdevices/pr-poll-loop.c

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

+ 16 - 0
qdevices/test-pr-poll-loop.c

@@ -523,6 +523,22 @@ test_fd_basics(struct pr_poll_loop *poll_loop)
 	assert(fd_set_events_cb1_return_called == 1);
 	assert(fd_set_events_cb1_return_called == 1);
 	timer_list_delete(pr_poll_loop_get_timer_list(poll_loop), timeout_timer);
 	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
 	 * Remove entry and try different cb
 	 */
 	 */