From: Cyril H. <su...@li...> - 2013-02-05 07:56:38
|
The branch, master, has been updated via 4d1cf776b9134f0e592c67d4355ed207bf50d903 (commit) via 4582b9c13a7e2b610b3b7cead3f1c0930468b5ff (commit) via 40e9ee3e258dbdc7c957c94e3205d44c7480477b (commit) via 78d42779bb87102d5dd1fd2441c9928d543b5839 (commit) via 32b27f93d536eeccaec2f7586931ee765cae4525 (commit) via b4f038d8087f4c8eb1b0a3c95cb09cf211989fc9 (commit) via 68f73c342c58e570beb15217c57b69dec1c280b7 (commit) via 777588e5b5948a712adc0cafe591f32d9190e1d4 (commit) via 001ce03e83d4f7918307eb7cd57b6721c200e0b5 (commit) via b2c141f68823c9d7968ced2221f75a90b14fdebd (commit) from 4d7e1881df9b25812be790e1d1016cfe8c0b5755 (commit) - Log ----------------------------------------------------------------- commit 4d1cf776b9134f0e592c67d4355ed207bf50d903 Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open10: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit 4582b9c13a7e2b610b3b7cead3f1c0930468b5ff Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open09: rework test case Rework this test case. Signed-off-by: Wanlong Gao <gao...@cn...> commit 40e9ee3e258dbdc7c957c94e3205d44c7480477b Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open08: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit 78d42779bb87102d5dd1fd2441c9928d543b5839 Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open07: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit 32b27f93d536eeccaec2f7586931ee765cae4525 Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open06: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit b4f038d8087f4c8eb1b0a3c95cb09cf211989fc9 Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open05: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit 68f73c342c58e570beb15217c57b69dec1c280b7 Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open04: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit 777588e5b5948a712adc0cafe591f32d9190e1d4 Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open03: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit 001ce03e83d4f7918307eb7cd57b6721c200e0b5 Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open02: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> commit b2c141f68823c9d7968ced2221f75a90b14fdebd Author: Wanlong Gao <gao...@cn...> Date: Mon Feb 4 17:11:18 2013 +0800 open01: code cleanups Cleanup the coding style. Signed-off-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/open/open01.c | 42 ++---- testcases/kernel/syscalls/open/open02.c | 33 ++---- testcases/kernel/syscalls/open/open03.c | 141 ++------------------- testcases/kernel/syscalls/open/open04.c | 74 +++-------- testcases/kernel/syscalls/open/open05.c | 72 ++++-------- testcases/kernel/syscalls/open/open06.c | 57 ++------- testcases/kernel/syscalls/open/open07.c | 136 +++++++++----------- testcases/kernel/syscalls/open/open08.c | 113 +++++++---------- testcases/kernel/syscalls/open/open09.c | 137 +++++++++----------- testcases/kernel/syscalls/open/open10.c | 210 ++++++++++++------------------- 10 files changed, 336 insertions(+), 679 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index 0d5c384..fe8be43 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -59,10 +59,10 @@ char *TCID = "open01"; int TST_TOTAL = 1; -char pfilname[40] = ""; +static char pfilname[40] = ""; -void cleanup(void); -void setup(void); +static void cleanup(void); +static void setup(void); int main(int ac, char **av) { @@ -76,11 +76,11 @@ int main(int ac, char **av) /* * parse standard command line options */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } - setup(); /* global setup for test */ + setup(); /* * check looping state if -i option given on the command line @@ -91,7 +91,8 @@ int main(int ac, char **av) /* test #1 */ TEST(open(pfilname, O_RDWR | O_CREAT, 01444)); - if ((fildes = TEST_RETURN) == -1) { + fildes = TEST_RETURN; + if (fildes == -1) { tst_resm(TFAIL, "Cannot open %s", pfilname); continue; } @@ -134,27 +135,21 @@ int main(int ac, char **av) } /* clean up things is case we are looping */ - if (close(fildes) == -1) { + if (close(fildes) == -1) tst_brkm(TBROK, cleanup, "close #1 failed"); - } - if (unlink(pfilname) == -1) { + if (unlink(pfilname) == -1) tst_brkm(TBROK, cleanup, "can't remove file"); - } - if (close(TEST_RETURN) == -1) { + if (close(TEST_RETURN) == -1) tst_brkm(TBROK, cleanup, "close #2 failed"); - } } - cleanup(); + cleanup(); tst_exit(); } -/* - * setup() - performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { umask(0); @@ -167,18 +162,9 @@ void setup(void) sprintf(pfilname, "open3.%d", getpid()); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at completion or - * premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open02.c b/testcases/kernel/syscalls/open/open02.c index 22dff85..877ac65 100644 --- a/testcases/kernel/syscalls/open/open02.c +++ b/testcases/kernel/syscalls/open/open02.c @@ -53,12 +53,12 @@ char *TCID = "open02"; int TST_TOTAL = 1; -char pfilname[40] = ""; +static char pfilname[40] = ""; -int exp_enos[] = { ENOENT, 0 }; +static int exp_enos[] = { ENOENT, 0 }; -void cleanup(void); -void setup(void); +static void cleanup(void); +static void setup(void); int main(int ac, char **av) { @@ -68,11 +68,11 @@ int main(int ac, char **av) /* * parse standard command line options */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } - setup(); /* global setup for test */ + setup(); TEST_EXP_ENOS(exp_enos); @@ -98,15 +98,12 @@ int main(int ac, char **av) tst_resm(TPASS, "open returned ENOENT"); } } - cleanup(); + cleanup(); tst_exit(); } -/* - * setup() - performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { umask(0); @@ -119,18 +116,8 @@ void setup(void) sprintf(pfilname, "./open3.%d", getpid()); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at completion or - * premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; - tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open03.c b/testcases/kernel/syscalls/open/open03.c index 3446e3c..b47d8a4 100644 --- a/testcases/kernel/syscalls/open/open03.c +++ b/testcases/kernel/syscalls/open/open03.c @@ -23,91 +23,7 @@ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, * Mountain View, CA 94043, or: * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * */ -/* $Id: open03.c,v 1.6 2009/08/28 13:35:01 vapier Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : open03 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for open(2) - * - * PARENT DOCUMENT : xxxtds01 - * - * TEST CASE TOTAL : 1 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) open(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - * - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the open(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * open(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ #include <sys/types.h> #include <sys/fcntl.h> @@ -117,59 +33,42 @@ #include "test.h" #include "usctest.h" -void setup(); -void cleanup(); +static void setup(void); +static void cleanup(void); -char *TCID = "open03"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test cases. */ +char *TCID = "open03"; +int TST_TOTAL = 1; -int exp_enos[] = { 0, 0 }; +static int exp_enos[] = { 0, 0 }; -char fname[255]; -int fd; +static char fname[255]; +static int fd; int main(int ac, char **av) { int lc; char *msg; - /*************************************************************** - * parse standard options - ***************************************************************/ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - /*************************************************************** - * perform global setup for test - ***************************************************************/ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); - /*************************************************************** - * check looping state if -c option given - ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { - Tst_count = 0; - /* - * Call open(2) - */ TEST(open(fname, O_RDWR | O_CREAT, 0700)); - fd = TEST_RETURN; - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL | TTERRNO, "open(%s,O_RDWR|O_CREAT,0700) failed", fname); } else { - /*************************************************************** - * only perform functional verification if flag set (-f not given) - ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, @@ -186,20 +85,12 @@ int main(int ac, char **av) } } - /*************************************************************** - * cleanup and exit - ***************************************************************/ cleanup(); tst_exit(); - } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - ***************************************************************/ -void setup() +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; @@ -209,18 +100,8 @@ void setup() sprintf(fname, "tfile_%d", getpid()); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup() +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; - tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open04.c b/testcases/kernel/syscalls/open/open04.c index 9bc7f65..0eb00ed 100644 --- a/testcases/kernel/syscalls/open/open04.c +++ b/testcases/kernel/syscalls/open/open04.c @@ -18,9 +18,6 @@ */ /* - * NAME - * open04.c - * * DESCRIPTION * Testcase to check that open(2) sets EMFILE if a process opens files * more than its descriptor size @@ -30,23 +27,8 @@ * Use open(2) for creating files till the descriptor table becomes full. * These open(2)s should succeed. Finally use open(2) to open another * file. This attempt should fail with EMFILE. - * - * USAGE: <for command-line> - * open04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * NONE - * */ + #include <stdio.h> #include <errno.h> #include <fcntl.h> @@ -57,31 +39,30 @@ char *TCID = "open04"; int TST_TOTAL = 1; -int fd, ifile, mypid, first; -int nfile; -int *buf; -char fname[40]; +static int fd, ifile, mypid, first; +static int nfile; +static int *buf; +static char fname[40]; -int exp_enos[] = { EMFILE, 0 }; +static int exp_enos[] = { EMFILE, 0 }; -void setup(void); -void cleanup(void); +static void setup(void); +static void cleanup(void); int main(int ac, char **av) { int lc; char *msg; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset Tst_count in case we are looping */ Tst_count = 0; TEST(open(fname, O_RDWR | O_CREAT, 0777)); @@ -93,25 +74,20 @@ int main(int ac, char **av) TEST_ERROR_LOG(TEST_ERRNO); - if (TEST_ERRNO != EMFILE) { + if (TEST_ERRNO != EMFILE) tst_resm(TFAIL, "Expected EMFILE, got %d", TEST_ERRNO); - } else { + else tst_resm(TPASS, "call returned expected EMFILE error"); - } } + close(first); close(fd); cleanup(); tst_exit(); - } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup() +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; @@ -123,22 +99,23 @@ void setup() nfile = getdtablesize(); sprintf(fname, "open04.%d", mypid); - if ((first = fd = open(fname, O_RDWR | O_CREAT, 0777)) == -1) { + first = fd = open(fname, O_RDWR | O_CREAT, 0777); + if (first == -1) tst_brkm(TBROK, cleanup, "Cannot open first file"); - } close(fd); close(first); unlink(fname); /* Allocate memory for stat and ustat structure variables */ - if ((buf = (int *)malloc(sizeof(int) * nfile - first)) == NULL) { + buf = malloc(sizeof(int) * nfile - first); + if (buf == NULL) tst_brkm(TBROK, NULL, "Failed to allocate Memory"); - } for (ifile = first; ifile <= nfile; ifile++) { sprintf(fname, "open04.%d.%d", ifile, mypid); - if ((fd = open(fname, O_RDWR | O_CREAT, 0777)) == -1) { + fd = open(fname, O_RDWR | O_CREAT, 0777); + if (fd == -1) { if (errno != EMFILE) { tst_brkm(TBROK, cleanup, "Expected EMFILE got " "%d", errno); @@ -149,16 +126,8 @@ void setup() } } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup() +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ close(first); TEST_CLEANUP; @@ -171,5 +140,4 @@ void cleanup() /* delete the test directory created in setup() */ tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open05.c b/testcases/kernel/syscalls/open/open05.c index 491eaff..b18f29d 100644 --- a/testcases/kernel/syscalls/open/open05.c +++ b/testcases/kernel/syscalls/open/open05.c @@ -18,28 +18,14 @@ */ /* - * NAME - * open05.c - * * DESCRIPTION * Testcase to check open(2) sets errno to EACCES correctly. * * ALGORITHM * Create a file owned by root with no read permission for other users. * Attempt to open it as ltpuser(1). The attempt should fail with EACCES. - * - * USAGE: <for command-line> - * open05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * * RESTRICTION * Must run test as root. - * */ #include <errno.h> #include <pwd.h> @@ -50,20 +36,20 @@ #include "test.h" #include "usctest.h" -char user1name[] = "nobody"; +static char user1name[] = "nobody"; char *TCID = "open05"; int TST_TOTAL = 1; extern struct passwd *my_getpwnam(char *); -char fname[20]; -struct passwd *nobody; -int fd; +static char fname[20]; +static struct passwd *nobody; +static int fd; -int exp_enos[] = { EACCES, 0 }; +static int exp_enos[] = { EACCES, 0 }; -void cleanup(void); -void setup(void); +static void cleanup(void); +static void setup(void); int main(int ac, char **av) { @@ -72,24 +58,23 @@ int main(int ac, char **av) int e_code, status, retval = 0; pid_t pid; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset Tst_count in case we are looping */ Tst_count = 0; - if ((pid = FORK_OR_VFORK()) == -1) { + pid = FORK_OR_VFORK(); + if (pid == -1) tst_brkm(TBROK, cleanup, "fork() failed"); - } - if (pid == 0) { /* child */ + if (pid == 0) { if (seteuid(nobody->pw_uid) == -1) { tst_resm(TWARN, "seteuid() failed, errno: %d", errno); @@ -114,37 +99,33 @@ int main(int ac, char **av) } /* set the id back to root */ - if (seteuid(0) == -1) { + if (seteuid(0) == -1) tst_resm(TWARN, "seteuid(0) failed"); - } + exit(retval); - } else { /* parent */ + } else { /* wait for the child to finish */ wait(&status); /* make sure the child returned a good exit status */ e_code = status >> 8; - if ((e_code != 0) || (retval != 0)) { + if ((e_code != 0) || (retval != 0)) tst_resm(TFAIL, "Failures reported above"); - } close(fd); cleanup(); } } + tst_exit(); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup() +static void setup(void) { /* test must be run as root */ - if (geteuid() != 0) { + if (geteuid() != 0) tst_brkm(TBROK, NULL, "Must run test as root"); - } tst_sig(FORK, DEF_HANDLER, cleanup); @@ -157,26 +138,17 @@ void setup() nobody = my_getpwnam(user1name); - if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) { + fd = open(fname, O_RDWR | O_CREAT, 0700); + if (fd == -1) tst_brkm(TBROK, cleanup, "open() failed, errno: %d", errno); - } } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup() +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; unlink(fname); /* delete the test directory created in setup() */ tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open06.c b/testcases/kernel/syscalls/open/open06.c index db9f9c4..fc6c093 100644 --- a/testcases/kernel/syscalls/open/open06.c +++ b/testcases/kernel/syscalls/open/open06.c @@ -18,9 +18,6 @@ */ /* - * NAME - * open06.c - * * DESCRIPTION * Testcase to check open(2) sets errno to ENXIO correctly. * @@ -28,21 +25,6 @@ * Create a named pipe using mknod(2). Attempt to * open(2) the pipe for writing. The open(2) should * fail with ENXIO. - * - * USAGE: <for command-line> - * open06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * NONE */ #include <sys/types.h> #include <sys/stat.h> @@ -55,29 +37,27 @@ char *TCID = "open06"; int TST_TOTAL = 1; -void setup(void); -void cleanup(void); +static void setup(void); +static void cleanup(void); -char fname[100] = "fifo"; +static char fname[100] = "fifo"; -int exp_enos[] = { ENXIO, 0 }; +static int exp_enos[] = { ENXIO, 0 }; int main(int ac, char **av) { int lc; char *msg; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { - - /* reset Tst_count in case we are looping */ Tst_count = 0; TEST(open(fname, O_NONBLOCK | O_WRONLY)); @@ -88,27 +68,22 @@ int main(int ac, char **av) TEST_ERROR_LOG(TEST_ERRNO); - if (TEST_ERRNO != ENXIO) { + if (TEST_ERRNO != ENXIO) tst_resm(TFAIL, "Expected ENXIO got %d", TEST_ERRNO); - } else { + else tst_resm(TPASS, "call returned expected ENXIO error"); - } } + cleanup(); tst_exit(); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup() +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; - /* make a temporary directory and cd to it */ tst_tmpdir(); sprintf(fname, "%s.%d", fname, getpid()); @@ -117,21 +92,11 @@ void setup() tst_brkm(TBROK, cleanup, "mknod FAILED"); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup() +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; unlink(fname); - /* delete the test directory created in setup() */ tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open07.c b/testcases/kernel/syscalls/open/open07.c index e652132..373691a 100644 --- a/testcases/kernel/syscalls/open/open07.c +++ b/testcases/kernel/syscalls/open/open07.c @@ -40,7 +40,7 @@ * 4. Create a symbolic link to a symbolically linked directory, and call * open(O_NOFOLLOW). Check that it returns ELOOP. * - * 5. Create a symbolic link to a directory, and call + * 5. Create a symbolic link to a directory, and call * open("link/", O_NOFOLLOW). Check that it succeeds. * * USAGE: <for command-line> @@ -67,21 +67,22 @@ #include "test.h" #include "usctest.h" -void setup(void); -void cleanup(void); -void setupfunc_test1(); -void setupfunc_test2(); -void setupfunc_test3(); -void setupfunc_test4(); -void setupfunc_test5(); +static void setup(void); +static void cleanup(void); +static void setupfunc_test1(); +static void setupfunc_test2(); +static void setupfunc_test3(); +static void setupfunc_test4(); +static void setupfunc_test5(); char *TCID = "open07"; int TST_TOTAL = 5; -int fd1, fd2; -int exp_enos[] = { ELOOP, 0 }; +static int fd1, fd2; -struct test_case_t { +static int exp_enos[] = { ELOOP, 0 }; + +static struct test_case_t { char *desc; char filename[100]; int flags; @@ -89,19 +90,17 @@ struct test_case_t { void (*setupfunc) (); int exp_errno; } TC[] = { - { - "Test for ELOOP on f2: f1 -> f2", { - }, O_NOFOLLOW, 00700, setupfunc_test1, ELOOP}, { - "Test for ELOOP on d2: d1 -> d2", { - }, O_NOFOLLOW, 00700, setupfunc_test2, ELOOP}, { - "Test for ELOOP on f3: f1 -> f2 -> f3", { - }, O_NOFOLLOW, 00700, setupfunc_test3, ELOOP}, { - "Test for ELOOP on d3: d1 -> d2 -> d3", { - }, O_NOFOLLOW, 00700, setupfunc_test4, ELOOP}, { - "Test for success on d2: d1 -> d2", { - }, O_NOFOLLOW, 00700, setupfunc_test5, 0}, { - NULL, { - }, 0, 0, NULL, 0} + {"Test for ELOOP on f2: f1 -> f2", {}, + O_NOFOLLOW, 00700, setupfunc_test1, ELOOP}, + {"Test for ELOOP on d2: d1 -> d2", {}, + O_NOFOLLOW, 00700, setupfunc_test2, ELOOP}, + {"Test for ELOOP on f3: f1 -> f2 -> f3", {}, + O_NOFOLLOW, 00700, setupfunc_test3, ELOOP}, + {"Test for ELOOP on d3: d1 -> d2 -> d3", {}, + O_NOFOLLOW, 00700, setupfunc_test4, ELOOP}, + {"Test for success on d2: d1 -> d2", {}, + O_NOFOLLOW, 00700, setupfunc_test5, 0}, + {NULL, {}, 0, 0, NULL, 0} }; int main(int ac, char **av) @@ -110,9 +109,9 @@ int main(int ac, char **av) char *msg; int i; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } setup(); @@ -120,19 +119,14 @@ int main(int ac, char **av) /* run the setup routines for the individual tests */ for (i = 0; i < TST_TOTAL; i++) { - if (TC[i].setupfunc != NULL) { + if (TC[i].setupfunc != NULL) TC[i].setupfunc(); - } } - /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { - - /* reset Tst_count in case we are looping */ Tst_count = 0; for (i = 0; TC[i].desc != NULL; ++i) { - TEST(open(TC[i].filename, TC[i].flags, TC[i].mode)); if (TC[i].exp_errno != 0) { @@ -161,102 +155,103 @@ int main(int ac, char **av) "expected"); } } + if (TEST_RETURN != -1) close(TEST_RETURN); } } + cleanup(); tst_exit(); } -void setupfunc_test1() +static void setupfunc_test1() { char file1[100], file2[100]; sprintf(file1, "open03.1.%d", getpid()); sprintf(file2, "open03.2.%d", getpid()); - if ((fd1 = creat(file1, 00700)) < 0) { + fd1 = creat(file1, 00700); + if (fd1 < 0) tst_brkm(TBROK, cleanup, "creat(2) failed: errno: %d", errno); - } - if (symlink(file1, file2) < 0) { + + if (symlink(file1, file2) < 0) tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); - } + strcpy(TC[0].filename, file2); } -void setupfunc_test2() +static void setupfunc_test2() { char file1[100], file2[100]; sprintf(file1, "open03.3.%d", getpid()); sprintf(file2, "open03.4.%d", getpid()); - if (mkdir(file1, 00700) < 0) { + if (mkdir(file1, 00700) < 0) tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno); - } - if (symlink(file1, file2) < 0) { + + if (symlink(file1, file2) < 0) tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); - } + strcpy(TC[1].filename, file2); } -void setupfunc_test3() +static void setupfunc_test3() { char file1[100], file2[100], file3[100]; sprintf(file1, "open03.5.%d", getpid()); sprintf(file2, "open03.6.%d", getpid()); sprintf(file3, "open03.7.%d", getpid()); - if ((fd2 = creat(file1, 00700)) < 0) { + fd2 = creat(file1, 00700); + if (fd2 < 0) tst_brkm(TBROK, cleanup, "creat(2) failed: errno: %d", errno); - } - if (symlink(file1, file2) < 0) { + + if (symlink(file1, file2) < 0) tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); - } - if (symlink(file2, file3) < 0) { + + if (symlink(file2, file3) < 0) tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); - } + strcpy(TC[2].filename, file3); } -void setupfunc_test4() +static void setupfunc_test4() { char file1[100], file2[100], file3[100]; sprintf(file1, "open03.8.%d", getpid()); sprintf(file2, "open03.9.%d", getpid()); sprintf(file3, "open03.10.%d", getpid()); - if (mkdir(file1, 00700) < 0) { + if (mkdir(file1, 00700) < 0) tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno); - } - if (symlink(file1, file2) < 0) { + + if (symlink(file1, file2) < 0) tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); - } - if (symlink(file2, file3) < 0) { + + if (symlink(file2, file3) < 0) tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); - } + strcpy(TC[3].filename, file3); } -void setupfunc_test5() +static void setupfunc_test5() { char file1[100], file2[100]; sprintf(file1, "open11.3.%d", getpid()); sprintf(file2, "open12.4.%d", getpid()); - if (mkdir(file1, 00700) < 0) { + if (mkdir(file1, 00700) < 0) tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno); - } - if (symlink(file1, file2) < 0) { + + if (symlink(file1, file2) < 0) tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); - } + strcpy(TC[4].filename, file2); strcat(TC[4].filename, "/"); } -/* - * setup() - performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { umask(0); @@ -267,20 +262,11 @@ void setup(void) tst_tmpdir(); } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing status if that option was specified. - * print errno log if that option was specified - */ TEST_CLEANUP; close(fd1); close(fd2); tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open08.c b/testcases/kernel/syscalls/open/open08.c index 754f2dd..0e94d92 100644 --- a/testcases/kernel/syscalls/open/open08.c +++ b/testcases/kernel/syscalls/open/open08.c @@ -1,7 +1,22 @@ /* - * NAME - * open08.c + * Copyright (c) 2013 Wanlong Gao <gao...@cn...> * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* * DESCRIPTION * Check for the following errors: * 1. EEXIST @@ -30,22 +45,8 @@ * 6. Attempt to pass an invalid pathname with an address pointing outside * the address space of the process, as the argument to open(), and * expect to get EFAULT. - * - * USAGE: <for command-line> - * open08 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None */ + #define _GNU_SOURCE /* for O_DIRECTORY */ #include <sys/types.h> #include <sys/stat.h> @@ -58,37 +59,35 @@ #include "test.h" #include "usctest.h" -void setup(void); -void cleanup(void); +static void setup(void); +static void cleanup(void); char *TCID = "open08"; -char nobody_uid[] = "nobody"; -struct passwd *ltpuser; +static char nobody_uid[] = "nobody"; +static struct passwd *ltpuser; -int exp_enos[] = { EEXIST, EISDIR, ENOTDIR, ENAMETOOLONG, EACCES, EFAULT, 0 }; +static int exp_enos[] = {EEXIST, EISDIR, ENOTDIR, ENAMETOOLONG, + EACCES, EFAULT, 0}; -char *bad_addr = 0; +static char *bad_addr; -char filename[40] = ""; -char fname[] = "/bin/cat"; /* test executable to open */ -char bad_file[] = - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; +static char filename[40] = ""; +static char fname[] = "/bin/cat"; +static char bad_file[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; -struct test_case_t { +static struct test_case_t { char *fname; int flags; int error; } TC[] = { - { - filename, O_CREAT | O_EXCL, EEXIST}, { - "/tmp", O_RDWR, EISDIR}, { - filename, O_DIRECTORY, ENOTDIR}, { - bad_file, O_RDWR, ENAMETOOLONG}, { - fname, O_WRONLY, EACCES}, + {filename, O_CREAT | O_EXCL, EEXIST}, + {"/tmp", O_RDWR, EISDIR}, + {filename, O_DIRECTORY, ENOTDIR}, + {bad_file, O_RDWR, ENAMETOOLONG}, + {fname, O_WRONLY, EACCES}, #if !defined(UCLINUX) - { - (char *)-1, O_CREAT, EFAULT} + {(char *)-1, O_CREAT, EFAULT} #endif }; @@ -100,24 +99,18 @@ int main(int ac, char **av) char *msg; int i; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } setup(); - /* set up the expected errnos */ TEST_EXP_ENOS(exp_enos); - /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { - - /* reset Tst_count in case we are looping */ Tst_count = 0; - /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { - TEST(open(TC[i].fname, TC[i].flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)); @@ -139,15 +132,12 @@ int main(int ac, char **av) } } } - cleanup(); + cleanup(); tst_exit(); } -/* - * setup() - performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { int fildes; @@ -158,9 +148,9 @@ void setup(void) TEST_PAUSE; /* Switch to nobody user for correct error code collection */ - if (geteuid() != 0) { + if (geteuid() != 0) tst_brkm(TBROK, NULL, "Test must be run as root"); - } + ltpuser = getpwnam(nobody_uid); if (setgid(ltpuser->pw_gid) == -1) { tst_brkm(TBROK | TERRNO, NULL, "setgid(%d) failed", @@ -174,33 +164,24 @@ void setup(void) sprintf(filename, "open3.%d", getpid()); - if ((fildes = creat(filename, 0600)) == -1) { + fildes = creat(filename, 0600); + if (fildes == -1) tst_brkm(TBROK, cleanup, "Can't creat %s", filename); - } + close(fildes); #if !defined(UCLINUX) bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); - if (bad_addr == MAP_FAILED) { + if (bad_addr == MAP_FAILED) tst_brkm(TBROK, cleanup, "mmap failed"); - } + TC[5].fname = bad_addr; #endif } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing status if that option was specified. - * print errno log if that option was specified - */ TEST_CLEANUP; - tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/open/open09.c b/testcases/kernel/syscalls/open/open09.c index d9564be..e5a3dbe 100644 --- a/testcases/kernel/syscalls/open/open09.c +++ b/testcases/kernel/syscalls/open/open09.c @@ -1,6 +1,6 @@ /* - * * Copyright (c) International Business Machines Corp., 2002 + * Copyright (c) 2013 Wanlong Gao <gao...@cn...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,18 +17,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* Ported from SPIE, section2/iosuite/open1.c, by Airong Zhang */ - -/*====================================================================== - =================== TESTPLAN SEGMENT =================== ->KEYS: < open() ->WHAT: < Does a read on a file opened with oflag = O_WRONLY return -1? - < Does a write on a file opened with oflag = O_RDONLY return -1? ->HOW: < Open a file with O_WRONLY, test for -1 to pass - < Open a file with O_RDONLY, test for -1 to pass ->BUGS: < DUMMY functions used in BSD ->AUTHOR:< PERENNIAL -======================================================================*/ +/* + * Description: + * 1. open an O_WRONLY file, test if read failed. + * 2. open an O_RDONLY file, test if write failed. + */ #include <sys/types.h> #include <sys/stat.h> @@ -38,16 +31,16 @@ #include "usctest.h" char *TCID = "open09"; -int TST_TOTAL = 1; -int local_flag; +int TST_TOTAL = 2; #define PASSED 1 #define FAILED 0 -char progname[] = "open09()"; -char tempfile[40] = ""; +static char tempfile[40] = ""; + +static void setup(void); +static void cleanup(void); -/*--------------------------------------------------------------------*/ int main(int ac, char *av[]) { int fildes; @@ -56,76 +49,66 @@ int main(int ac, char *av[]) int lc; char *msg; - int fail_count = 0; - - /* - * parse standard options - */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { - tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg); - tst_exit(); - } - tst_tmpdir(); - local_flag = PASSED; - sprintf(tempfile, "open09.%d", getpid()); -/*--------------------------------------------------------------------*/ + + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + + setup(); + for (lc = 0; TEST_LOOPING(lc); lc++) { - local_flag = PASSED; - //block0: - if ((fildes = creat(tempfile, 0600)) == -1) { - tst_resm(TBROK, "\t\t\tcan't create '%s'", tempfile); - tst_exit(); - } else { - close(fildes); - if ((fildes = open(tempfile, 1)) == -1) { - tst_resm(TFAIL, "\t\t\topen failed"); - tst_exit(); - } - } + fildes = open(tempfile, O_WRONLY); + if (fildes == -1) + tst_brkm(TFAIL, cleanup, "\t\t\topen failed"); + ret = read(fildes, pbuf, 1); - if (ret != -1) { + if (ret != -1) tst_resm(TFAIL, "read should not succeed"); - local_flag = FAILED; - } - close(fildes); + else + tst_resm(TPASS, "Test passed in O_WRONLY."); - if (local_flag == PASSED) { - tst_resm(TPASS, "Test passed in block0."); - } else { - tst_resm(TFAIL, "Test failed in block0."); - fail_count++; - } + close(fildes); - local_flag = PASSED; - /*--------------------------------------------------------------------*/ - //block1: - if ((fildes = open(tempfile, 0)) == -1) { + fildes = open(tempfile, O_RDONLY); + if (fildes == -1) { tst_resm(TFAIL, "\t\t\topen failed"); - local_flag = FAILED; } else { ret = write(fildes, pbuf, 1); - if (ret != -1) { - tst_resm(TFAIL, "writeshould not succeed"); - local_flag = FAILED; - } + if (ret != -1) + tst_resm(TFAIL, "write should not succeed"); + else + tst_resm(TPASS, "Test passed in O_RDONLY."); } close(fildes); - if (local_flag == PASSED) { - tst_resm(TPASS, "Test passed in block1."); - } else { - tst_resm(TFAIL, "Test failed in block1."); - fail_count++; - } - /*--------------------------------------------------------------------*/ - unlink(tempfile); - tst_rmdir(); + } - if (fail_count == 0) { - tst_resm(TPASS, "Test passed."); - } else { - tst_resm(TFAIL, "Test failed due to above failures."); - } - } /* end for */ + cleanup(); tst_exit(); } + +static void setup(void) +{ + int fildes; + + tst_sig(NOFORK, DEF_HANDLER, cleanup); + TEST_PAUSE; + tst_tmpdir(); + + sprintf(tempfile, "open09.%d", getpid()); + + fildes = creat(tempfile, 0600); + if (fildes == -1) { + tst_brkm(TBROK, cleanup, "\t\t\tcan't create '%s'", + tempfile); + } else { + close(fildes); + } +} + +static void cleanup(void) +{ + TEST_CLEANUP; + unlink(tempfile); + tst_rmdir(); +} diff --git a/testcases/kernel/syscalls/open/open10.c b/testcases/kernel/syscalls/open/open10.c index 6888203..275299e 100644 --- a/testcases/kernel/syscalls/open/open10.c +++ b/testcases/kernel/syscalls/open/open10.c @@ -18,14 +18,9 @@ */ /* - * NAME - * open10.c - Verifies that the group ID and setgid bit are - * set correctly when a new file is created using open. - * (ported from SPIE, section2/iosuite/open5.c, by - * Airong Zhang) - * - * CALLS - * open + * Description: + * Verifies that the group ID and setgid bit are + * set correctly when a new file is created using open. * * ALGORITHM * Create two directories, one with the group ID of this process @@ -37,15 +32,9 @@ * As root, create a file with the setgid bit on in the * directory with the setgid bit. * This tests the SVID3 create group semantics. - * - * USAGE - * open10 - * - * RESTRICTIONS - * */ -#include <stdio.h> /* needed by testhead.h */ +#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/fcntl.h> @@ -57,15 +46,13 @@ char *TCID = "open10"; int TST_TOTAL = 1; -int local_flag; +static int local_flag; #define PASSED 1 #define FAILED 0 -int local_flag; - -#define MODE_RWX S_IRWXU | S_IRWXG | S_IRWXO -#define MODE_SGID S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO +#define MODE_RWX (S_IRWXU | S_IRWXG | S_IRWXO) +#define MODE_SGID (S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO) #define DIR_A_TEMP "open10.testdir.A.%d" #define DIR_B_TEMP "open10.testdir.B.%d" #define SETGID "setgid" @@ -73,34 +60,9 @@ int local_flag; #define ROOT_SETGID "root_setgid" #define MSGSIZE 150 -void cleanup(void); - -char progname[] = "open10()"; +static void setup(void); +static void cleanup(void); -int issu() -{ - - int uid; - - uid = (-1); - uid = geteuid(); - - if (uid == (-1)) { - fprintf(stderr, "geteuid: failed in issu()"); - return (-1); - } - - if (uid == 0) { - return 0; - } else { - fprintf(stderr, "*** NOT SUPERUSER must be root %s\n", - progname); - return (uid); - } - return 0; -} - -/*--------------------------------------------------------------*/ int main(int ac, char *av[]) { int ret; @@ -118,21 +80,13 @@ int main(int ac, char *av[]) char *msg; int fail_count = 0; - /* - * parse standard options - */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } - tst_tmpdir(); + setup(); - if (issu() != 0) { - tst_resm(TINFO, "Must be root to run this test."); - cleanup(); - } for (lc = 0; TEST_LOOPING(lc); lc++) { - local_flag = PASSED; save_myuid = getuid(); @@ -146,46 +100,45 @@ int main(int ac, char *av[]) sprintf(root_setgid_B, "%s/%s", DIR_B, ROOT_SETGID); /* Get the uid of user1 */ - if ((user1 = getpwnam("nobody")) == NULL) { + user1 = getpwnam("nobody"); + if (user1 == NULL) tst_brkm(TBROK, cleanup, "nobody not in /etc/passwd"); - } + user1_uid = user1->pw_uid; /* * Get the group IDs of group1 and group2. */ - if ((group = getgrnam("nobody")) == NULL) { - if ((group = getgrnam("nogroup")) == NULL) { + group = getgrnam("nobody"); + if (group == NULL) { + group = getgrnam("nogroup"); + if (group == NULL) { tst_brkm(TBROK, cleanup, "nobody/nogroup not in /etc/group"); } } group1_gid = group->gr_gid; - if ((group = getgrnam("bin")) == NULL) { + group = getgrnam("bin"); + if (group == NULL) tst_brkm(TBROK, cleanup, "bin not in /etc/group"); - } - group2_gid = group->gr_gid; - /*--------------------------------------------------------------*/ - /* Block0: Set up the parent directories */ - /*--------------------------------------------------------------*/ - //block0: + group2_gid = group->gr_gid; /* * Create a directory with group id the same as this process * and with no setgid bit. */ - if ((ret = mkdir(DIR_A, MODE_RWX)) < 0) { + if (mkdir(DIR_A, MODE_RWX) < 0) { tst_resm(TFAIL | TERRNO, "mkdir(%s) failed", DIR_A); local_flag = FAILED; } - if ((ret = chown(DIR_A, user1_uid, group2_gid)) < 0) { + if (chown(DIR_A, user1_uid, group2_gid) < 0) { tst_resm(TFAIL | TERRNO, "chown(%s) failed", DIR_A); local_flag = FAILED; } - if ((ret = stat(DIR_A, &buf)) < 0) { + if (stat(DIR_A, &buf) < 0) { tst_resm(TFAIL | TERRNO, "stat(%s) failed", DIR_A); local_flag = FAILED; } @@ -208,22 +161,22 @@ int main(int ac, char *av[]) * Create a directory with group id different from that of * this process and with the setgid bit set. */ - if ((ret = mkdir(DIR_B, MODE_RWX)) < 0) { + if (mkdir(DIR_B, MODE_RWX) < 0) { tst_resm(TFAIL | TERRNO, "mkdir(%s) failed", DIR_B); local_flag = FAILED; } - if ((ret = chown(DIR_B, user1_uid, group2_gid)) < 0) { + if (chown(DIR_B, user1_uid, group2_gid) < 0) { tst_resm(TFAIL | TERRNO, "chown(%s) failed", DIR_B); local_flag = FAILED; } - if ((ret = chmod(DIR_B, MODE_SGID)) < 0) { + if (chmod(DIR_B, MODE_SGID) < 0) { tst_resm(TFAIL | TERRNO, "chmod(%s) failed", DIR_B); local_flag = FAILED; } - if ((ret = stat(DIR_B, &buf)) < 0) { + if (stat(DIR_B, &buf) < 0) { tst_resm(TFAIL | TERRNO, "stat(%s) failed", DIR_B); local_flag = FAILED; } @@ -252,26 +205,21 @@ int main(int ac, char *av[]) local_flag = PASSED; - /*--------------------------------------------------------------*/ - /* Block1: Create two files in testdir.A, one with the setgid */ - /* bit set in the creation modes and the other without. */ - /* Both should inherit the group ID of the process and */ - /* maintain the setgid bit as specified in the creation */ - /* modes. */ - /*--------------------------------------------------------------*/ - //block1: - /* - * Now become user1, group1 + * Create two files in testdir.A, one with the setgid + * bit set in the creation modes and the other without. + * Both should inherit the group ID of the process and + * maintain the setgid bit as specified in the creation + * modes. */ - if ((ret = setgid(group1_gid)) < 0) { + if (setgid(group1_gid) < 0) { tst_resm(TINFO, "Unable to set process group ID to group1"); } - if ((ret = setreuid(-1, user1_uid)) < 0) { + if (setreuid(-1, user1_uid) < 0) tst_resm(TINFO, "Unable to set process uid to user1"); - } + mygid = getgid(); /* @@ -284,7 +232,7 @@ int main(int ac, char *av[]) } close(ret); - if ((ret = stat(nosetgid_A, &buf)) < 0) { + if (stat(nosetgid_A, &buf) < 0) { tst_resm(TFAIL | TERRNO, "stat(%s) failed", nosetgid_A); local_flag = FAILED; } @@ -313,7 +261,7 @@ int main(int ac, char *av[]) } close(ret); - if ((ret = stat(setgid_A, &buf)) < 0) { + if (stat(setgid_A, &buf) < 0) { tst_resm(TFAIL | TERRNO, "stat(%s) failed", setgid_A); local_flag = FAILED; } @@ -342,15 +290,13 @@ int main(int ac, char *av[]) local_flag = PASSED; - /*--------------------------------------------------------------*/ - /* Block2: Create two files in testdir.B, one with the setgid */ - /* bit set in the creation modes and the other without. */ - /* Both should inherit the group ID of the parent */ - /* directory, group2. Either file should have the segid */ - /* bit set in the modes. */ - /*--------------------------------------------------------------*/ - //block2: - + /* + * Create two files in testdir.B, one with the setgid + * bit set in the creation modes and the other without. + * Both should inherit the group ID of the parent + * directory, group2. Either file should have the segid + * bit set in the modes. + */ /* * Create the file with setgid not set */ @@ -361,7 +307,7 @@ int main(int ac, char *av[]) } close(ret); - if ((ret = stat(nosetgid_B, &buf)) < 0) { + if (stat(nosetgid_B, &buf) < 0) { tst_resm(TFAIL | TERRNO, "stat(%s) failed", nosetgid_B); local_flag = FAILED; } @@ -391,7 +337,7 @@ int main(int ac, char *av[]) } close(ret); - if ((ret = stat(setgid_B, &buf)) < 0) { + if (stat(setgid_B, &buf) < 0) { tst_resm(TFAIL | TERRNO, "stat(%s) failed", setgid_B); local_flag = FAILED; } @@ -420,31 +366,30 @@ int main(int ac, char *av[]) local_flag = PASSED; - /*--------------------------------------------------------------*/ - /* Block3: Create a file in testdir.B, with the setgid bit set */ - /* in the creation modes and do so as root. The file */ - /* should inherit the group ID of the parent directory, */ - /* group2 and should have the setgid bit set. */ - /*--------------------------------------------------------------*/ - //block3: + /* + * Create a file in testdir.B, with the setgid bit set + * in the creation modes and do so as root. The file + * should inherit the group ID of the parent directory, + * group2 and should have the setgid bit set. + */ /* Become root again */ - if ((ret = setreuid(-1, save_myuid)) < 0) { + if (setreuid(-1, save_myuid) < 0) { tst_resm(TFAIL | TERRNO, "Changing back to root failed"); local_flag = FAILED; } /* Create the file with setgid set */ - if ((ret = open(root_setgid_B, O_CREAT | O_EXCL | O_RDWR, - MODE_SGID)) < 0) { + ret = open(root_setgid_B, O_CREAT | O_EXCL | O_RDWR, MODE_SGID); + if (ret < 0) { tst_resm(TFAIL | TERRNO, "open(%s) failed", root_setgid_B); local_flag = FAILED; } close(ret); - if ((ret = stat(root_setgid_B, &buf)) < 0) { + if (stat(root_setgid_B, &buf) < 0) { tst_resm(TFAIL | TERRNO, "stat(%s) failed", root_setgid_B); local_flag = FAILED; @@ -472,27 +417,27 @@ int main(int ac, char *av[]) fail_count++; } - /*--------------------------------------------------------------*/ - /* Clean up any files created by test before call to anyfail. */ - /* Remove the directories. */ - /*--------------------------------------------------------------*/ - if ((ret = unlink(setgid_A)) < 0) + /* + * Clean up any files created by test before call to anyfail. + * Remove the directories. + */ + if (unlink(setgid_A) < 0) tst_resm(TWARN | TERRNO, "unlink(%s) failed", setgid_A); - if ((ret = unlink(nosetgid_A)) < 0) + if (unlink(nosetgid_A) < 0) tst_resm(TWARN | TERRNO, "unlink(%s) failed", nosetgid_A); - if ((ret = rmdir(DIR_A)) < 0) + if (rmdir(DIR_A) < 0) tst_resm(TWARN | TERRNO, "rmdir(%s) failed", DIR_A); - if ((ret = unlink(setgid_B)) < 0) + if (unlink(setgid_B) < 0) tst_resm(TWARN | TERRNO, "unlink(%s) failed", setgid_B); - if ((ret = unlink(root_setgid_B)) < 0) + if (unlink(root_setgid_B) < 0) tst_resm(TWARN | TERRNO, "unlink(%s) failed", root_setgid_B); - if ((ret = unlink(nosetgid_B)) < 0) + if (unlink(nosetgid_B) < 0) tst_resm(TWARN | TERRNO, "unlink(%s) failed", nosetgid_B); - if ((ret = rmdir(DIR_B)) < 0) + if (rmdir(DIR_B) < 0) tst_resm(TWARN | TERRNO, "rmdir(%s) failed", DIR_B); if (fail_count == 0) { @@ -503,18 +448,21 @@ int main(int ac, char *av[]) } } + cleanup(); tst_exit(); } -void cleanup(void) +static void setup(void) { - /* - * print timing status if that option was specified. - * print errno log if that option was specified - */ - TEST_CLEANUP; + tst_require_root(NULL); + tst_sig(NOFORK, DEF_HANDLER, cleanup); + TEST_PAUSE; + tst_tmpdir(); +} +static void cleanup(void) +{ + TEST_CLEANUP; tst_rmdir(); - } hooks/post-receive -- ltp |