public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP]  [PATCH] setfsuid04.c: the child process should exit 0
@ 2011-02-14  6:05 Peng Haitao
  2011-02-14  6:23 ` Garrett Cooper
  0 siblings, 1 reply; 10+ messages in thread
From: Peng Haitao @ 2011-02-14  6:05 UTC (permalink / raw)
  To: Garrett Cooper; +Cc: ltp-list

Hi Garrett,

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/kernel/syscalls/setfsuid/setfsuid04.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/setfsuid/setfsuid04.c b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
index 9129892..cd230ff 100644
--- a/testcases/kernel/syscalls/setfsuid/setfsuid04.c
+++ b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
@@ -93,7 +93,7 @@ int main(int ac, char **av)
 
 	if (pid == 0) {
 		do_master_child();
-
+		exit(0);
 	} else {
 		waitpid(pid, &status, 0);
 		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
@@ -103,8 +103,6 @@ int main(int ac, char **av)
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -244,4 +242,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
-- 
1.7.3.1

-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-14  6:05 [LTP] [PATCH] setfsuid04.c: the child process should exit 0 Peng Haitao
@ 2011-02-14  6:23 ` Garrett Cooper
  2011-02-14  9:35   ` Peng Haitao
  0 siblings, 1 reply; 10+ messages in thread
From: Garrett Cooper @ 2011-02-14  6:23 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

[-- Attachment #1: Type: text/plain, Size: 532 bytes --]

On Sun, Feb 13, 2011 at 10:05 PM, Peng Haitao <penght@cn.fujitsu.com> wrote:
> Hi Garrett,
>
> Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>

Hi Peng,
    How about this version instead? There were issues with the
previous version of the file where calling tst_brkm from inside the
child process would break test execution in interesting and
non-deterministic ways.
    As a bonus task you could convert things to SAFE_* macros as there
are a number of spots that I didn't touch that are missing error
checks.
Thanks!
-Garrett

[-- Attachment #2: ltp-fix-setfsuid04-testcase.patch --]
[-- Type: text/x-patch, Size: 5870 bytes --]

diff --git a/testcases/kernel/syscalls/setfsuid/setfsuid04.c b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
index 9129892..02a49de 100644
--- a/testcases/kernel/syscalls/setfsuid/setfsuid04.c
+++ b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
@@ -43,18 +43,21 @@
  * RESTRICTIONS
  * 	Must be run as root.
  */
-#include <errno.h>
 #include <sys/types.h>
+#ifdef __GLIBC__
+#include <sys/fsuid.h>
+#endif
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#ifdef __GLIBC__
-#include <sys/fsuid.h>
-#endif
 #include "test.h"
 #include "usctest.h"
-#include <pwd.h>
 
 char *TCID = "setfsuid04";
 int TST_TOTAL = 1;
@@ -76,13 +79,9 @@ int main(int ac, char **av)
 	int status;
 
 	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	 }
 
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	TEST_EXP_ENOS(exp_enos);
@@ -91,20 +90,16 @@ int main(int ac, char **av)
 	if (pid < 0)
 		tst_brkm(TBROK, cleanup, "Fork failed");
 
-	if (pid == 0) {
+	if (pid == 0)
 		do_master_child();
 
-	} else {
-		waitpid(pid, &status, 0);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-			tst_resm(WEXITSTATUS(status),
-				 "son process exits with error");
-	}
+	if (waitpid(pid, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid failed");
+	if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+		tst_resm(TFAIL, "child process terminated abnormally");
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -112,95 +107,87 @@ int main(int ac, char **av)
  */
 void do_master_child()
 {
-	int lc;			/* loop counter */
 	int pid;
 	int status;
+	int tst_fd;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int tst_fd;
+	if (setfsuid(ltpuser->pw_uid) == -1) {
+		perror("setfsuid failed");
+		exit(1);
+	}
 
-		/* Reset Tst_count in case we are looping */
-		Tst_count = 0;
+	/* Test 1: Check the process with new uid cannot open the file
+	 *         with RDWR permissions.
+	 */
+	tst_fd = open(testfile, O_RDWR);
 
-		if (setfsuid(ltpuser->pw_uid) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setfsuid failed to set the euid to %d",
-				 ltpuser->pw_uid);
-		}
+	if (tst_fd != -1) {
+		printf("open succeeded unexpectedly");
+		close(tst_fd);
+		exit(1);
+	}
 
-		/* Test 1: Check the process with new uid cannot open the file
-		 *         with RDWR permissions.
-		 */
-		TEST(tst_fd = open(testfile, O_RDWR));
+	if (TEST_ERRNO == EACCES)
+		printf("open failed with EACCES as expected");
+	else {
+		perror("open failed unexpectedly");
+		exit(1);
+	}
 
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-			close(tst_fd);
-		}
+	/* Test 2: Check a son process cannot open the file
+	 *         with RDWR permissions.
+	 */
+	pid = FORK_OR_VFORK();
+	if (pid < 0)
+		tst_brkm(TBROK, cleanup, "Fork failed");
 
-		if (TEST_ERRNO == EACCES) {
-			tst_resm(TPASS, "open returned errno EACCES");
-		} else {
-			tst_resm(TFAIL, "open returned unexpected errno - %d",
-				 TEST_ERRNO);
-			continue;
-		}
+	if (pid == 0) {
+		int tst_fd2;
+
+		/* Test to open the file in son process */
+		tst_fd2 = open(testfile, O_RDWR);
 
-		/* Test 2: Check a son process cannot open the file
-		 *         with RDWR permissions.
-		 */
-		pid = FORK_OR_VFORK();
-		if (pid < 0)
-			tst_brkm(TBROK, cleanup, "Fork failed");
-
-		if (pid == 0) {
-			int tst_fd2;
-
-			/* Test to open the file in son process */
-			TEST(tst_fd2 = open(testfile, O_RDWR));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				close(tst_fd2);
-			}
-
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "open returned errno EACCES");
-			} else {
-				tst_resm(TFAIL,
-					 "open returned unexpected errno - %d",
-					 TEST_ERRNO);
-			}
-			continue;
-		} else {
-			/* Wait for son completion */
-			waitpid(pid, &status, 0);
-			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-				exit(WEXITSTATUS(status));
+		if (tst_fd2 != -1) {
+			printf("call succeeded unexpectedly\n");
+			close(tst_fd2);
+			exit(1);
 		}
 
-		/* Test 3: Fallback to initial uid and check we can again open
-		 *         the file with RDWR permissions.
-		 */
-		Tst_count++;
-		if (setfsuid(0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setfsuid failed to set the euid to 0");
+		if (TEST_ERRNO == EACCES)
+			printf("open failed with EACCES as expected\n");
+		else {
+			printf("open failed unexpectedly\n");
+			exit(1);
 		}
+	} else {
+		/* Wait for son completion */
+		if (waitpid(pid, &status, 0) == -1) {
+			perror("waitpid failed");
+			exit(1);
+		}
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			exit(WEXITSTATUS(status));
+	}
+
+	/* Test 3: Fallback to initial uid and check we can again open
+	 *         the file with RDWR permissions.
+	 */
+	Tst_count++;
+	if (setfsuid(0) == -1) {
+		perror("setfsuid failed");
+		exit(1);
+	}
 
-		TEST(tst_fd = open(testfile, O_RDWR));
+	tst_fd = open(testfile, O_RDWR);
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "open returned unexpected errno %d",
-				 TEST_ERRNO);
-			continue;
-		} else {
-			tst_resm(TPASS, "open call succeeded");
-			close(tst_fd);
-		}
+	if (tst_fd == -1) {
+		perror("open failed unexpectedly");
+		exit(1);
+	} else {
+		printf("open call succeeded");
+		close(tst_fd);
 	}
+	exit(0);
 }
 
 /*
@@ -208,9 +195,7 @@ void do_master_child()
  */
 void setup(void)
 {
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
+	tst_require_root(NULL);
 
 	ltpuser = getpwnam(nobody_uid);
 
@@ -244,4 +229,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}

[-- Attachment #3: Type: text/plain, Size: 387 bytes --]

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-14  6:23 ` Garrett Cooper
@ 2011-02-14  9:35   ` Peng Haitao
  2011-02-15 14:42     ` Garrett Cooper
  0 siblings, 1 reply; 10+ messages in thread
From: Peng Haitao @ 2011-02-14  9:35 UTC (permalink / raw)
  To: Garrett Cooper; +Cc: ltp-list

Hi Garrett,

Garrett Cooper said the following on 2011-2-14 14:23:
>     How about this version instead? There were issues with the

The two "TEST_ERRNO" should be replaced with "errno" in this version, 
If not, the version will fail.

-- 
Best Regards,
Peng Haitao

> previous version of the file where calling tst_brkm from inside the
> child process would break test execution in interesting and
> non-deterministic ways.
>     As a bonus task you could convert things to SAFE_* macros as there
> are a number of spots that I didn't touch that are missing error
> checks.
> Thanks!
> -Garrett


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-14  9:35   ` Peng Haitao
@ 2011-02-15 14:42     ` Garrett Cooper
  2011-02-16  6:40       ` Peng Haitao
  0 siblings, 1 reply; 10+ messages in thread
From: Garrett Cooper @ 2011-02-15 14:42 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On Mon, Feb 14, 2011 at 1:35 AM, Peng Haitao <penght@cn.fujitsu.com> wrote:
> Hi Garrett,
>
> Garrett Cooper said the following on 2011-2-14 14:23:
>>     How about this version instead? There were issues with the
>
> The two "TEST_ERRNO" should be replaced with "errno" in this version,
> If not, the version will fail.

Other than that I assume things are ok?
Thanks,
-Garrett

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-15 14:42     ` Garrett Cooper
@ 2011-02-16  6:40       ` Peng Haitao
  2011-02-16  6:45         ` Garrett Cooper
  0 siblings, 1 reply; 10+ messages in thread
From: Peng Haitao @ 2011-02-16  6:40 UTC (permalink / raw)
  To: Garrett Cooper; +Cc: ltp-list

[-- Attachment #1: Type: text/plain, Size: 5441 bytes --]

Hi Garrett,

Garrett Cooper said the following on 2011-2-15 22:42:
>>>     How about this version instead? There were issues with the
>>
>> The two "TEST_ERRNO" should be replaced with "errno" in this version,
>> If not, the version will fail.
> 
> Other than that I assume things are ok?

Sorry, the child process need exit when success in do_master_child().
I rewrite a new patch base on your version, please review.
Thinks.

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/kernel/syscalls/setfsuid/setfsuid04.c |  105 +++++++++++------------
 1 files changed, 49 insertions(+), 56 deletions(-)

diff --git a/testcases/kernel/syscalls/setfsuid/setfsuid04.c b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
index 9129892..ddbbcde 100644
--- a/testcases/kernel/syscalls/setfsuid/setfsuid04.c
+++ b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
@@ -43,18 +43,21 @@
  * RESTRICTIONS
  * 	Must be run as root.
  */
-#include <errno.h>
 #include <sys/types.h>
+#ifdef __GLIBC__
+#include <sys/fsuid.h>
+#endif
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#ifdef __GLIBC__
-#include <sys/fsuid.h>
-#endif
 #include "test.h"
 #include "usctest.h"
-#include <pwd.h>
 
 char *TCID = "setfsuid04";
 int TST_TOTAL = 1;
@@ -76,13 +79,9 @@ int main(int ac, char **av)
 	int status;
 
 	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	 }
 
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	TEST_EXP_ENOS(exp_enos);
@@ -91,20 +90,16 @@ int main(int ac, char **av)
 	if (pid < 0)
 		tst_brkm(TBROK, cleanup, "Fork failed");
 
-	if (pid == 0) {
+	if (pid == 0)
 		do_master_child();
 
-	} else {
-		waitpid(pid, &status, 0);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-			tst_resm(WEXITSTATUS(status),
-				 "son process exits with error");
-	}
+	if (waitpid(pid, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid failed");
+	if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+		tst_resm(TFAIL, "child process terminated abnormally");
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -123,27 +118,26 @@ void do_master_child()
 		Tst_count = 0;
 
 		if (setfsuid(ltpuser->pw_uid) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setfsuid failed to set the euid to %d",
-				 ltpuser->pw_uid);
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		/* Test 1: Check the process with new uid cannot open the file
 		 *         with RDWR permissions.
 		 */
-		TEST(tst_fd = open(testfile, O_RDWR));
+		tst_fd = open(testfile, O_RDWR);
 
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
+		if (tst_fd != -1) {
+			printf("open succeeded unexpectedly\n");
 			close(tst_fd);
+			exit(1);
 		}
 
-		if (TEST_ERRNO == EACCES) {
-			tst_resm(TPASS, "open returned errno EACCES");
-		} else {
-			tst_resm(TFAIL, "open returned unexpected errno - %d",
-				 TEST_ERRNO);
-			continue;
+		if (errno == EACCES)
+			printf("open failed with EACCES as expected\n");
+		else {
+			perror("open failed unexpectedly");
+			exit(1);
 		}
 
 		/* Test 2: Check a son process cannot open the file
@@ -157,27 +151,28 @@ void do_master_child()
 			int tst_fd2;
 
 			/* Test to open the file in son process */
-			TEST(tst_fd2 = open(testfile, O_RDWR));
+			tst_fd2 = open(testfile, O_RDWR);
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
+			if (tst_fd2 != -1) {
+				printf("call succeeded unexpectedly\n");
 				close(tst_fd2);
+				exit(1);
 			}
 
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "open returned errno EACCES");
+			if (errno == EACCES) {
+				printf("open failed with EACCES as expected\n");
+				exit(0);
 			} else {
-				tst_resm(TFAIL,
-					 "open returned unexpected errno - %d",
-					 TEST_ERRNO);
+				printf("open failed unexpectedly\n");
+				exit(1);
 			}
-			continue;
 		} else {
 			/* Wait for son completion */
-			waitpid(pid, &status, 0);
-			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+			if (waitpid(pid, &status, 0) == -1) {
+				perror("waitpid failed");
+				exit(1);
+			}
+			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 				exit(WEXITSTATUS(status));
 		}
 
@@ -186,21 +181,21 @@ void do_master_child()
 		 */
 		Tst_count++;
 		if (setfsuid(0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setfsuid failed to set the euid to 0");
+			perror("setfsuid failed");
+			exit(1);
 		}
 
-		TEST(tst_fd = open(testfile, O_RDWR));
+		tst_fd = open(testfile, O_RDWR);
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "open returned unexpected errno %d",
-				 TEST_ERRNO);
-			continue;
+		if (tst_fd == -1) {
+			perror("open failed unexpectedly");
+			exit(1);
 		} else {
-			tst_resm(TPASS, "open call succeeded");
+			printf("open call succeeded\n");
 			close(tst_fd);
 		}
 	}
