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 <[email protected]>
---
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
Signed-off-by: Peng Haitao <[email protected]>
---
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
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list