On 20/03/2023 11:12, Amit Daniel Kachhap wrote:
In many instances waitid() syscall is used only to wait for the child process to exit and syscall out parameters struct siginfo and rusage are not used.
Introduce and utilize the lightweight waitpid() syscall which suit best
s/suit/suits/
in such instances.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@arm.com
tools/testing/selftests/arm64/morello/clone.c | 6 +++--- .../selftests/arm64/morello/freestanding.h | 5 +++++ tools/testing/selftests/arm64/morello/signal.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/arm64/morello/clone.c b/tools/testing/selftests/arm64/morello/clone.c index a511054f90fa..0381702ab0fc 100644 --- a/tools/testing/selftests/arm64/morello/clone.c +++ b/tools/testing/selftests/arm64/morello/clone.c @@ -398,7 +398,7 @@ void run_clone3(struct clone3_fixture *data) struct clone_args *args = &(data->args); int pidfd, parent_tid = 0, child_tid = 0; siginfo_t wait_si;
- int result;
- int result, wstatus; pid_t pid; void *tls = NULL;
@@ -461,8 +461,8 @@ void run_clone3(struct clone3_fixture *data) ASSERT_EQ(result, 0); }
- result = waitid(P_PID, pid, &wait_si, WEXITED, NULL);
- ASSERT_EQ(result, 0);
- result = waitpid(pid, &wstatus, 0);
The second argument can be NULL since we don't actually use wstatus.
Kevin
- ASSERT_EQ(result, pid);
/* child_tid set once the thread gets scheduled */ if (args->flags & CLONE_PARENT_SETTID && args->flags & CLONE_CHILD_SETTID diff --git a/tools/testing/selftests/arm64/morello/freestanding.h b/tools/testing/selftests/arm64/morello/freestanding.h index 19611b315de9..0b0de05d46bc 100644 --- a/tools/testing/selftests/arm64/morello/freestanding.h +++ b/tools/testing/selftests/arm64/morello/freestanding.h @@ -213,4 +213,9 @@ static inline int waitid(int id_type, pid_t id, siginfo_t *info, int options, st return syscall(__NR_waitid, id_type, id, info, options, ru); } +static inline int waitpid(pid_t pid, int *wstatus, int options) +{
- return syscall(__NR_wait4, pid, wstatus, options, 0);
+}
#endif diff --git a/tools/testing/selftests/arm64/morello/signal.c b/tools/testing/selftests/arm64/morello/signal.c index 3dcea434275c..3108755d9ed7 100644 --- a/tools/testing/selftests/arm64/morello/signal.c +++ b/tools/testing/selftests/arm64/morello/signal.c @@ -302,10 +302,10 @@ TEST(test_rt_sigqueueinfo) TEST(test_rt_tgsigqueueinfo) {
- siginfo_t si, wait_si;
- siginfo_t si; pid_t cpid; struct sigaction sa;
- int ret;
- int ret, wstatus;
setup_sigusr1_handler(&sa, SIG_UNBLOCK); @@ -324,17 +324,17 @@ TEST(test_rt_tgsigqueueinfo) ASSERT_EQ(ret, 0) { __TH_LOG_ERROR("rt_tgsigqueueinfo syscall failed"); }
- ret = waitid(P_PID, cpid, &wait_si, WEXITED, NULL);
- ASSERT_EQ(ret, 0) {
- ret = waitpid(cpid, &wstatus, 0);
- ASSERT_EQ(ret, cpid) { __TH_LOG_ERROR("test_rt_tgsigqueueinfo: Failed on wait"); }
} TEST(test_pidfd_send_signal) {
- siginfo_t si, wait_si;
- siginfo_t si; pid_t cpid;
- int pidfd, ret;
- int pidfd, ret, wstatus; struct sigaction sa;
setup_sigusr1_handler(&sa, SIG_UNBLOCK); @@ -364,8 +364,8 @@ TEST(test_pidfd_send_signal) ASSERT_EQ(ret, 0) { __TH_LOG_ERROR("pidfd_send_signal syscall failed"); }
- ret = waitid(P_PID, cpid, &wait_si, WEXITED, NULL);
- ASSERT_EQ(ret, 0) {
- ret = waitpid(cpid, &wstatus, 0);
- ASSERT_EQ(ret, cpid) { __TH_LOG_ERROR("test_pidfd_send_signal: Failed on wait"); } close(pidfd);