• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Test that we exit properly with SQPOLL and having a request that
4  * adds a circular reference to the ring itself.
5  */
6 #include <errno.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <sys/time.h>
11 #include <poll.h>
12 #include "liburing.h"
13 #include "helpers.h"
14 
main(int argc,char * argv[])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 
23 	if (argc > 1)
24 		return 0;
25 
26 	p.flags = IORING_SETUP_SQPOLL;
27 	p.sq_thread_idle = 100;
28 
29 	ret = io_uring_queue_init_params(1, &ring, &p);
30 	if (ret) {
31 		if (geteuid()) {
32 			printf("%s: skipped, not root\n", argv[0]);
33 			return 0;
34 		}
35 		fprintf(stderr, "queue_init=%d\n", ret);
36 		return 1;
37 	}
38 
39 	if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) {
40 		fprintf(stdout, "Skipping\n");
41 		return 0;
42 	}
43 
44 	sqe = io_uring_get_sqe(&ring);
45 	io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
46 	io_uring_submit(&ring);
47 
48 	gettimeofday(&tv, NULL);
49 	do {
50 		usleep(1000);
51 	} while (mtime_since_now(&tv) < 1000);
52 
53 	return 0;
54 }
55