Skip to content

Commit 8a2dca1

Browse files
metan-ucwpevik
authored andcommitted
syscalls/msgstress01: Fix the stop logic
The stop flag didn't really work because: - if queue is full msgsnd() will block in the kernel - if queue is empty msgrcv() will block in the kernel And if the other process from the reader-writer pair exits the queue will be never changed and the test will get stuck and killed by watchdog timer. What we need to do is to use IPC_NOWAIT, retry manually (after short usleep) and handle errors manually as well. In that case no processes will sleep in kernel and setting the stop flag will actually stop the test. Link: https://lore.kernel.org/ltp/[email protected]/ Acked-by: Andrea Cervesato <[email protected]> Reviewed-by: Martin Doucha <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent f888bc2 commit 8a2dca1

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

testcases/kernel/syscalls/ipc/msgstress/msgstress01.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,18 @@ static void writer(const int id, const int pos)
101101
struct sysv_data *buff = &ipc_data[pos];
102102
int iter = num_iterations;
103103

104-
while (--iter >= 0 && !(*stop))
105-
SAFE_MSGSND(id, &buff->msg, 100, 0);
104+
while (--iter >= 0 && !(*stop)) {
105+
int size = msgsnd(id, &buff->msg, 100, IPC_NOWAIT);
106+
107+
if (size < 0) {
108+
if (errno == EAGAIN) {
109+
usleep(10);
110+
continue;
111+
}
112+
113+
tst_brk(TBROK | TERRNO, "msgsnd() failed");
114+
}
115+
}
106116
}
107117

108118
static void reader(const int id, const int pos)
@@ -115,7 +125,15 @@ static void reader(const int id, const int pos)
115125
while (--iter >= 0 && !(*stop)) {
116126
memset(&msg_recv, 0, sizeof(struct sysv_msg));
117127

118-
size = SAFE_MSGRCV(id, &msg_recv, 100, MSGTYPE, 0);
128+
size = msgrcv(id, &msg_recv, 100, MSGTYPE, IPC_NOWAIT);
129+
if (size < 0) {
130+
if (errno == ENOMSG) {
131+
usleep(10);
132+
continue;
133+
}
134+
135+
tst_brk(TBROK | TERRNO, "msgrcv() failed");
136+
}
119137

120138
if (msg_recv.type != buff->msg.type) {
121139
tst_res(TFAIL, "Received the wrong message type");
@@ -152,6 +170,7 @@ static void remove_queues(void)
152170
{
153171
for (int pos = 0; pos < num_messages; pos++) {
154172
struct sysv_data *buff = &ipc_data[pos];
173+
155174
if (buff->id != -1)
156175
SAFE_MSGCTL(buff->id, IPC_RMID, NULL);
157176
}

0 commit comments

Comments
 (0)