+	exit(0);
 }
 
 /*
@@ -208,9 +203,7 @@ void do_master_child()
  */
 void setup(void)
 {
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
+	tst_require_root(NULL);
 
 	ltpuser = getpwnam(nobody_uid);
 
@@ -244,4 +237,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
-- 
1.7.3.1

-- 
Best Regards,
Peng Haitao

[-- Attachment #2: 0001-setfsuid04.c-the-child-process-should-exit-0.patch --]
[-- Type: text/plain, Size: 5192 bytes --]

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/kernel/syscalls/setfsuid/setfsuid04.c |  105 +++++++++++------------
 1 files changed, 49 insertions(+), 56 deletions(-)

diff --git a/testcases/kernel/syscalls/setfsuid/setfsuid04.c b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
index 9129892..ddbbcde 100644
--- a/testcases/kernel/syscalls/setfsuid/setfsuid04.c
+++ b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
@@ -43,18 +43,21 @@
  * RESTRICTIONS
  * 	Must be run as root.
  */
-#include <errno.h>
 #include <sys/types.h>
+#ifdef __GLIBC__
+#include <sys/fsuid.h>
+#endif
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#ifdef __GLIBC__
-#include <sys/fsuid.h>
-#endif
 #include "test.h"
 #include "usctest.h"
-#include <pwd.h>
 
 char *TCID = "setfsuid04";
 int TST_TOTAL = 1;
@@ -76,13 +79,9 @@ int main(int ac, char **av)
 	int status;
 
 	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	 }
 
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	TEST_EXP_ENOS(exp_enos);
@@ -91,20 +90,16 @@ int main(int ac, char **av)
 	if (pid < 0)
 		tst_brkm(TBROK, cleanup, "Fork failed");
 
-	if (pid == 0) {
+	if (pid == 0)
 		do_master_child();
 
-	} else {
-		waitpid(pid, &status, 0);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-			tst_resm(WEXITSTATUS(status),
-				 "son process exits with error");
-	}
+	if (waitpid(pid, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid failed");
+	if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+		tst_resm(TFAIL, "child process terminated abnormally");
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -123,27 +118,26 @@ void do_master_child()
 		Tst_count = 0;
 
 		if (setfsuid(ltpuser->pw_uid) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setfsuid failed to set the euid to %d",
-				 ltpuser->pw_uid);
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		/* Test 1: Check the process with new uid cannot open the file
 		 *         with RDWR permissions.
 		 */
-		TEST(tst_fd = open(testfile, O_RDWR));
+		tst_fd = open(testfile, O_RDWR);
 
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
+		if (tst_fd != -1) {
+			printf("open succeeded unexpectedly\n");
 			close(tst_fd);
+			exit(1);
 		}
 
-		if (TEST_ERRNO == EACCES) {
-			tst_resm(TPASS, "open returned errno EACCES");
-		} else {
-			tst_resm(TFAIL, "open returned unexpected errno - %d",
-				 TEST_ERRNO);
-			continue;
+		if (errno == EACCES)
+			printf("open failed with EACCES as expected\n");
+		else {
+			perror("open failed unexpectedly");
+			exit(1);
 		}
 
 		/* Test 2: Check a son process cannot open the file
@@ -157,27 +151,28 @@ void do_master_child()
 			int tst_fd2;
 
 			/* Test to open the file in son process */
-			TEST(tst_fd2 = open(testfile, O_RDWR));
+			tst_fd2 = open(testfile, O_RDWR);
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
+			if (tst_fd2 != -1) {
+				printf("call succeeded unexpectedly\n");
 				close(tst_fd2);
+				exit(1);
 			}
 
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "open returned errno EACCES");
+			if (errno == EACCES) {
+				printf("open failed with EACCES as expected\n");
+				exit(0);
 			} else {
-				tst_resm(TFAIL,
-					 "open returned unexpected errno - %d",
-					 TEST_ERRNO);
+				printf("open failed unexpectedly\n");
+				exit(1);
 			}
-			continue;
 		} else {
 			/* Wait for son completion */
-			waitpid(pid, &status, 0);
-			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+			if (waitpid(pid, &status, 0) == -1) {
+				perror("waitpid failed");
+				exit(1);
+			}
+			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 				exit(WEXITSTATUS(status));
 		}
 
@@ -186,21 +181,21 @@ void do_master_child()
 		 */
 		Tst_count++;
 		if (setfsuid(0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setfsuid failed to set the euid to 0");
+			perror("setfsuid failed");
+			exit(1);
 		}
 
-		TEST(tst_fd = open(testfile, O_RDWR));
+		tst_fd = open(testfile, O_RDWR);
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "open returned unexpected errno %d",
-				 TEST_ERRNO);
-			continue;
+		if (tst_fd == -1) {
+			perror("open failed unexpectedly");
+			exit(1);
 		} else {
-			tst_resm(TPASS, "open call succeeded");
+			printf("open call succeeded\n");
 			close(tst_fd);
 		}
 	}
+	exit(0);
 }
 
 /*
@@ -208,9 +203,7 @@ void do_master_child()
  */
 void setup(void)
 {
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
+	tst_require_root(NULL);
 
 	ltpuser = getpwnam(nobody_uid);
 
@@ -244,4 +237,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
-- 
1.7.3.1


[-- Attachment #3: Type: text/plain, Size: 387 bytes --]

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-16  6:40       ` Peng Haitao
@ 2011-02-16  6:45         ` Garrett Cooper
  2011-02-16  7:27           ` Peng Haitao
  0 siblings, 1 reply; 10+ messages in thread
From: Garrett Cooper @ 2011-02-16  6:45 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On Tue, Feb 15, 2011 at 10:40 PM, Peng Haitao <penght@cn.fujitsu.com> wrote:
> Hi Garrett,
>
> Garrett Cooper said the following on 2011-2-15 22:42:
>>>>     How about this version instead? There were issues with the
>>>
>>> The two "TEST_ERRNO" should be replaced with "errno" in this version,
>>> If not, the version will fail.
>>
>> Other than that I assume things are ok?
>
> Sorry, the child process need exit when success in do_master_child().
> I rewrite a new patch base on your version, please review.
> Thinks.

    This is what the code currently looks like. I assume the same
needs to be done for the other set*suid syscall testcases?
Thanks,
-Garrett

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-16  6:45         ` Garrett Cooper
@ 2011-02-16  7:27           ` Peng Haitao
  2011-02-23  9:50             ` Peng Haitao
  0 siblings, 1 reply; 10+ messages in thread
From: Peng Haitao @ 2011-02-16  7:27 UTC (permalink / raw)
  To: Garrett Cooper; +Cc: ltp-list

Hi Garrett,

Garrett Cooper said the following on 2011-2-16 14:45:
>> Sorry, the child process need exit when success in do_master_child().
>> I rewrite a new patch base on your version, please review.
> 
>     This is what the code currently looks like. I assume the same
> needs to be done for the other set*suid syscall testcases?

setresuid and setreuid also need to be fixed at least.
Thanks.

-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-16  7:27           ` Peng Haitao
@ 2011-02-23  9:50             ` Peng Haitao
  2011-02-24  5:27               ` Garrett Cooper
  2011-02-24  5:27               ` Garrett Cooper
  0 siblings, 2 replies; 10+ messages in thread
From: Peng Haitao @ 2011-02-23  9:50 UTC (permalink / raw)
  To: Garrett Cooper; +Cc: ltp-list

[-- Attachment #1: Type: text/plain, Size: 8484 bytes --]

Hi Garrett,

Peng Haitao said the following on 2011-2-16 15:27:
>>     This is what the code currently looks like. I assume the same
>> needs to be done for the other set*suid syscall testcases?
> 
> setresuid and setreuid also need to be fixed at least.
> Thanks.
> 

 The following patch fix the cases of setresuid and setreuid.

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/kernel/syscalls/setresuid/setresuid04.c |   71 +++++++++------------
 testcases/kernel/syscalls/setreuid/setreuid07.c   |   71 +++++++++------------
 2 files changed, 62 insertions(+), 80 deletions(-)

diff --git a/testcases/kernel/syscalls/setresuid/setresuid04.c b/testcases/kernel/syscalls/setresuid/setresuid04.c
index 13c7a8f..eef0d11 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid04.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid04.c
@@ -74,13 +74,8 @@ int main(int ac, char **av)
 	int status;
 
 	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	 }
-
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	TEST_EXP_ENOS(exp_enos);
@@ -89,20 +84,16 @@ int main(int ac, char **av)
 	if (pid < 0)
 		tst_brkm(TBROK, cleanup, "Fork failed");
 
-	if (pid == 0) {
+	if (pid == 0)
 		do_master_child();
 
-	} else {
-		waitpid(pid, &status, 0);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-			tst_resm(WEXITSTATUS(status),
-				 "son process exits with error");
-	}
+	if (waitpid(pid, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid failed");
+	if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+		tst_resm(TFAIL, "child process terminated abnormally");
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -121,9 +112,8 @@ void do_master_child()
 		Tst_count = 0;
 
 		if (setresuid(0, ltpuser->pw_uid, 0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setresuid failed to set the euid to %d",
-				 ltpuser->pw_uid);
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		/* Test 1: Check the process with new uid cannot open the file
@@ -132,16 +122,16 @@ void do_master_child()
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
+			printf("open succeeded unexpectedly\n");
 			close(tst_fd);
+			exit(1);
 		}
 
 		if (TEST_ERRNO == EACCES) {
-			tst_resm(TPASS, "open returned errno EACCES");
+			printf("open failed with EACCES as expected\n");
 		} else {
-			tst_resm(TFAIL, "open returned unexpected errno - %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		}
 
 		/* Test 2: Check a son process cannot open the file
@@ -158,23 +148,26 @@ void do_master_child()
 			TEST(tst_fd2 = open(testfile, O_RDWR));
 
 			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
+				printf("call succeeded unexpectedly\n");
 				close(tst_fd2);
+				exit(1);
 			}
 
 			TEST_ERROR_LOG(TEST_ERRNO);
 
 			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "open returned errno EACCES");
+				printf("open failed with EACCES as expected\n");
+				exit(0);
 			} else {
-				tst_resm(TFAIL,
-					 "open returned unexpected errno - %d",
-					 TEST_ERRNO);
+				printf("open failed unexpectedly\n");
+				exit(1);
 			}
-			continue;
 		} else {
 			/* Wait for son completion */
-			waitpid(pid, &status, 0);
+			if(waitpid(pid, &status, 0) == -1) {
+				perror("waitpid failed");
+				exit(1);
+			}
 			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
 				exit(WEXITSTATUS(status));
 		}
@@ -184,21 +177,21 @@ void do_master_child()
 		 */
 		Tst_count++;
 		if (setresuid(0, 0, 0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setresuid failed to set the euid to 0");
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "open returned unexpected errno %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		} else {
-			tst_resm(TPASS, "open call succeeded");
+			printf("open call succeeded\n");
 			close(tst_fd);
 		}
 	}
+	exit(0);
 }
 
 /*
@@ -206,9 +199,7 @@ void do_master_child()
  */
 void setup(void)
 {
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
+	tst_require_root(NULL);
 
 	ltpuser = getpwnam(nobody_uid);
 
@@ -242,4 +233,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
diff --git a/testcases/kernel/syscalls/setreuid/setreuid07.c b/testcases/kernel/syscalls/setreuid/setreuid07.c
index 19025cd..69bb25f 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid07.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid07.c
@@ -73,13 +73,8 @@ int main(int ac, char **av)
 	int status;
 
 	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	 }
-
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	TEST_EXP_ENOS(exp_enos);
@@ -88,20 +83,16 @@ int main(int ac, char **av)
 	if (pid < 0)
 		tst_brkm(TBROK, cleanup, "Fork failed");
 
-	if (pid == 0) {
+	if (pid == 0)
 		do_master_child();
 
-	} else {
-		waitpid(pid, &status, 0);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-			tst_resm(WEXITSTATUS(status),
-				 "son process exits with error");
-	}
+	if (waitpid(pid, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid failed");
+	if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+		tst_resm(TFAIL, "child process terminated abnormally");
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -120,9 +111,8 @@ void do_master_child()
 		Tst_count = 0;
 
 		if (setreuid(0, ltpuser->pw_uid) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setreuid failed to set the euid to %d",
-				 ltpuser->pw_uid);
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		/* Test 1: Check the process with new uid cannot open the file
@@ -131,16 +121,16 @@ void do_master_child()
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
+			printf("open succeeded unexpectedly\n");
 			close(tst_fd);
+			exit(1);
 		}
 
 		if (TEST_ERRNO == EACCES) {
-			tst_resm(TPASS, "open returned errno EACCES");
+			printf("open failed with EACCES as expected\n");
 		} else {
-			tst_resm(TFAIL, "open returned unexpected errno - %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		}
 
 		/* Test 2: Check a son process cannot open the file
@@ -157,23 +147,26 @@ void do_master_child()
 			TEST(tst_fd2 = open(testfile, O_RDWR));
 
 			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
+				printf("call succeeded unexpectedly\n");
 				close(tst_fd2);
+				exit(1);
 			}
 
 			TEST_ERROR_LOG(TEST_ERRNO);
 
 			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "open returned errno EACCES");
+				printf("open failed with EACCES as expected\n");
+				exit(0);
 			} else {
-				tst_resm(TFAIL,
-					 "open returned unexpected errno - %d",
-					 TEST_ERRNO);
+				printf("open failed unexpectedly\n");
+				exit(1);
 			}
-			continue;
 		} else {
 			/* Wait for son completion */
-			waitpid(pid, &status, 0);
+			if (waitpid(pid, &status, 0) == -1) {
+				perror("waitpid failed");
+				exit(1);
+			}
 			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
 				exit(WEXITSTATUS(status));
 		}
@@ -183,21 +176,21 @@ void do_master_child()
 		 */
 		Tst_count++;
 		if (setreuid(0, 0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setreuid failed to set the euid to 0");
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "open returned unexpected errno %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		} else {
-			tst_resm(TPASS, "open call succeeded");
+			printf("open call succeeded\n");
 			close(tst_fd);
 		}
 	}
+	exit(0);
 }
 
 /*
@@ -205,9 +198,7 @@ void do_master_child()
  */
 void setup(void)
 {
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
+	tst_require_root(NULL);
 
 	ltpuser = getpwnam(nobody_uid);
 
@@ -241,4 +232,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
-- 
1.7.1

-- 
Best Regards,
Peng Haitao

[-- Attachment #2: 0001-the-child-process-should-exit-0.patch --]
[-- Type: text/plain, Size: 8449 bytes --]

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/kernel/syscalls/setresuid/setresuid04.c |   71 +++++++++------------
 testcases/kernel/syscalls/setreuid/setreuid07.c   |   71 +++++++++------------
 2 files changed, 62 insertions(+), 80 deletions(-)

diff --git a/testcases/kernel/syscalls/setresuid/setresuid04.c b/testcases/kernel/syscalls/setresuid/setresuid04.c
index 13c7a8f..eef0d11 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid04.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid04.c
@@ -74,13 +74,8 @@ int main(int ac, char **av)
 	int status;
 
 	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	 }
-
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	TEST_EXP_ENOS(exp_enos);
@@ -89,20 +84,16 @@ int main(int ac, char **av)
 	if (pid < 0)
 		tst_brkm(TBROK, cleanup, "Fork failed");
 
-	if (pid == 0) {
+	if (pid == 0)
 		do_master_child();
 
-	} else {
-		waitpid(pid, &status, 0);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-			tst_resm(WEXITSTATUS(status),
-				 "son process exits with error");
-	}
+	if (waitpid(pid, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid failed");
+	if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+		tst_resm(TFAIL, "child process terminated abnormally");
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -121,9 +112,8 @@ void do_master_child()
 		Tst_count = 0;
 
 		if (setresuid(0, ltpuser->pw_uid, 0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setresuid failed to set the euid to %d",
-				 ltpuser->pw_uid);
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		/* Test 1: Check the process with new uid cannot open the file
@@ -132,16 +122,16 @@ void do_master_child()
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
+			printf("open succeeded unexpectedly\n");
 			close(tst_fd);
+			exit(1);
 		}
 
 		if (TEST_ERRNO == EACCES) {
-			tst_resm(TPASS, "open returned errno EACCES");
+			printf("open failed with EACCES as expected\n");
 		} else {
-			tst_resm(TFAIL, "open returned unexpected errno - %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		}
 
 		/* Test 2: Check a son process cannot open the file
@@ -158,23 +148,26 @@ void do_master_child()
 			TEST(tst_fd2 = open(testfile, O_RDWR));
 
 			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
+				printf("call succeeded unexpectedly\n");
 				close(tst_fd2);
+				exit(1);
 			}
 
 			TEST_ERROR_LOG(TEST_ERRNO);
 
 			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "open returned errno EACCES");
+				printf("open failed with EACCES as expected\n");
+				exit(0);
 			} else {
-				tst_resm(TFAIL,
-					 "open returned unexpected errno - %d",
-					 TEST_ERRNO);
+				printf("open failed unexpectedly\n");
+				exit(1);
 			}
-			continue;
 		} else {
 			/* Wait for son completion */
-			waitpid(pid, &status, 0);
+			if(waitpid(pid, &status, 0) == -1) {
+				perror("waitpid failed");
+				exit(1);
+			}
 			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
 				exit(WEXITSTATUS(status));
 		}
@@ -184,21 +177,21 @@ void do_master_child()
 		 */
 		Tst_count++;
 		if (setresuid(0, 0, 0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setresuid failed to set the euid to 0");
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "open returned unexpected errno %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		} else {
-			tst_resm(TPASS, "open call succeeded");
+			printf("open call succeeded\n");
 			close(tst_fd);
 		}
 	}
+	exit(0);
 }
 
 /*
@@ -206,9 +199,7 @@ void do_master_child()
  */
 void setup(void)
 {
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
+	tst_require_root(NULL);
 
 	ltpuser = getpwnam(nobody_uid);
 
@@ -242,4 +233,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
diff --git a/testcases/kernel/syscalls/setreuid/setreuid07.c b/testcases/kernel/syscalls/setreuid/setreuid07.c
index 19025cd..69bb25f 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid07.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid07.c
@@ -73,13 +73,8 @@ int main(int ac, char **av)
 	int status;
 
 	/* parse standard options */
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	 }
-
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	TEST_EXP_ENOS(exp_enos);
@@ -88,20 +83,16 @@ int main(int ac, char **av)
 	if (pid < 0)
 		tst_brkm(TBROK, cleanup, "Fork failed");
 
-	if (pid == 0) {
+	if (pid == 0)
 		do_master_child();
 
-	} else {
-		waitpid(pid, &status, 0);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
-			tst_resm(WEXITSTATUS(status),
-				 "son process exits with error");
-	}
+	if (waitpid(pid, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid failed");
+	if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
+		tst_resm(TFAIL, "child process terminated abnormally");
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 /*
@@ -120,9 +111,8 @@ void do_master_child()
 		Tst_count = 0;
 
 		if (setreuid(0, ltpuser->pw_uid) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setreuid failed to set the euid to %d",
-				 ltpuser->pw_uid);
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		/* Test 1: Check the process with new uid cannot open the file
@@ -131,16 +121,16 @@ void do_master_child()
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
+			printf("open succeeded unexpectedly\n");
 			close(tst_fd);
+			exit(1);
 		}
 
 		if (TEST_ERRNO == EACCES) {
-			tst_resm(TPASS, "open returned errno EACCES");
+			printf("open failed with EACCES as expected\n");
 		} else {
-			tst_resm(TFAIL, "open returned unexpected errno - %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		}
 
 		/* Test 2: Check a son process cannot open the file
@@ -157,23 +147,26 @@ void do_master_child()
 			TEST(tst_fd2 = open(testfile, O_RDWR));
 
 			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
+				printf("call succeeded unexpectedly\n");
 				close(tst_fd2);
+				exit(1);
 			}
 
 			TEST_ERROR_LOG(TEST_ERRNO);
 
 			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "open returned errno EACCES");
+				printf("open failed with EACCES as expected\n");
+				exit(0);
 			} else {
-				tst_resm(TFAIL,
-					 "open returned unexpected errno - %d",
-					 TEST_ERRNO);
+				printf("open failed unexpectedly\n");
+				exit(1);
 			}
-			continue;
 		} else {
 			/* Wait for son completion */
-			waitpid(pid, &status, 0);
+			if (waitpid(pid, &status, 0) == -1) {
+				perror("waitpid failed");
+				exit(1);
+			}
 			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
 				exit(WEXITSTATUS(status));
 		}
@@ -183,21 +176,21 @@ void do_master_child()
 		 */
 		Tst_count++;
 		if (setreuid(0, 0) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "setreuid failed to set the euid to 0");
+			perror("setfsuid failed");
+			exit(1);
 		}
 
 		TEST(tst_fd = open(testfile, O_RDWR));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "open returned unexpected errno %d",
-				 TEST_ERRNO);
-			continue;
+			perror("open failed unexpectedly");
+			exit(1);
 		} else {
-			tst_resm(TPASS, "open call succeeded");
+			printf("open call succeeded\n");
 			close(tst_fd);
 		}
 	}
+	exit(0);
 }
 
 /*
@@ -205,9 +198,7 @@ void do_master_child()
  */
 void setup(void)
 {
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
+	tst_require_root(NULL);
 
 	ltpuser = getpwnam(nobody_uid);
 
@@ -241,4 +232,4 @@ void cleanup(void)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
-- 
1.7.1


[-- Attachment #3: Type: text/plain, Size: 429 bytes --]

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-23  9:50             ` Peng Haitao
@ 2011-02-24  5:27               ` Garrett Cooper
  2011-02-24  5:27               ` Garrett Cooper
  1 sibling, 0 replies; 10+ messages in thread
From: Garrett Cooper @ 2011-02-24  5:27 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On Wed, Feb 23, 2011 at 1:50 AM, Peng Haitao <penght@cn.fujitsu.com> wrote:
> Hi Garrett,
>
> Peng Haitao said the following on 2011-2-16 15:27:
>>>     This is what the code currently looks like. I assume the same
>>> needs to be done for the other set*suid syscall testcases?
>>
>> setresuid and setreuid also need to be fixed at least.
>> Thanks.
>>
>
>  The following patch fix the cases of setresuid and setreuid.

Committed -- thanks!
-Garrett

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH] setfsuid04.c: the child process should exit 0
  2011-02-23  9:50             ` Peng Haitao
  2011-02-24  5:27               ` Garrett Cooper
@ 2011-02-24  5:27               ` Garrett Cooper
  1 sibling, 0 replies; 10+ messages in thread
From: Garrett Cooper @ 2011-02-24  5:27 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On Wed, Feb 23, 2011 at 1:50 AM, Peng Haitao <penght@cn.fujitsu.com> wrote:
> Hi Garrett,
>
> Peng Haitao said the following on 2011-2-16 15:27:
>>>     This is what the code currently looks like. I assume the same
>>> needs to be done for the other set*suid syscall testcases?
>>
>> setresuid and setreuid also need to be fixed at least.
>> Thanks.
>>
>
>  The following patch fix the cases of setresuid and setreuid.

Committed -- thanks!
-Garrett

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-02-24  5:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-14  6:05 [LTP] [PATCH] setfsuid04.c: the child process should exit 0 Peng Haitao
2011-02-14  6:23 ` Garrett Cooper
2011-02-14  9:35   ` Peng Haitao
2011-02-15 14:42     ` Garrett Cooper
2011-02-16  6:40       ` Peng Haitao
2011-02-16  6:45         ` Garrett Cooper
2011-02-16  7:27           ` Peng Haitao
2011-02-23  9:50             ` Peng Haitao
2011-02-24  5:27               ` Garrett Cooper
2011-02-24  5:27               ` Garrett Cooper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox