1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/types.h>
17 #include "../kselftest.h"
21 static void handle_alarm(int sig
)
26 int main(int argc
, char **argv
)
30 int nr_iterations
= 10000;
35 ksft_exit_fail_msg("Unexpected command line argument\n");
38 nr_iterations
= atoi(argv
[1]);
39 if (nr_iterations
<= 0)
40 ksft_exit_fail_msg("invalid input parameter %s\n",
44 ksft_print_msg("running pidfd poll test for %d iterations\n",
47 for (iter
= 0; iter
< nr_iterations
; iter
++) {
49 int child_pid
= fork();
52 if (errno
== EAGAIN
) {
57 "%s - failed to fork a child process\n",
62 /* Child process just sleeps for a min and exits */
67 /* Parent kills the child and waits for its death */
68 pidfd
= sys_pidfd_open(child_pid
, 0);
70 ksft_exit_fail_msg("%s - pidfd_open failed\n",
73 /* Setup 3 sec alarm - plenty of time */
74 if (signal(SIGALRM
, handle_alarm
) == SIG_ERR
)
75 ksft_exit_fail_msg("%s - signal failed\n",
79 /* Send SIGKILL to the child */
80 if (sys_pidfd_send_signal(pidfd
, SIGKILL
, NULL
, 0))
81 ksft_exit_fail_msg("%s - pidfd_send_signal failed\n",
84 /* Wait for the death notification */
86 nevents
= poll(&fds
, 1, -1);
88 /* Check for error conditions */
90 ksft_exit_fail_msg("%s - poll failed\n",
94 ksft_exit_fail_msg("unexpected poll result: %d\n",
97 if (!(fds
.revents
& POLLIN
))
99 "unexpected event type received: 0x%x\n",
104 "death notification wait timeout\n");
107 /* Wait for child to prevent zombies */
108 if (waitpid(child_pid
, NULL
, 0) < 0)
109 ksft_exit_fail_msg("%s - waitpid failed\n",
114 ksft_test_result_pass("pidfd poll test: pass\n");