syscalls/mprotect: Cleanup.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
diff --git a/testcases/kernel/syscalls/mprotect/mprotect01.c b/testcases/kernel/syscalls/mprotect/mprotect01.c
index e635fed..b781968 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect01.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect01.c
@@ -1,26 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * Copyright (c) International Business Machines Corp., 2001
+ * 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 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.
*
- * 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
+ * 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
*/
/*
- * NAME
- * mprotect01.c
- *
* DESCRIPTION
* Testcase to check the error conditions for mprotect(2)
*
@@ -36,28 +32,16 @@
* Try to set write permission (PROT_WRITE) using mprotect(2).
* Check that error is set to EACCES.
*
- * USAGE: <for command-line>
- * mprotect01 [-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
* 03/2002 Paul Larson: case 1 should expect ENOMEM not EFAULT
- *
- * RESTRICTIONS
- * None
*/
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include <stdlib.h>
-#include <limits.h> /* for PAGESIZE */
+#include <limits.h>
#include <unistd.h>
#include "test.h"
#include "usctest.h"
@@ -66,19 +50,19 @@
#define PAGESIZE 4096
#endif
-void cleanup(void);
-void setup(void);
-void setup1(void);
-void setup2(void);
-void setup3(void);
+static void cleanup(void);
+static void setup(void);
+static void setup1(void);
+static void setup2(void);
+static void setup3(void);
char *TCID = "mprotect01";
int TST_TOTAL = 3;
-void *addr1, *addr2, *addr3;
-int fd;
+static void *addr1, *addr2, *addr3;
+static int fd;
-int exp_enos[] = { ENOMEM, EINVAL, EACCES, 0 };
+static int exp_enos[] = { ENOMEM, EINVAL, EACCES, 0 };
struct test_case_t {
void **addr;
@@ -89,25 +73,21 @@
} TC[] = {
#ifdef __ia64__
/* Check for ENOMEM passing memory that cannot be accessed. */
- {
- &addr1, 1024, PROT_READ, ENOMEM, setup1},
+ {&addr1, 1024, PROT_READ, ENOMEM, setup1},
#else
/* Check for ENOMEM passing memory that cannot be accessed. */
- {
- &addr1, 1024, PROT_READ, ENOMEM, NULL},
+ {&addr1, 1024, PROT_READ, ENOMEM, NULL},
#endif
- /*
- * Check for EINVAL by passing a pointer which is not a
- * multiple of PAGESIZE.
- */
- {
- &addr2, 1024, PROT_READ, EINVAL, setup2},
- /*
- * Check for EACCES by trying to mark a section of memory
- * which has been mmap'ed as read-only, as PROT_WRITE
- */
- {
- &addr3, PAGESIZE, PROT_WRITE, EACCES, setup3}
+ /*
+ * Check for EINVAL by passing a pointer which is not a
+ * multiple of PAGESIZE.
+ */
+ {&addr2, 1024, PROT_READ, EINVAL, setup2},
+ /*
+ * Check for EACCES by trying to mark a section of memory
+ * which has been mmap'ed as read-only, as PROT_WRITE
+ */
+ {&addr3, PAGESIZE, PROT_WRITE, EACCES, setup3}
};
int main(int ac, char **av)
@@ -116,28 +96,21 @@
int i;
char *msg;
- 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);
- }
- setup(); /* global setup */
+ 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++) {
- /* perform test specific setup */
- if (TC[i].setupfunc != NULL) {
+ if (TC[i].setupfunc != NULL)
TC[i].setupfunc();
- }
TEST(mprotect(*(TC[i].addr), TC[i].len, TC[i].prot));
@@ -164,67 +137,43 @@
tst_exit();
}
-/*
- * setup1() - sets up conditions for the first test
- */
-void setup1()
+static void setup1(void)
{
TC[0].len = getpagesize() + 1;
}
-/*
- * setup2() - sets up conditions for the second test
- */
-void setup2()
+static void setup2(void)
{
+ addr2 = malloc(PAGESIZE);
- addr2 = (char *)malloc(PAGESIZE);
- if (addr2 == NULL) {
+ if (addr2 == NULL)
tst_brkm(TINFO, cleanup, "malloc failed");
- }
+
addr2++; /* Ensure addr2 is not page aligned */
}
-/*
- * setup3() - sets up conditions for the third test
- */
-void setup3()
+static void setup3(void)
{
fd = open("/etc/passwd", O_RDONLY);
- if (fd < 0) {
+ if (fd < 0)
tst_brkm(TBROK, cleanup, "open failed");
- }
/*
* mmap the PAGESIZE bytes as read only.
*/
addr3 = mmap(0, PAGESIZE, PROT_READ, MAP_SHARED, fd, 0);
- if (addr3 < 0) {
+ if (addr3 < 0)
tst_brkm(TBROK, cleanup, "mmap failed");
- }
}
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup()
+static void setup(void)
{
-
tst_sig(FORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing status if that option was specified.
- * print errno log if that option was specified
- */
TEST_CLEANUP;
-
}
diff --git a/testcases/kernel/syscalls/mprotect/mprotect02.c b/testcases/kernel/syscalls/mprotect/mprotect02.c
index 05f6bfe..afaa5b8 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect02.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect02.c
@@ -1,26 +1,22 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * Copyright (c) International Business Machines Corp., 2001
+ * 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 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.
*
- * 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
+ * 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
*/
/*
- * NAME
- * mprotect02.c
- *
* DESCRIPTION
* Testcase to check the mprotect(2) system call.
*
@@ -32,21 +28,9 @@
* Again try to write into the mapped region.
* Verify that no SIGSEGV is generated.
*
- * USAGE: <for command-line>
- * mprotect02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -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
* 05/2002 changed over to use tst_sig instead of sigaction
- *
- * RESTRICTIONS
- * None
*/
#include <sys/mman.h>
@@ -66,11 +50,11 @@
char *TCID = "mprotect02";
int TST_TOTAL = 1;
-int fd, status;
-char file1[BUFSIZ];
+static int fd, status;
+static char file1[BUFSIZ];
-char *addr = MAP_FAILED;
-char buf[] = "abcdefghijklmnopqrstuvwxyz";
+static char *addr = MAP_FAILED;
+static char buf[] = "abcdefghijklmnopqrstuvwxyz";
int main(int ac, char **av)
{
@@ -113,7 +97,7 @@
tst_brkm(TBROK | TERRNO, cleanup, "fork #1 failed");
if (pid == 0) {
- (void)memcpy(addr, buf, strlen(buf));
+ memcpy(addr, buf, strlen(buf));
exit(255);
}
@@ -147,7 +131,7 @@
"fork #2 failed");
if (pid == 0) {
- (void)memcpy(addr, buf, strlen(buf));
+ memcpy(addr, buf, strlen(buf));
exit(0);
}
@@ -188,7 +172,7 @@
_exit((sig == SIGSEGV) ? 0 : sig);
}
-static void setup()
+static void setup(void)
{
tst_sig(FORK, sighandler, cleanup);
@@ -199,7 +183,7 @@
sprintf(file1, "mprotect02.tmp.%d", getpid());
}
-static void cleanup()
+static void cleanup(void)
{
TEST_CLEANUP;
diff --git a/testcases/kernel/syscalls/mprotect/mprotect03.c b/testcases/kernel/syscalls/mprotect/mprotect03.c
index 524cfe7..49212f3 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect03.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect03.c
@@ -1,20 +1,19 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * Copyright (c) International Business Machines Corp., 2001
+ * 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 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.
*
- * 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
+ * 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
*/
/*
@@ -34,27 +33,15 @@
* succeeds only when this sigsegv is generated while attempting to
* memcpy() on a shared region with only read permission.
*
- * USAGE: <for command-line>
- * mprotect03 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -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
* 05/2002 changed over to use tst_sig instead of sigaction
- *
- * RESTRICTIONS
- * None
*/
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
-#include <limits.h> /* for PAGESIZE */
+#include <limits.h>
#include <signal.h>
#include <wait.h>
#include "test.h"
@@ -65,8 +52,8 @@
#endif
#define FAILED 1
-void cleanup(void);
-void setup(void);
+static void cleanup(void);
+static void setup(void);
char *TCID = "mprotect03";
int TST_TOTAL = 1;
@@ -82,32 +69,26 @@
int fd, pid;
char *buf = "abcdefghijklmnopqrstuvwxyz";
- 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);
- }
- setup(); /* global setup */
+ setup();
- /* 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;
- if ((fd = open(file1, O_RDWR | O_CREAT, 0777)) < 0) { //mode must be specified when O_CREAT is in the flag
+ if ((fd = open(file1, O_RDWR | O_CREAT, 0777)) < 0)
tst_brkm(TBROK, cleanup, "open failed");
- }
- (void)write(fd, buf, strlen(buf));
+ write(fd, buf, strlen(buf));
/*
* mmap the PAGESIZE bytes as read only.
*/
addr = mmap(0, strlen(buf), PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
- if (addr < 0) {
+ if (addr < 0)
tst_brkm(TBROK, cleanup, "mmap failed");
- }
/*
* Try to change the protection to WRITE.
@@ -120,16 +101,14 @@
tst_brkm(TBROK, cleanup, "fork failed");
}
- if (pid == 0) { /* child */
- (void)memcpy((void *)addr, (void *)buf,
- strlen(buf));
+ if (pid == 0) {
+ memcpy(addr, buf, strlen(buf));
tst_resm(TINFO, "memcpy() did "
"not generate SIGSEGV");
exit(1);
}
- /* parent */
- (void)waitpid(pid, &status, 0);
+ waitpid(pid, &status, 0);
if (WEXITSTATUS(status) != 0) {
tst_resm(TFAIL, "child returned "
"unexpected status");
@@ -156,12 +135,12 @@
tst_brkm(TBROK, cleanup, "unlink failed");
}
}
+
cleanup();
tst_exit();
-
}
-void sighandler(int sig)
+static void sighandler(int sig)
{
if (sig == SIGSEGV) {
tst_resm(TINFO, "received signal: SIGSEGV");
@@ -170,32 +149,20 @@
tst_brkm(TBROK, 0, "Unexpected signal %d received.", sig);
}
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup()
+static void setup(void)
{
tst_sig(FORK, sighandler, NULL);
TEST_PAUSE;
- tst_tmpdir(); /* create a temporary directory, cd to it */
+ tst_tmpdir();
sprintf(file1, "mprotect03.tmp.%d", getpid());
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing status if that option was specified.
- * print errno log if that option was specified
- */
TEST_CLEANUP;
tst_rmdir();
-
}