[LTP] [PATCH v5 5/5] mmapstress01: move sighandler to setup and remove sig blocks
Edward Liaw
edliaw@google.com
Wed Oct 12 16:48:23 CEST 2022
Signed-off-by: Edward Liaw <edliaw@google.com>
---
.../kernel/mem/mmapstress/mmapstress01.c | 51 +++++--------------
1 file changed, 12 insertions(+), 39 deletions(-)
diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
index de7da5b99..cf8fb3b1f 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress01.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
@@ -52,6 +52,7 @@
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
static unsigned int initrand(void);
+static void sighandler(int);
static char *debug;
static char *do_sync;
@@ -88,7 +89,17 @@ static struct tst_option options[] = {
static void setup(void)
{
- int pagesize = sysconf(_SC_PAGE_SIZE);
+ struct sigaction sa;
+
+ sa.sa_handler = sighandler;
+ sa.sa_flags = 0;
+ SAFE_SIGEMPTYSET(&sa.sa_mask);
+ SAFE_SIGACTION(SIGINT, &sa, 0);
+ SAFE_SIGACTION(SIGQUIT, &sa, 0);
+ SAFE_SIGACTION(SIGTERM, &sa, 0);
+ SAFE_SIGACTION(SIGALRM, &sa, 0);
+
+ pagesize = sysconf(_SC_PAGE_SIZE);
if (tst_parse_filesize(opt_filesize, &filesize, 0, FSIZE_MAX))
tst_brk(TBROK, "invalid initial filesize '%s'", opt_filesize);
@@ -273,9 +284,7 @@ static void run(void)
int wait_stat;
off_t bytes_left;
pid_t pid;
- sigset_t set_mask;
size_t write_cnt;
- struct sigaction sa;
unsigned char data;
unsigned char *buf;
unsigned int seed;
@@ -284,19 +293,7 @@ static void run(void)
seed = initrand();
pattern = seed & 0xff;
- /*
- * Plan for death by signal or alarm.
- * Also catch and cleanup with SIGINT.
- */
finished = 0;
- sa.sa_handler = sighandler;
- sa.sa_flags = 0;
- SAFE_SIGEMPTYSET(&sa.sa_mask);
- SAFE_SIGACTION(SIGINT, &sa, 0);
- SAFE_SIGACTION(SIGQUIT, &sa, 0);
- SAFE_SIGACTION(SIGTERM, &sa, 0);
-
- SAFE_SIGACTION(SIGALRM, &sa, 0);
alarm(tst_remaining_runtime());
fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664);
@@ -326,23 +323,9 @@ static void run(void)
}
/* Now wait for children and refork them as needed. */
-
- SAFE_SIGEMPTYSET(&set_mask);
- SAFE_SIGADDSET(&set_mask, SIGALRM);
- SAFE_SIGADDSET(&set_mask, SIGINT);
while (!finished) {
pid = wait(&wait_stat);
- /*
- * Block signals while processing child exit.
- */
-
- SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL);
-
if (pid != -1) {
- /*
- * Check exit status, then refork with the
- * appropriate procno.
- */
if (!WIFEXITED(wait_stat)
|| WEXITSTATUS(wait_stat) != 0)
tst_brk(TBROK, "child exit with err <x%x>",
@@ -353,21 +336,11 @@ static void run(void)
exit(0);
}
} else {
- /*
- * wait returned an error. If EINTR, then
- * normal finish, else it's an unexpected
- * error...
- */
if (errno != EINTR || !finished)
tst_brk(TBROK | TERRNO,
"unexpected wait error");
}
- SAFE_SIGPROCMASK(SIG_UNBLOCK, &set_mask, NULL);
}
-
- SAFE_SIGEMPTYSET(&set_mask);
- SAFE_SIGADDSET(&set_mask, SIGALRM);
- SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL);
alarm(0);
/* Finished! Check the file for sanity. */
--
2.38.0.rc1.362.ged0d419d3c-goog
More information about the ltp
mailing list