public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: DAN LI <li.dan@cn.fujitsu.com>
To: LTP list <ltp-list@lists.sourceforge.net>
Subject: [LTP]  [PATCH] kill/1-2.c: fix potential bug
Date: Mon, 18 Feb 2013 11:05:31 +0800	[thread overview]
Message-ID: <51219A7B.2020909@cn.fujitsu.com> (raw)


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

             reply	other threads:[~2013-02-18  3:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-18  3:05 DAN LI [this message]
2013-02-19  2:14 ` [LTP] [PATCH] kill/1-2.c: fix potential bug Wanlong Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51219A7B.2020909@cn.fujitsu.com \
    --to=li.dan@cn.fujitsu.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox