poll-ring.c 952 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: Test poll against ring itself. A buggy kernel will end up
  5. * having io_wq_* workers pending, as the circular reference
  6. * will prevent full exit.
  7. *
  8. */
  9. #include <errno.h>
  10. #include <stdio.h>
  11. #include <unistd.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <poll.h>
  15. #include "liburing.h"
  16. int main(int argc, char *argv[])
  17. {
  18. struct io_uring_sqe *sqe;
  19. struct io_uring ring;
  20. int ret;
  21. if (argc > 1)
  22. return 0;
  23. ret = io_uring_queue_init(1, &ring, 0);
  24. if (ret) {
  25. fprintf(stderr, "child: ring setup failed: %d\n", ret);
  26. return 1;
  27. }
  28. sqe = io_uring_get_sqe(&ring);
  29. if (!sqe) {
  30. fprintf(stderr, "get sqe failed\n");
  31. return 1;
  32. }
  33. io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
  34. io_uring_sqe_set_data(sqe, sqe);
  35. ret = io_uring_submit(&ring);
  36. if (ret <= 0) {
  37. fprintf(stderr, "child: sqe submit failed: %d\n", ret);
  38. return 1;
  39. }
  40. return 0;
  41. }