Skip to contentSkip to conversation

syscalls/shmctl04: Add kernel version requestions

PATCH New Zhao Gongyi 2 participants 2 messages Mar 29, 2021 – Mar 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/shmctl04: Add kernel version requestions

SHM_STAT_ANY is imported to linux in v4.17.

---
 testcases/kernel/syscalls/ipc/shmctl/shmctl04.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/syscalls/ipc/shmctl/shmctl04.c +1 -0
index 9e8ec4199..18ac8ba0a 100644
@@ -168,6 +168,7 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
+	.min_kver = "4.17",
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = verify_shminfo,

--
2.17.1

#1 lore raw

PATCH 1/1 syscalls/shmctl04: Add kernel version requestions

Hi Gongyi

Quoted 12 lines

SHM_STAT_ANY is imported to linux in v4.17.

---
  testcases/kernel/syscalls/ipc/shmctl/shmctl04.c | 1 +
  1 file changed, 1 insertion(+)
testcases/kernel/syscalls/ipc/shmctl/shmctl04.c +0 -0
index 9e8ec4199..18ac8ba0a 100644

testcases/kernel/syscalls/ipc/shmctl/shmctl04.c static void cleanup(void) · line 171

Quoted 4 lines
testcases/kernel/syscalls/ipc/shmctl/shmctl04.c +1 -0
@@ -168,6 +168,7 @@ static void cleanup(void)
  }
 
  static struct tst_test test = {
+	.min_kver = "4.17",

Some linux distribution such as centos7.8 has backported this feature, so we should call SHM_STAT_ANY directly to detect whether kernel supports SHM_STAT_ANY instead of using min_kver.

code as below:

testcases/kernel/syscalls/ipc/shmctl/shmctl04.c +5 -0
@@ -155,10 +155,19 @@ static void verify_shminfo(unsigned int n)
  static void setup(void)
  {
         struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
+       struct shmid_ds temp_ds;
         nobody_uid = ltpuser->pw_uid;
         root_uid = 0;
 
         shm_id = SAFE_SHMGET(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | SHM_RW);
+       TEST(shmctl(shm_id, SHM_STAT_ANY, &temp_ds));
+       if (TST_RET == -1) {
+               if (TST_ERR == EINVAL)
+                       tst_brk(TCONF, "kernel doesn't support 

SHM_STAT_ANY");
+ else
+ tst_brk(TBROK | TTERRNO,
+ "Current environment doesn't permit
SHM_STAT_ANY");
+ }
}

Also, On your environment, does semctl09.c/msgctl06.c have the same problem?

Quoted 7 lines
testcases/kernel/syscalls/ipc/shmctl/shmctl04.c +0 -1
  	.setup = setup,
  	.cleanup = cleanup,
  	.test = verify_shminfo,
--

2.17.1