Skip to contentSkip to conversation

kill/1-2.c: fix potential bug

PATCH Applied DAN LI 2 participants 2 messages Feb 18, 2013 – Feb 19, 2013

lore
Share & tools
lore

DAN LI

author
#0 lore raw

PATCH 1/1 kill/1-2.c: fix potential bug

If fork() fails,this case will cause unexpected problem when kill(-1,...) called by root.

---
 .../conformance/interfaces/kill/1-2.c              | 35 ++++++++++++++--------
 1 file changed, 22 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c index 26580ec..18aad8a 100644

testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c +22 -13
@@ -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");
Signature · 12 lines
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Applied
#1 lore raw
Quoted 3 lines · DAN LI

If fork() fails,this case will cause unexpected problem when kill(-1,...) called by root.

Applied, thank you .

Wanlong Gao

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list