rteval-loads/SOURCES/0006-stress-shm-sysv-exercise-shmctl-and-shmdt-race-on-ch.patch
2022-02-03 05:25:55 +00:00

105 lines
2.4 KiB
Diff

From ceb4a4712eb09892af949494a95ffc4d15f04272 Mon Sep 17 00:00:00 2001
From: Colin Ian King <colin.king@canonical.com>
Date: Mon, 18 May 2020 10:17:17 +0100
Subject: [PATCH 06/28] stress-shm-sysv: exercise shmctl and shmdt race on
child exit
Add a little more shm-sysv kernel coverage by performing shm
actions with a child process that has inherited shm from parent.
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
stress-shm-sysv.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/stress-shm-sysv.c b/stress-shm-sysv.c
index 7703e58cad7a..26d47ccdd4d7 100644
--- a/stress-shm-sysv.c
+++ b/stress-shm-sysv.c
@@ -200,6 +200,7 @@ static int stress_shm_sysv_child(
do {
size_t sz = max_sz;
+ pid_t pid = -1;
for (i = 0; i < shm_sysv_segments; i++) {
int shm_id, count = 0;
@@ -325,7 +326,7 @@ static int stress_shm_sysv_child(
}
}
#endif
-#if defined(IPC_STAT) && \
+#if defined(IPC_STAT) && \
defined(HAVE_SHMID_DS)
{
struct shmid_ds ds;
@@ -343,7 +344,7 @@ static int stress_shm_sysv_child(
#endif
}
#endif
-#if defined(IPC_INFO) && \
+#if defined(IPC_INFO) && \
defined(HAVE_SHMINFO)
{
struct shminfo s;
@@ -353,7 +354,7 @@ static int stress_shm_sysv_child(
args->name, errno, strerror(errno));
}
#endif
-#if defined(SHM_INFO) && \
+#if defined(SHM_INFO) && \
defined(HAVE_SHMINFO)
{
struct shm_info s;
@@ -363,7 +364,7 @@ static int stress_shm_sysv_child(
args->name, errno, strerror(errno));
}
#endif
-#if defined(SHM_LOCK) && \
+#if defined(SHM_LOCK) && \
defined(SHM_UNLOCK)
if (shmctl(shm_id, SHM_LOCK, (struct shmid_ds *)NULL) < 0) {
int ret;
@@ -394,6 +395,25 @@ static int stress_shm_sysv_child(
inc_counter(args);
}
+
+ pid = fork();
+ if (pid == 0) {
+ for (i = 0; i < shm_sysv_segments; i++) {
+ int ret;
+#if defined(IPC_STAT) && \
+ defined(HAVE_SHMID_DS)
+
+ if (shm_ids[i] >= 0) {
+ struct shmid_ds ds;
+ ret = shmctl(shm_ids[i], IPC_STAT, &ds);
+ (void)ret;
+ }
+#endif
+ ret = shmdt(addrs[i]);
+ (void)ret;
+ }
+ _exit(EXIT_SUCCESS);
+ }
reap:
for (i = 0; i < shm_sysv_segments; i++) {
if (addrs[i]) {
@@ -422,6 +442,12 @@ reap:
shm_ids[i] = -1;
keys[i] = 0;
}
+
+ if (pid >= 0) {
+ int status;
+
+ (void)waitpid(pid, &status, 0);
+ }
} while (ok && keep_stressing());
/* Inform parent of end of run */
--
2.21.3