Skip to contentSkip to conversation

syscalls: Add missing WEXITSTATUS() check

PATCH In review Petr Vorel 2 participants 5 messages Nov 11, 2024 – Nov 12, 2024

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 syscalls: Add missing WEXITSTATUS() check

---
I haven't found any other test which would need it.

 testcases/kernel/syscalls/madvise/madvise08.c | 2 +-
 testcases/kernel/syscalls/select/select03.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/madvise/madvise08.c +1 -1
index 96bcaf159a..cd5ce722a5 100644
@@ -173,7 +173,7 @@ static pid_t run_child(int advice)
 	SAFE_WAITPID(pid, &status, 0);
 	if (WIFSIGNALED(status) && WCOREDUMP(status))
 		return pid;
-	if (WIFEXITED(status))
+	if (WIFEXITED(status) && !WEXITSTATUS(status))
 		return 0;
 
 	tst_res(TCONF, "No coredump produced after signal (%d)",
testcases/kernel/syscalls/select/select03.c +1 -1
index 1cec3a4c76..216b22104f 100644
@@ -77,7 +77,7 @@ static void run(unsigned int n)
 
 	SAFE_WAITPID(pid, &status, 0);
 
-	if (WIFEXITED(status))
+	if (WIFEXITED(status) && !WEXITSTATUS(status))
 		return;
 
 	if (tst_variant == GLIBC_SELECT_VARIANT &&
Signature · 5 lines
2.45.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 12 lines

---
I haven't found any other test which would need it.

 testcases/kernel/syscalls/madvise/madvise08.c | 2 +-
 testcases/kernel/syscalls/select/select03.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/madvise/madvise08.c +0 -0
index 96bcaf159a..cd5ce722a5 100644

testcases/kernel/syscalls/madvise/madvise08.c static pid_t run_child(int advice) · line 179

Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise08.c +1 -1
@@ -173,7 +173,7 @@ static pid_t run_child(int advice)
 	SAFE_WAITPID(pid, &status, 0);
 	if (WIFSIGNALED(status) && WCOREDUMP(status))
 		return pid;
-	if (WIFEXITED(status))
+	if (WIFEXITED(status) && !WEXITSTATUS(status))
 		return 0;
 
 	tst_res(TCONF, "No coredump produced after signal (%d)",

This one is not complete. We do exit(1) if madvise fails that would be previously caught here so we have to add:

testcases/kernel/syscalls/madvise/madvise08.c +1 -1
index 96bcaf159..f8f74ef4f 100644
@@ -165,7 +165,7 @@ static pid_t run_child(int advice)
                                fmem,
                                FMEMSIZE,
                                advstr);
-                       exit(1);
+                       exit(0);
                }
                abort();
        }
Quoted 16 lines
testcases/kernel/syscalls/select/select03.c +1 -1
index 1cec3a4c76..216b22104f 100644
@@ -77,7 +77,7 @@ static void run(unsigned int n)
 
 	SAFE_WAITPID(pid, &status, 0);
 
-	if (WIFEXITED(status))
+	if (WIFEXITED(status) && !WEXITSTATUS(status))
 		return;
 
 	if (tst_variant == GLIBC_SELECT_VARIANT &&
Signature · 1 line
2.45.2
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw

Hi Cyril,

Quoted 19 lines

Review static pid_t run_child(int advice) · line 179

Quoted 10 lines

+++ b/testcases/kernel/syscalls/madvise/madvise08.c

(quoted diff) +1 -1
@@ -173,7 +173,7 @@ static pid_t run_child(int advice)
 	SAFE_WAITPID(pid, &status, 0);
 	if (WIFSIGNALED(status) && WCOREDUMP(status))
 		return pid;
-	if (WIFEXITED(status))
+	if (WIFEXITED(status) && !WEXITSTATUS(status))
 		return 0;
 
 	tst_res(TCONF, "No coredump produced after signal (%d)",

This one is not complete. We do exit(1) if madvise fails that would be previously caught here so we have to add:

testcases/kernel/syscalls/madvise/madvise08.c +0 -0
index 96bcaf159..f8f74ef4f 100644

testcases/kernel/syscalls/madvise/madvise08.c static pid_t run_child(int advice) · line 171

Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise08.c +1 -1
@@ -165,7 +165,7 @@ static pid_t run_child(int advice)
                                fmem,
                                FMEMSIZE,
                                advstr);
-                       exit(1);
+                       exit(0);
                }
                abort();
        }

Good catch, thanks!

Maybe it'd be more logical to keep exit(1) (it's error) and check against WEXITSTATUS(status) == 1, but it's a minor detail, let's keep exit(0).

Can I merge with your RBT?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 25 lines
Quoted 14 lines

Review

Quoted 5 lines
(quoted diff) +1 -1
-	if (WIFEXITED(status))
+	if (WIFEXITED(status) && !WEXITSTATUS(status))
 		return 0;
 
 	tst_res(TCONF, "No coredump produced after signal (%d)",

This one is not complete. We do exit(1) if madvise fails that would be previously caught here so we have to add:

testcases/kernel/syscalls/madvise/madvise08.c +0 -0
index 96bcaf159..f8f74ef4f 100644

testcases/kernel/syscalls/madvise/madvise08.c static pid_t run_child(int advice) · line 171

Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise08.c +1 -1
@@ -165,7 +165,7 @@ static pid_t run_child(int advice)
                                fmem,
                                FMEMSIZE,
                                advstr);
-                       exit(1);
+                       exit(0);
                }
                abort();
        }

Good catch, thanks!

Quoted 2 lines

Maybe it'd be more logical to keep exit(1) (it's error) and check against WEXITSTATUS(status) == 1, but it's a minor detail, let's keep exit(0).

I wouldn't do so, as it may confuse people into thinking that the return value actually carries any information, which it does not since the failure has been already reported. I would just stick to exit(0) which makes it more clear that we just need to exit the process, nothing more.

Quoted 1 line

Can I merge with your RBT?

Yes, with the fix above.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw

Hi Cyril,

...

Quoted 14 lines
Quoted 13 lines

testcases/kernel/syscalls/madvise/madvise08.c static pid_t run_child(int advice) · line 171

Quoted 11 lines
testcases/kernel/syscalls/madvise/madvise08.c +1 -1
@@ -165,7 +165,7 @@ static pid_t run_child(int advice)
                                fmem,
                                FMEMSIZE,
                                advstr);
-                       exit(1);
+                       exit(0);
                }
                abort();
        }

Good catch, thanks!

Quoted 7 lines
Quoted 2 lines

Maybe it'd be more logical to keep exit(1) (it's error) and check against WEXITSTATUS(status) == 1, but it's a minor detail, let's keep exit(0).

I wouldn't do so, as it may confuse people into thinking that the return value actually carries any information, which it does not since the failure has been already reported. I would just stick to exit(0) which makes it more clear that we just need to exit the process, nothing more.

This makes sense, kept it this way.

Quoted 3 lines
Quoted 1 line

Can I merge with your RBT?

Yes, with the fix above.

Thanks, merged.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp