[LTP] [PATCH v2] open_posix: Add failure handling of fork()
Zhao Gongyi
zhaogongyi@huawei.com
Tue Sep 21 00:12:12 CEST 2021
When fork() failed and transfer the return value(-1) to kill(),
it would freeze the system, so it is very serious in this
cases and should be avoided.
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
.../conformance/interfaces/clock_nanosleep/1-5.c | 5 ++++-
.../conformance/interfaces/nanosleep/3-2.c | 5 ++++-
.../conformance/interfaces/sigaction/10-1.c | 5 ++++-
.../conformance/interfaces/sigaction/11-1.c | 5 ++++-
.../conformance/interfaces/sigaction/9-1.c | 5 ++++-
5 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c
index 263d98a08..7c09d7599 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c
@@ -35,7 +35,10 @@ int main(void)
return PTS_UNRESOLVED;
}
- if ((pid = fork()) == 0) {
+ if ((pid = fork()) < 0) {
+ printf("fork() did not return success\n");
+ return PTS_UNRESOLVED;
+ } else if (pid == 0) {
/* child here */
struct timespec tssleep;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c b/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c
index 4016fb4e6..bfc271edf 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c
@@ -31,7 +31,10 @@ int main(void)
return PTS_UNRESOLVED;
}
- if ((pid = fork()) == 0) {
+ if ((pid = fork()) < 0) {
+ printf("fork() did not return success\n");
+ return PTS_UNRESOLVED;
+ } else if (pid == 0) {
/* child here */
struct timespec tssleep;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c
index 02150a150..722cbf2b5 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c
@@ -66,7 +66,10 @@ int main(void)
sigemptyset(&act.sa_mask);
sigaction(SIGCHLD, &act, 0);
- if ((pid = fork()) == 0) {
+ if ((pid = fork()) < 0) {
+ printf("fork() did not return success\n");
+ return PTS_UNRESOLVED;
+ } else if (pid == 0) {
/* child */
while (1) {
/* wait forever, or until we are
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c
index 41db84865..fcf5e7837 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c
@@ -51,7 +51,10 @@ int main(void)
sigemptyset(&act.sa_mask);
sigaction(SIGCHLD, &act, 0);
- if ((pid = fork()) == 0) {
+ if ((pid = fork()) < 0) {
+ printf("fork() did not return success\n");
+ return PTS_UNRESOLVED;
+ } else if (pid == 0) {
/* child */
while (1) {
/* wait forever, or until we are
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c
index 1d45c09c6..dc3200eae 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c
@@ -51,7 +51,10 @@ int main(void)
sigemptyset(&act.sa_mask);
sigaction(SIGCHLD, &act, 0);
- if ((pid = fork()) == 0) {
+ if ((pid = fork()) < 0) {
+ printf("fork() did not return success\n");
+ return PTS_UNRESOLVED;
+ } else if (pid == 0) {
/* child */
/* wait forever, or until we are
interrupted by a signal */
--
2.17.1
More information about the ltp
mailing list