[LTP] [PATCH 2/2] openposix: mq_close/2-1: Initialize sigev_signo and check for EBUSY

Avinesh Kumar avinesh.kumar@suse.com
Sun Oct 18 18:01:15 CEST 2026


From: Avinesh Kumar <avinesh.kumar@suse.com>

The first mq_notify() call in the child is expected to fail with EBUSY,
because the parent still has a notification registered on the queue.
But sigev_signo is never set for this call, so the kernel gets whatever
is left on the stack. That is often 0, depending on compiler flags
and stack layout.

This used to be harmless, since do_mq_notify() accepted signo 0 and the
call reached the EBUSY check. Since Linux commit 1184f5e82009 ("mqueue:
reject mq_notify with signo 0"), merged in v7.3-rc1, it fails with
EINVAL before the queue state is checked. The test only checks that the
call failed, not why, so it still passes without exercising the EBUSY
case. Trace on v7.3+ with the previous patch (which fixed the child's
second mq_notify() call) applied:

  # strace -f -e trace=mq_notify ./mq_close_2-1.run-test
  strace: Process 32289 attached
  [pid 32288] mq_notify(4, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  [pid 32289] mq_notify(3, {sigev_signo=0, sigev_notify=SIGEV_SIGNAL}) = -1 EINVAL (Invalid argument)
  [pid 32289] mq_notify(3, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  Test PASSED
  [pid 32289] +++ exited with 0 +++

Set sigev_signo to SIGUSR1 and verify the call fails with EBUSY, so an
unexpected errno is reported as failure instead of passing silently:

  # strace -f -e trace=mq_notify ./mq_close_2-1.run-test
  strace: Process 32535 attached
  [pid 32534] mq_notify(4, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  [pid 32535] mq_notify(3, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = -1 EBUSY (Device or resource busy)
  [pid 32535] mq_notify(3, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  Test PASSED
  [pid 32535] +++ exited with 0 +++

Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com>
---
 .../conformance/interfaces/mq_close/2-1.c                 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_close/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_close/2-1.c
index 971278aee730..48f80a1ee430 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_close/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_close/2-1.c
@@ -175,12 +175,18 @@ static int child_process(char *qname, int read_pipe, int write_pipe)
 	if (queue == (mqd_t) - 1) {
 		return PTS_UNRESOLVED;
 	}
-	// try notify while parent still has queue open - should fail
+	// try notify while parent still has queue open - should fail with EBUSY
 	se.sigev_notify = SIGEV_SIGNAL;
+	se.sigev_signo = SIGUSR1;
 	if (!mq_notify(queue, &se)) {
 		puts(ERROR_PREFIX "mq_notify (2): " "should have failed");
 		return PTS_UNRESOLVED;
 	}
+	if (errno != EBUSY) {
+		perror(ERROR_PREFIX "mq_notify (2): expected EBUSY");
+		return PTS_UNRESOLVED;
+	}
+
 	// send 'b' - signal parent to close queue
 	rval = send_receive(read_pipe, write_pipe, 'b', &reply);
 	if (rval) {
-- 
2.56.0



More information about the ltp mailing list