Skip to content

Commit

Permalink
syscalls/ipc: Check that whether if kernel supports *_STAT_ANY
Browse files Browse the repository at this point in the history
SHM_STAT_ANY,SEM_STAT_ANY and MSG_STAT_ANY are imported to linux
in v4.17, and some linux distribution such as centos7.8 has
backported this feature, so we should call *_STAT_ANY directly
to detect whether kernel supports *_STAT_ANY.

Also fix wrong TTERRNO usage.

Reviewed-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
  • Loading branch information
xuyang0410 committed Apr 1, 2021
1 parent 24c3171 commit bd29c0e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
12 changes: 11 additions & 1 deletion testcases/kernel/syscalls/ipc/msgctl/msgctl06.c
Expand Up @@ -115,7 +115,7 @@ static void verify_msgctl(unsigned int n)
msgid = msgctl(TST_RET, MSG_STAT_ANY, &buf);

if (msgid == -1) {
tst_res(TFAIL | TTERRNO, "MSG_INFO haven't returned a valid index");
tst_res(TFAIL | TERRNO, "MSG_INFO haven't returned a valid index");
} else {
tst_res(TPASS, "MSG_INFO returned valid index %li to msgid %i",
TST_RET, msgid);
Expand All @@ -138,12 +138,22 @@ static void verify_msgctl(unsigned int n)

static void setup(void)
{
struct msqid_ds temp_buf;
ltpuser = SAFE_GETPWNAM("nobody");
nobody_uid = ltpuser->pw_uid;
root_uid = 0;

msg_id = SAFE_MSGGET(IPC_PRIVATE, IPC_CREAT | MSG_RW);
SAFE_MSGSND(msg_id, "abcd", 4, 0);

TEST(msgctl(msg_id, MSG_STAT_ANY, &temp_buf));
if (TST_RET == -1) {
if (TST_ERR == EINVAL)
tst_brk(TCONF, "kernel doesn't support MSG_STAT_ANY");
else
tst_brk(TBROK | TTERRNO,
"Current environment doesn't permit MSG_STAT_ANY");
}
}

static void cleanup(void)
Expand Down
14 changes: 13 additions & 1 deletion testcases/kernel/syscalls/ipc/semctl/semctl09.c
Expand Up @@ -158,7 +158,7 @@ static void verify_semctl(unsigned int n)
"specified by the caller to kernel");
return;
} else if (semid == -1) {
tst_res(TFAIL | TTERRNO, "SEM_INFO haven't returned a valid index");
tst_res(TFAIL | TERRNO, "SEM_INFO haven't returned a valid index");
} else {
tst_res(TPASS, "SEM_INFO returned valid index %li to semid %i",
TST_RET, semid);
Expand Down Expand Up @@ -193,6 +193,18 @@ static void setup(void)
#endif

sem_id = SAFE_SEMGET(IPC_PRIVATE, 2, IPC_CREAT | 0600);

TEST(do_semctl(sem_id, 0, SEM_STAT_ANY));
if (TST_RET == -1) {
if (TST_ERR == EFAULT)
tst_brk(TFAIL,
"SEM_STAT_ANY doesn't pass the buffer specified by the caller to kernel");
if (TST_ERR == EINVAL)
tst_brk(TCONF, "kernel doesn't support SEM_STAT_ANY");
else
tst_brk(TBROK | TTERRNO,
"Current environment doesn't permit SEM_STAT_ANY");
}
}

static void cleanup(void)
Expand Down
10 changes: 10 additions & 0 deletions testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
Expand Up @@ -155,10 +155,20 @@ 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");
}
}

static void cleanup(void)
Expand Down

0 comments on commit bd29c0e

Please sign in to comment.