All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] mq_unlink01: fix EEXIST failure when run in parallel
@ 2026-04-13 18:07 Soma Das
  2026-04-13 18:05 ` [LTP] " linuxtestproject.agent
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Soma Das @ 2026-04-13 18:07 UTC (permalink / raw)
  To: ltp; +Cc: somadas1

When executed with -w N, all workers share the hardcoded
"/test_mqueue" queue name. The second worker to reach
SAFE_MQ_OPEN(O_CREAT|O_EXCL) finds the queue already exists
and aborts with TBROK: EEXIST.

Fix by generating a per-process queue name using getpid(),
matching the approach used in mq_timedreceive01.

Signed-off-by: Soma Das <somadas1@linux.ibm.com>
---
 testcases/kernel/syscalls/mq_unlink/mq_unlink01.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/mq_unlink/mq_unlink01.c b/testcases/kernel/syscalls/mq_unlink/mq_unlink01.c
index baca57948..1cfffb083 100644
--- a/testcases/kernel/syscalls/mq_unlink/mq_unlink01.c
+++ b/testcases/kernel/syscalls/mq_unlink/mq_unlink01.c
@@ -14,10 +14,9 @@
 #include "tst_test.h"
 #include "tst_safe_posix_ipc.h"
 
-#define QUEUE_NAME	"/test_mqueue"
-
 static uid_t euid;
 static struct passwd *pw;
+static char queue_name[64];
 
 struct test_case {
 	int as_nobody;
@@ -28,13 +27,11 @@ struct test_case {
 
 static struct test_case tcase[] = {
 	{
-		.qname = QUEUE_NAME,
 		.ret = 0,
 		.err = 0,
 	},
 	{
 		.as_nobody = 1,
-		.qname = QUEUE_NAME,
 		.ret = -1,
 		.err = EACCES,
 	},
@@ -64,6 +61,9 @@ static struct test_case tcase[] = {
 
 void setup(void)
 {
+	snprintf(queue_name, sizeof(queue_name), "/test_mqueue_%d", getpid());
+	tcase[0].qname = queue_name;
+	tcase[1].qname = queue_name;
 	euid = geteuid();
 	pw = SAFE_GETPWNAM("nobody");
 }
@@ -79,10 +79,10 @@ static void do_test(unsigned int i)
 	 * When test ended with SIGTERM etc, mq descriptor is left remains.
 	 * So we delete it first.
 	 */
-	mq_unlink(QUEUE_NAME);
+	mq_unlink(queue_name);
 
 	/* prepare */
-	fd = SAFE_MQ_OPEN(QUEUE_NAME, O_CREAT | O_EXCL | O_RDWR, S_IRWXU, NULL);
+	fd = SAFE_MQ_OPEN(queue_name, O_CREAT | O_EXCL | O_RDWR, S_IRWXU, NULL);
 
 	if (tc->as_nobody && seteuid(pw->pw_uid)) {
 		tst_res(TFAIL | TERRNO, "seteuid failed");
@@ -107,7 +107,7 @@ EXIT:
 	if (fd > 0 && close(fd))
 		tst_res(TWARN | TERRNO, "close(fd) failed");
 
-	mq_unlink(QUEUE_NAME);
+	mq_unlink(queue_name);
 }
 
 static struct tst_test test = {
-- 
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-04-29 14:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-13 18:07 [LTP] [PATCH] mq_unlink01: fix EEXIST failure when run in parallel Soma Das
2026-04-13 18:05 ` [LTP] " linuxtestproject.agent
2026-04-13 19:07 ` [LTP] [PATCH] " Soma Das
2026-04-29 14:41 ` Andrea Cervesato via ltp
2026-04-29 14:42 ` Andrea Cervesato via ltp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.