Skip to contentSkip to conversation

syscalls/shmctl04: Add kernel version requestions

PATCH New zhaogongyi 2 participants 2 messages Mar 30, 2021

lore
Share & tools
lore

zhaogongyi

author
#0 lore raw

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

Hi Xu,

It looks good to me.

On the other hand, msgctl06.c, semctl09.c have the same problem for MSG_STAT_ANY and SEM_STAT_ANY, we can also fix them similarly?

Thanks!

Best Regards,
Gongyi

Quoted 59 lines

Hi Gongyi

Quoted 13 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 +9 -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

#1 lore raw

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

Hi Gongyi

Quoted 5 lines

Hi Xu,

It looks good to me.

On the other hand, msgctl06.c, semctl09.c have the same problem for MSG_STAT_ANY and SEM_STAT_ANY, we can also fix them similarly?

Yes. We can fix them similarly.

Quoted 65 lines

Thanks!

Best Regards,
Gongyi

Quoted 59 lines

Hi Gongyi

Quoted 13 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 +9 -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