[LTP] [PATCH 5/5] libs/sigwait: Use safe/test macros

Petr Vorel pvorel@suse.cz
Thu Nov 14 15:40:29 CET 2024


Simplify code with SAFE_SIGPROCMASK(), TST_EXP_FAIL().

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 libs/sigwait/sigwait.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/libs/sigwait/sigwait.c b/libs/sigwait/sigwait.c
index cf3c445b4a..a9fd62d73c 100644
--- a/libs/sigwait/sigwait.c
+++ b/libs/sigwait/sigwait.c
@@ -286,9 +286,7 @@ void test_bad_address(swi_func sigwaitinfo, int signo,
 	/* let's not get interrupted by our dying child */
 	SAFE_SIGADDSET(&sigs, SIGCHLD);
 
-	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
+	SAFE_SIGPROCMASK(SIG_SETMASK, &sigs, &oldmask);
 
 	/* don't wait on a SIGCHLD */
 	SAFE_SIGDELSET(&sigs, SIGCHLD);
@@ -296,19 +294,8 @@ void test_bad_address(swi_func sigwaitinfo, int signo,
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, 1, 0);
 
-	TEST(sigwaitinfo(&sigs, (void *)1, NULL));
-	if (TST_RET == -1) {
-		if (TST_ERR == EFAULT)
-			tst_res(TPASS, "Fault occurred while accessing the buffers");
-		else
-			tst_res(TFAIL | TTERRNO, "Expected error number EFAULT, got");
-	} else {
-		tst_res(TFAIL, "Expected return value -1, got: %ld", TST_RET);
-	}
-
-	TEST(sigprocmask(SIG_SETMASK, &oldmask, NULL));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
+	TST_EXP_FAIL(sigwaitinfo(&sigs, (void *)1, NULL), EFAULT);
+	SAFE_SIGPROCMASK(SIG_SETMASK, &oldmask, NULL);
 
 	SAFE_KILL(child, SIGTERM);
 	SAFE_WAIT(NULL);
-- 
2.45.2



More information about the ltp mailing list