Skip to contentSkip to conversation

mprotect02: fix error of the case need sighandler()

PATCH In review Peng Haitao 2 participants 6 messages Jan 20, 2011 – Jan 21, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mprotect02: fix error of the case need sighandler()

Hi Garrett,

The case expect the signal "SIGSEGV", so should add sighandler().

---
 testcases/kernel/syscalls/mprotect/mprotect02.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
testcases/kernel/syscalls/mprotect/mprotect02.c +10 -1
index ebc4bcc..36c41de 100644
@@ -198,12 +198,21 @@ int main()
 
 #endif /* UCLINUX */
 
+void sighandler(int sig)
+{
+	tst_resm(TINFO, "received signal: %d", sig);
+	if (sig == SIGSEGV)
+		exit(1);
+	else
+		tst_brkm(TBROK, 0, "Unexpected signal %d received.", sig);
+}
+
 /*
  * setup() - performs all ONE TIME setup for this test
  */
 void setup()
 {
-	tst_sig(FORK, DEF_HANDLER, NULL);
+	tst_sig(FORK, sighandler, NULL);
 
 	TEST_PAUSE;
 
Signature · 17 lines
1.7.3.1

-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw
Quoted 3 lines · Peng Haitao

Hi Garrett,

The case expect the signal "SIGSEGV", so should add sighandler().

For the first portion of the testcase, yes. For the second part of the testcase, no.
Thanks,
-Garrett

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

Hi Garrett,

Garrett Cooper said the following on 2011-1-20 17:28:

Quoted 4 lines
Quoted 1 line

The case expect the signal "SIGSEGV", so should add sighandler().

For the first portion of the testcase, yes. For the second part of the testcase, no.

This is OK, but the default signal handler is invoked when an unexpected signal is caught. so I think we should add sighandler(). Furthermore, the default signal handler make the child process exit 2, but the case expect the child process exit 1, this will cause the case fail.

The following patch will reinitialize signal handler.

---
 testcases/kernel/syscalls/mprotect/mprotect02.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
testcases/kernel/syscalls/mprotect/mprotect02.c +13 -1
index ebc4bcc..c0a5d8b 100644
@@ -129,6 +129,9 @@ int main(int ac, char **av)
 			tst_brkm(TBROK, cleanup, "child failed");
 		 }
 
+		/* Re-Initialization signal handler */
+		tst_sig(FORK, DEF_HANDLER, NULL);
+
 		/*
 		 * Change the protection to WRITE.
 		 */
@@ -198,12 +201,21 @@ int main()
 
 #endif /* UCLINUX */
 
+void sighandler(int sig)
+{
+	tst_resm(TINFO, "received signal: %d", sig);
+	if (sig == SIGSEGV)
+		exit(1);
+	else
+		tst_brkm(TBROK, 0, "Unexpected signal %d received.", sig);
+}
+
 /*
  * setup() - performs all ONE TIME setup for this test
  */
 void setup()
 {
-	tst_sig(FORK, DEF_HANDLER, NULL);
+	tst_sig(FORK, sighandler, NULL);
 
 	TEST_PAUSE;
 
Signature · 18 lines
1.7.3.1


-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw
Quoted 8 lines · Peng Haitao

Hi Garrett,

Garrett Cooper said the following on 2011-1-20 17:28:

Quoted 4 lines
Quoted 1 line

The case expect the signal "SIGSEGV", so should add sighandler().

For the first portion of the testcase, yes. For the second part of the testcase, no.

Quoted 6 lines

This is OK, but the default signal handler is invoked when an unexpected signal is caught. so I think we should add sighandler(). Furthermore, the default signal handler make the child process exit 2, but the case expect the child process exit 1, this will cause the case fail.

The following patch will reinitialize signal handler.

This won't work if the number of test loops is > 1 (it will reset
the handler back to the default and fail on the next iteration). Thanks,
-Garrett

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw

Hi Garrett,

Garrett Cooper said the following on 2011-1-21 12:00:

Quoted 9 lines
Quoted 6 lines

This is OK, but the default signal handler is invoked when an unexpected signal is caught. so I think we should add sighandler(). Furthermore, the default signal handler make the child process exit 2, but the case expect the child process exit 1, this will cause the case fail.

The following patch will reinitialize signal handler.

This won't work if the number of test loops is > 1 (it will reset
the handler back to the default and fail on the next iteration).

Thanks for your comment.

The following patch will initialize signal handler to sighandler() in loops starting, and reinitialize default signal handle in the second part.

---
 testcases/kernel/syscalls/mprotect/mprotect02.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/mprotect/mprotect02.c +16 -2
index ebc4bcc..f27d2da 100644
@@ -65,6 +65,7 @@
 
 void cleanup(void);
 void setup(void);
+void sighandler(int);
 
 char *TCID = "mprotect02";
 int TST_TOTAL = 1;
@@ -93,6 +94,9 @@ int main(int ac, char **av)
 	/* The following loop checks looping state if -i option given */
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
+		/* Initialization signal handler */
+		tst_sig(FORK, sighandler, NULL);
+
 		/* reset Tst_count in case we are looping */
 		Tst_count = 0;
 
@@ -129,6 +133,9 @@ int main(int ac, char **av)
 			tst_brkm(TBROK, cleanup, "child failed");
 		 }
 
+		/* Re-Initialization signal handler */
+		tst_sig(FORK, DEF_HANDLER, NULL);
+
 		/*
 		 * Change the protection to WRITE.
 		 */
@@ -198,13 +205,20 @@ int main()
 
 #endif /* UCLINUX */
 
+void sighandler(int sig)
+{
+	tst_resm(TINFO, "received signal: %d", sig);
+	if (sig == SIGSEGV)
+		exit(1);
+	else
+		tst_brkm(TBROK, 0, "Unexpected signal %d received.", sig);
+}
+
 /*
  * setup() - performs all ONE TIME setup for this test
  */
 void setup()
 {
-	tst_sig(FORK, DEF_HANDLER, NULL);
-
 	TEST_PAUSE;
 
 	tst_tmpdir();		/* create a temporary directory, cd to it */
Signature · 18 lines
1.7.3.1


-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw
Quoted 10 lines · Peng Haitao

Hi Garrett,

Garrett Cooper said the following on 2011-1-21 12:00:

Quoted 7 lines
Quoted 6 lines

This is OK, but the default signal handler is invoked when an unexpected signal is caught. so I think we should add sighandler(). Furthermore, the default signal handler make the child process exit 2, but the case expect the child process exit 1, this will cause the case fail.

The following patch will reinitialize signal handler.

Quoted 7 lines
Quoted 2 lines

    This won't work if the number of test loops is > 1 (it will reset the handler back to the default and fail on the next iteration).

Thanks for your comment.

The following patch will initialize signal handler to sighandler() in loops starting, and reinitialize default signal handle in the second part.

I fixed it in a different way from what you did and it appears to
work well now (I simplified the test by not using tst_sig, as it kept on segfaulting in the parent process when I used tst_sig). Thanks,
-Garrett

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list