mirror of
https://github.com/torvalds/linux.git
synced 2026-04-22 08:44:02 -04:00
This follow-up patch completes centralization of kselftest.h and ksefltest_harness.h includes in remaining seltests files, replacing all relative paths with a non-relative paths using shared -I include path in lib.mk Tested with gcc-13.3 and clang-18.1, and cross-compiled successfully on riscv, arm64, x86_64 and powerpc arch. [reddybalavignesh9979@gmail.com: add selftests include path for kselftest.h] Link: https://lkml.kernel.org/r/20251017090201.317521-1-reddybalavignesh9979@gmail.com Link: https://lkml.kernel.org/r/20251016104409.68985-1-reddybalavignesh9979@gmail.com Signed-off-by: Bala-Vignesh-Reddy <reddybalavignesh9979@gmail.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Link: https://lore.kernel.org/lkml/20250820143954.33d95635e504e94df01930d0@linux-foundation.org/ Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Cc: David Hildenbrand <david@redhat.com> Cc: David S. Miller <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Günther Noack <gnoack@google.com> Cc: Jakub Kacinski <kuba@kernel.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Mickael Salaun <mic@digikod.net> Cc: Ming Lei <ming.lei@redhat.com> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Simon Horman <horms@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
125 lines
2.5 KiB
C
125 lines
2.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#define _GNU_SOURCE
|
|
#include <errno.h>
|
|
#include <sched.h>
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/types.h>
|
|
#include <sys/syscall.h>
|
|
#include <sys/wait.h>
|
|
|
|
#include "kselftest.h"
|
|
#include "clone3_selftests.h"
|
|
|
|
static void nop_handler(int signo)
|
|
{
|
|
}
|
|
|
|
static int wait_for_pid(pid_t pid)
|
|
{
|
|
int status, ret;
|
|
|
|
again:
|
|
ret = waitpid(pid, &status, 0);
|
|
if (ret == -1) {
|
|
if (errno == EINTR)
|
|
goto again;
|
|
|
|
return -1;
|
|
}
|
|
|
|
if (!WIFEXITED(status))
|
|
return -1;
|
|
|
|
return WEXITSTATUS(status);
|
|
}
|
|
|
|
static void test_clone3_clear_sighand(void)
|
|
{
|
|
int ret;
|
|
pid_t pid;
|
|
struct __clone_args args = {};
|
|
struct sigaction act;
|
|
|
|
/*
|
|
* Check that CLONE_CLEAR_SIGHAND and CLONE_SIGHAND are mutually
|
|
* exclusive.
|
|
*/
|
|
args.flags |= CLONE_CLEAR_SIGHAND | CLONE_SIGHAND;
|
|
args.exit_signal = SIGCHLD;
|
|
pid = sys_clone3(&args, sizeof(args));
|
|
if (pid > 0)
|
|
ksft_exit_fail_msg(
|
|
"clone3(CLONE_CLEAR_SIGHAND | CLONE_SIGHAND) succeeded\n");
|
|
|
|
act.sa_handler = nop_handler;
|
|
ret = sigemptyset(&act.sa_mask);
|
|
if (ret < 0)
|
|
ksft_exit_fail_msg("%s - sigemptyset() failed\n",
|
|
strerror(errno));
|
|
|
|
act.sa_flags = 0;
|
|
|
|
/* Register signal handler for SIGUSR1 */
|
|
ret = sigaction(SIGUSR1, &act, NULL);
|
|
if (ret < 0)
|
|
ksft_exit_fail_msg(
|
|
"%s - sigaction(SIGUSR1, &act, NULL) failed\n",
|
|
strerror(errno));
|
|
|
|
/* Register signal handler for SIGUSR2 */
|
|
ret = sigaction(SIGUSR2, &act, NULL);
|
|
if (ret < 0)
|
|
ksft_exit_fail_msg(
|
|
"%s - sigaction(SIGUSR2, &act, NULL) failed\n",
|
|
strerror(errno));
|
|
|
|
/* Check that CLONE_CLEAR_SIGHAND works. */
|
|
args.flags = CLONE_CLEAR_SIGHAND;
|
|
pid = sys_clone3(&args, sizeof(args));
|
|
if (pid < 0)
|
|
ksft_exit_fail_msg("%s - clone3(CLONE_CLEAR_SIGHAND) failed\n",
|
|
strerror(errno));
|
|
|
|
if (pid == 0) {
|
|
ret = sigaction(SIGUSR1, NULL, &act);
|
|
if (ret < 0)
|
|
exit(EXIT_FAILURE);
|
|
|
|
if (act.sa_handler != SIG_DFL)
|
|
exit(EXIT_FAILURE);
|
|
|
|
ret = sigaction(SIGUSR2, NULL, &act);
|
|
if (ret < 0)
|
|
exit(EXIT_FAILURE);
|
|
|
|
if (act.sa_handler != SIG_DFL)
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
ret = wait_for_pid(pid);
|
|
if (ret)
|
|
ksft_exit_fail_msg(
|
|
"Failed to clear signal handler for child process\n");
|
|
|
|
ksft_test_result_pass("Cleared signal handlers for child process\n");
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
ksft_print_header();
|
|
ksft_set_plan(1);
|
|
test_clone3_supported();
|
|
|
|
test_clone3_clear_sighand();
|
|
|
|
ksft_exit_pass();
|
|
}
|