MCPcopy Create free account
hub / github.com/axboe/liburing / test_exec

Function test_exec

test/sqpoll-exec.c:34–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34static int test_exec(struct io_uring *ring, char * const argv[])
35{
36 char prog_path[PATH_MAX];
37 struct io_uring_sqe *sqe;
38 struct io_uring_cqe *cqe;
39 int ret, wstatus, fd;
40 pid_t p;
41
42 if (fill_exec_target(prog_path, "./exec-target.t") &&
43 fill_exec_target(prog_path, "test/exec-target.t")) {
44 fprintf(stdout, "Can't find exec-target, skipping\n");
45 return 0;
46 }
47
48 sqe = io_uring_get_sqe(ring);
49 io_uring_prep_openat(sqe, AT_FDCWD, prog_path, O_WRONLY, 0);
50 sqe->user_data = 0;
51
52 io_uring_submit(ring);
53
54 ret = io_uring_wait_cqe(ring, &cqe);
55 if (ret) {
56 fprintf(stderr, "wait cqe %d\n", ret);
57 return 1;
58 }
59 if (cqe->res < 0) {
60 fprintf(stderr, "open: %d\n", cqe->res);
61 return 1;
62 }
63 fd = cqe->res;
64 io_uring_cqe_seen(ring, cqe);
65
66 sqe = io_uring_get_sqe(ring);
67 io_uring_prep_close(sqe, fd);
68 sqe->user_data = 1;
69
70 io_uring_submit(ring);
71
72 ret = io_uring_wait_cqe(ring, &cqe);
73 if (ret) {
74 fprintf(stderr, "wait cqe %d\n", ret);
75 return 1;
76 }
77 if (cqe->res < 0) {
78 fprintf(stderr, "close: %d\n", cqe->res);
79 return 1;
80 }
81 io_uring_cqe_seen(ring, cqe);
82
83 p = fork();
84 if (p == -1) {
85 fprintf(stderr, "fork() failed\n");
86 return 1;
87 }
88
89 if (p == 0) {
90 /* file should be closed, try exec'ing it */
91 ret = execve(prog_path, argv, NULL);

Callers 1

mainFunction · 0.70

Calls 3

io_uring_submitFunction · 0.85
fill_exec_targetFunction · 0.70
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected