sqpoll-exit-hang.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Test that we exit properly with SQPOLL and having a request that
  5. * adds a circular reference to the ring itself.
  6. */
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <sys/time.h>
  12. #include <poll.h>
  13. #include "liburing.h"
  14. #include "helpers.h"
  15. int main(int argc, char *argv[])
  16. {
  17. struct io_uring_params p = {};
  18. struct timeval tv;
  19. struct io_uring ring;
  20. struct io_uring_sqe *sqe;
  21. int ret;
  22. if (argc > 1)
  23. return 0;
  24. p.flags = IORING_SETUP_SQPOLL;
  25. p.sq_thread_idle = 100;
  26. ret = io_uring_queue_init_params(1, &ring, &p);
  27. if (ret) {
  28. if (geteuid()) {
  29. printf("%s: skipped, not root\n", argv[0]);
  30. return 0;
  31. }
  32. fprintf(stderr, "queue_init=%d\n", ret);
  33. return 1;
  34. }
  35. if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) {
  36. fprintf(stdout, "Skipping\n");
  37. return 0;
  38. }
  39. sqe = io_uring_get_sqe(&ring);
  40. io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
  41. io_uring_submit(&ring);
  42. gettimeofday(&tv, NULL);
  43. do {
  44. usleep(1000);
  45. } while (mtime_since_now(&tv) < 1000);
  46. return 0;
  47. }