1 /* SPDX-License-Identifier: GPL-2.0 */
11 #include <linux/sched.h>
12 #include <linux/types.h>
13 #include <sys/syscall.h>
16 #include "../kselftest.h"
17 #include "clone3_selftests.h"
19 static void nop_handler(int signo
)
23 static int wait_for_pid(pid_t pid
)
28 ret
= waitpid(pid
, &status
, 0);
36 if (!WIFEXITED(status
))
39 return WEXITSTATUS(status
);
42 static void test_clone3_clear_sighand(void)
46 struct __clone_args args
= {};
50 * Check that CLONE_CLEAR_SIGHAND and CLONE_SIGHAND are mutually
53 args
.flags
|= CLONE_CLEAR_SIGHAND
| CLONE_SIGHAND
;
54 args
.exit_signal
= SIGCHLD
;
55 pid
= sys_clone3(&args
, sizeof(args
));
58 "clone3(CLONE_CLEAR_SIGHAND | CLONE_SIGHAND) succeeded\n");
60 act
.sa_handler
= nop_handler
;
61 ret
= sigemptyset(&act
.sa_mask
);
63 ksft_exit_fail_msg("%s - sigemptyset() failed\n",
68 /* Register signal handler for SIGUSR1 */
69 ret
= sigaction(SIGUSR1
, &act
, NULL
);
72 "%s - sigaction(SIGUSR1, &act, NULL) failed\n",
75 /* Register signal handler for SIGUSR2 */
76 ret
= sigaction(SIGUSR2
, &act
, NULL
);
79 "%s - sigaction(SIGUSR2, &act, NULL) failed\n",
82 /* Check that CLONE_CLEAR_SIGHAND works. */
83 args
.flags
= CLONE_CLEAR_SIGHAND
;
84 pid
= sys_clone3(&args
, sizeof(args
));
86 ksft_exit_fail_msg("%s - clone3(CLONE_CLEAR_SIGHAND) failed\n",
90 ret
= sigaction(SIGUSR1
, NULL
, &act
);
94 if (act
.sa_handler
!= SIG_DFL
)
97 ret
= sigaction(SIGUSR2
, NULL
, &act
);
101 if (act
.sa_handler
!= SIG_DFL
)
107 ret
= wait_for_pid(pid
);
110 "Failed to clear signal handler for child process\n");
112 ksft_test_result_pass("Cleared signal handlers for child process\n");
115 int main(int argc
, char **argv
)
119 test_clone3_supported();
121 test_clone3_clear_sighand();