* [LTP] [PATCH] kill/1-2.c: fix potential bug
@ 2013-02-18 3:05 DAN LI
2013-02-19 2:14 ` Wanlong Gao
0 siblings, 1 reply; 2+ messages in thread
From: DAN LI @ 2013-02-18 3:05 UTC (permalink / raw)
To: LTP list
If fork() fails,this case will cause unexpected problem when kill(-1,...) called by root.
Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
.../conformance/interfaces/kill/1-2.c | 35 ++++++++++++++--------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c
b/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c
index 26580ec..18aad8a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c
@@ -1,10 +1,3 @@
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include "posixtest.h"
-
/*
* Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
* Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com
@@ -31,6 +24,13 @@
* the parent's signal. If that is not the case, this test will fail.
*/
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include "posixtest.h"
+
#define SIGTOTEST SIGUSR1
void myhandler(int signo)
@@ -44,16 +44,19 @@ int main()
int sig;
sigset_t set;
+
if (sigemptyset(&set) == -1) {
perror("Error calling sigemptyset\n");
return PTS_UNRESOLVED;
}
+
if (sigaddset(&set, SIGTOTEST) == -1) {
perror("Error calling sigaddset\n");
return PTS_UNRESOLVED;
}
- if ((pid = fork()) == 0) {
+ pid = fork();
+ if (pid == 0) {
/* child here */
struct sigaction act;
act.sa_handler = myhandler;
@@ -62,16 +65,18 @@ int main()
sigaction(SIGTOTEST, &act, 0);
if (0 != sigwait(&set, &sig)) {
- printf
- ("Sigwait did not return 0. Possible problem with sigwait function\n");
- return 0; /* FAIL */
+ printf("Sigwait did not return 0."
+ "Possible problem with sigwait function\n");
+ /* FAIL */
+ return 0;
}
if (sig != SIGTOTEST)
- return 0; /* FAIL */
+ /* FAIL */
+ return 0;
return 1;
- } else {
+ } else if (pid > 0) {
/* parent here */
int i;
@@ -95,6 +100,10 @@ int main()
printf("Test FAILED\n");
return PTS_FAIL;
}
+
+ } else {
+ printf("Error fork() a child\n");
+ return PTS_UNRESOLVED;
}
printf("Should have exited from parent\n");
--
1.7.12
------------------------------------------------------------------------------
The Go Parallel Website, sponsored by Intel - in partnership with Geeknet,
is your hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials, tech docs,
whitepapers, evaluation guides, and opinion stories. Check out the most
recent posts - join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-02-19 2:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-18 3:05 [LTP] [PATCH] kill/1-2.c: fix potential bug DAN LI
2013-02-19 2:14 ` Wanlong Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox