2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
34 #include "tst-mqueue.h"
36 #if _POSIX_THREADS && defined SIGRTMIN && defined SA_SIGINFO
39 volatile int rtmin_cnt
;
40 volatile pid_t rtmin_pid
;
41 volatile uid_t rtmin_uid
;
42 volatile int rtmin_code
;
43 volatile union sigval rtmin_sigval
;
46 rtmin_handler (int sig
, siginfo_t
*info
, void *ctx
)
51 rtmin_pid
= info
->si_pid
;
52 rtmin_uid
= info
->si_uid
;
53 rtmin_code
= info
->si_code
;
54 rtmin_sigval
= info
->si_value
;
57 #define mqsend(q) (mqsend) (q, __LINE__)
59 (mqsend
) (mqd_t q
, int line
)
62 if (mq_send (q
, &c
, 1, 1) != 0)
64 printf ("mq_send on line %d failed with: %m\n", line
);
70 #define mqrecv(q) (mqrecv) (q, __LINE__)
72 (mqrecv
) (mqd_t q
, int line
)
75 ssize_t rets
= TEMP_FAILURE_RETRY (mq_receive (q
, &c
, 1, NULL
));
79 printf ("mq_receive on line %d failed with: %m\n", line
);
81 printf ("mq_receive on line %d returned %zd != 1\n",
91 pthread_barrier_t
*b3
;
98 pthread_barrier_t
*b3
= ((struct thr_data
*)arg
)->b3
;
99 mqd_t q
= ((struct thr_data
*)arg
)->q
;
100 const char *name
= ((struct thr_data
*)arg
)->name
;
103 result
|= mqrecv (q
);
105 (void) pthread_barrier_wait (b3
);
107 /* Child verifies SIGRTMIN has not been sent. */
109 (void) pthread_barrier_wait (b3
);
111 /* Parent calls mqsend (q), which should trigger notification. */
113 (void) pthread_barrier_wait (b3
);
117 puts ("SIGRTMIN signal in thread did not arrive");
120 else if (rtmin_pid
!= getppid ()
121 || rtmin_uid
!= getuid ()
122 || rtmin_code
!= SI_MESGQ
123 || rtmin_sigval
.sival_int
!= 0xdeadbeef)
125 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (%d)\n",
126 rtmin_pid
, getppid (), rtmin_uid
, getuid (),
127 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
, 0xdeadbeef);
132 memset (&ev
, 0x82, sizeof (ev
));
133 ev
.sigev_notify
= SIGEV_NONE
;
134 if (mq_notify (q
, &ev
) != 0)
136 printf ("mq_notify in thread (q, { SIGEV_NONE }) failed with: %m\n");
140 if (mq_notify (q
, NULL
) != 0)
142 printf ("mq_notify in thread (q, NULL) failed with: %m\n");
146 result
|= mqrecv (q
);
148 (void) pthread_barrier_wait (b3
);
150 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
152 (void) pthread_barrier_wait (b3
);
154 if (mq_notify (q
, NULL
) != 0)
156 printf ("second mq_notify in thread (q, NULL) failed with: %m\n");
160 (void) pthread_barrier_wait (b3
);
162 /* Parent calls mqsend (q), which should not trigger notification. */
164 (void) pthread_barrier_wait (b3
);
166 /* Child verifies SIGRTMIN has not been received. */
167 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
169 (void) pthread_barrier_wait (b3
);
171 mqd_t q4
= mq_open (name
, O_RDONLY
);
172 if (q4
== (mqd_t
) -1)
174 printf ("mq_open in thread failed with: %m\n");
178 if (mq_notify (q4
, NULL
) != 0)
180 printf ("mq_notify in thread (q4, NULL) failed with: %m\n");
184 if (mq_close (q4
) != 0)
186 printf ("mq_close in thread failed with: %m\n");
190 (void) pthread_barrier_wait (b3
);
192 /* Parent calls mqsend (q), which should not trigger notification. */
194 (void) pthread_barrier_wait (b3
);
196 /* Child verifies SIGRTMIN has not been received. */
197 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
199 (void) pthread_barrier_wait (b3
);
201 mqd_t q5
= mq_open (name
, O_WRONLY
);
202 if (q5
== (mqd_t
) -1)
204 printf ("mq_open O_WRONLY in thread failed with: %m\n");
208 if (mq_notify (q5
, NULL
) != 0)
210 printf ("mq_notify in thread (q5, NULL) failed with: %m\n");
214 if (mq_close (q5
) != 0)
216 printf ("mq_close in thread failed with: %m\n");
220 (void) pthread_barrier_wait (b3
);
222 /* Parent calls mqsend (q), which should not trigger notification. */
224 (void) pthread_barrier_wait (b3
);
226 /* Child verifies SIGRTMIN has not been received. */
228 return (void *) (long) result
;
232 do_child (const char *name
, pthread_barrier_t
*b2
, pthread_barrier_t
*b3
,
238 memset (&ev
, 0x55, sizeof (ev
));
239 ev
.sigev_notify
= SIGEV_SIGNAL
;
240 ev
.sigev_signo
= SIGRTMIN
;
241 ev
.sigev_value
.sival_ptr
= &ev
;
242 if (mq_notify (q
, &ev
) == 0)
244 puts ("first mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
247 else if (errno
!= EBUSY
)
249 printf ("first mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
253 (void) pthread_barrier_wait (b2
);
255 /* Parent calls mqsend (q), which makes notification available. */
257 (void) pthread_barrier_wait (b2
);
261 if (mq_notify (q
, &ev
) != 0)
263 printf ("second mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
269 puts ("SIGRTMIN signal in child caught too early");
273 (void) pthread_barrier_wait (b2
);
275 /* Parent unsuccessfully attempts to mq_notify. */
276 /* Parent calls mqsend (q), which makes notification available
277 and triggers a signal in the child. */
278 /* Parent successfully calls mq_notify SIGEV_SIGNAL. */
280 (void) pthread_barrier_wait (b2
);
284 puts ("SIGRTMIN signal in child did not arrive");
287 else if (rtmin_pid
!= getppid ()
288 || rtmin_uid
!= getuid ()
289 || rtmin_code
!= SI_MESGQ
290 || rtmin_sigval
.sival_ptr
!= &ev
)
292 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_ptr %p (%p)\n",
293 rtmin_pid
, getppid (), rtmin_uid
, getuid (),
294 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_ptr
, &ev
);
298 result
|= mqsend (q
);
300 (void) pthread_barrier_wait (b2
);
302 /* Parent verifies caught SIGRTMIN. */
304 mqd_t q2
= mq_open (name
, O_RDWR
);
305 if (q2
== (mqd_t
) -1)
307 printf ("mq_open in child failed with: %m\n");
311 (void) pthread_barrier_wait (b2
);
313 /* Parent mq_open's another mqd_t for the same queue (q3). */
315 memset (&ev
, 0x11, sizeof (ev
));
316 ev
.sigev_notify
= SIGEV_SIGNAL
;
317 ev
.sigev_signo
= SIGRTMIN
;
318 ev
.sigev_value
.sival_ptr
= &ev
;
319 if (mq_notify (q2
, &ev
) != 0)
321 printf ("mq_notify in child (q2, { SIGEV_SIGNAL }) failed with: %m\n");
325 (void) pthread_barrier_wait (b2
);
327 /* Parent unsuccessfully attempts to mq_notify { SIGEV_NONE } on q. */
329 (void) pthread_barrier_wait (b2
);
331 if (mq_close (q2
) != 0)
333 printf ("mq_close failed: %m\n");
337 (void) pthread_barrier_wait (b2
);
339 /* Parent successfully calls mq_notify { SIGEV_NONE } on q3. */
341 (void) pthread_barrier_wait (b2
);
343 memset (&ev
, 0xbb, sizeof (ev
));
344 ev
.sigev_notify
= SIGEV_SIGNAL
;
345 ev
.sigev_signo
= SIGRTMIN
;
346 ev
.sigev_value
.sival_ptr
= &b2
;
347 if (mq_notify (q
, &ev
) == 0)
349 puts ("third mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
352 else if (errno
!= EBUSY
)
354 printf ("third mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
358 (void) pthread_barrier_wait (b2
);
360 /* Parent calls mq_close on q3, which makes the queue available again for
363 (void) pthread_barrier_wait (b2
);
365 memset (&ev
, 0x13, sizeof (ev
));
366 ev
.sigev_notify
= SIGEV_NONE
;
367 if (mq_notify (q
, &ev
) != 0)
369 printf ("mq_notify in child (q, { SIGEV_NONE }) failed with: %m\n");
373 if (mq_notify (q
, NULL
) != 0)
375 printf ("mq_notify in child (q, NULL) failed with: %m\n");
379 (void) pthread_barrier_wait (b2
);
381 struct thr_data thr_data
= { .name
= name
, .b3
= b3
, .q
= q
};
383 int ret
= pthread_create (&th
, NULL
, thr
, &thr_data
);
387 printf ("pthread_created failed with: %m\n");
391 /* Wait till thr calls mq_receive on the empty queue q and blocks on it. */
394 memset (&ev
, 0x5f, sizeof (ev
));
395 ev
.sigev_notify
= SIGEV_SIGNAL
;
396 ev
.sigev_signo
= SIGRTMIN
;
397 ev
.sigev_value
.sival_int
= 0xdeadbeef;
398 if (mq_notify (q
, &ev
) != 0)
400 printf ("fourth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
404 /* Ensure the thr thread gets the signal, not us. */
407 sigaddset (&set
, SIGRTMIN
);
408 if (pthread_sigmask (SIG_BLOCK
, &set
, NULL
))
410 printf ("Failed to block SIGRTMIN in child: %m\n");
414 (void) pthread_barrier_wait (b2
);
416 /* Parent calls mqsend (q), which should wake up mqrecv (q)
417 in the thread but no notification should be sent. */
419 (void) pthread_barrier_wait (b3
);
423 puts ("SIGRTMIN signal caught while thr was blocked on mq_receive");
427 (void) pthread_barrier_wait (b3
);
429 /* Parent calls mqsend (q), which should trigger notification. */
431 (void) pthread_barrier_wait (b3
);
433 /* Thread verifies SIGRTMIN has been received. */
434 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
435 available for registration. */
436 /* Thread calls mq_notify (q, NULL). */
438 (void) pthread_barrier_wait (b3
);
440 memset (&ev
, 0x6a, sizeof (ev
));
441 ev
.sigev_notify
= SIGEV_SIGNAL
;
442 ev
.sigev_signo
= SIGRTMIN
;
443 ev
.sigev_value
.sival_ptr
= do_child
;
444 if (mq_notify (q
, &ev
) != 0)
446 printf ("fifth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
450 (void) pthread_barrier_wait (b3
);
452 /* Thread calls mq_notify (q, NULL), which should unregister the above
455 (void) pthread_barrier_wait (b3
);
457 /* Parent calls mqsend (q), which should not trigger notification. */
459 (void) pthread_barrier_wait (b3
);
463 puts ("SIGRTMIN signal caught while notification has been disabled");
467 memset (&ev
, 0x7b, sizeof (ev
));
468 ev
.sigev_notify
= SIGEV_SIGNAL
;
469 ev
.sigev_signo
= SIGRTMIN
;
470 ev
.sigev_value
.sival_ptr
= thr
;
471 if (mq_notify (q
, &ev
) != 0)
473 printf ("sixth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
477 (void) pthread_barrier_wait (b3
);
479 /* Thread opens a new O_RDONLY mqd_t (q4). */
480 /* Thread calls mq_notify (q4, NULL), which should unregister the above
482 /* Thread calls mq_close (q4). */
484 (void) pthread_barrier_wait (b3
);
486 /* Parent calls mqsend (q), which should not trigger notification. */
488 (void) pthread_barrier_wait (b3
);
492 puts ("SIGRTMIN signal caught while notification has been disabled");
496 memset (&ev
, 0xe1, sizeof (ev
));
497 ev
.sigev_notify
= SIGEV_SIGNAL
;
498 ev
.sigev_signo
= SIGRTMIN
;
499 ev
.sigev_value
.sival_int
= 127;
500 if (mq_notify (q
, &ev
) != 0)
502 printf ("seventh mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
506 (void) pthread_barrier_wait (b3
);
508 /* Thread opens a new O_WRONLY mqd_t (q5). */
509 /* Thread calls mq_notify (q5, NULL), which should unregister the above
511 /* Thread calls mq_close (q5). */
513 (void) pthread_barrier_wait (b3
);
515 /* Parent calls mqsend (q), which should not trigger notification. */
517 (void) pthread_barrier_wait (b3
);
521 puts ("SIGRTMIN signal caught while notification has been disabled");
525 /* Reenable test signals before cleaning up the thread. */
526 if (pthread_sigmask (SIG_UNBLOCK
, &set
, NULL
))
528 printf ("Failed to unblock SIGRTMIN in child: %m\n");
533 ret
= pthread_join (th
, &thr_ret
);
537 printf ("pthread_join failed: %m\n");
543 if (mq_close (q
) != 0)
545 printf ("mq_close failed: %m\n");
552 #define TEST_FUNCTION do_test ()
558 char tmpfname
[] = "/tmp/tst-mqueue5-barrier.XXXXXX";
559 int fd
= mkstemp (tmpfname
);
562 printf ("cannot open temporary file: %m\n");
566 /* Make sure it is always removed. */
569 /* Create one page of data. */
570 size_t ps
= sysconf (_SC_PAGESIZE
);
572 memset (data
, '\0', ps
);
574 /* Write the data to the file. */
575 if (write (fd
, data
, ps
) != (ssize_t
) ps
)
577 puts ("short write");
581 void *mem
= mmap (NULL
, ps
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
582 if (mem
== MAP_FAILED
)
584 printf ("mmap failed: %m\n");
588 pthread_barrier_t
*b2
;
589 b2
= (pthread_barrier_t
*) (((uintptr_t) mem
+ __alignof (pthread_barrier_t
))
590 & ~(__alignof (pthread_barrier_t
) - 1));
592 pthread_barrier_t
*b3
;
595 pthread_barrierattr_t a
;
596 if (pthread_barrierattr_init (&a
) != 0)
598 puts ("barrierattr_init failed");
602 if (pthread_barrierattr_setpshared (&a
, PTHREAD_PROCESS_SHARED
) != 0)
604 puts ("barrierattr_setpshared failed, could not test");
608 if (pthread_barrier_init (b2
, &a
, 2) != 0)
610 puts ("barrier_init failed");
614 if (pthread_barrier_init (b3
, &a
, 3) != 0)
616 puts ("barrier_init failed");
620 if (pthread_barrierattr_destroy (&a
) != 0)
622 puts ("barrierattr_destroy failed");
626 char name
[sizeof "/tst-mqueue5-" + sizeof (pid_t
) * 3];
627 snprintf (name
, sizeof (name
), "/tst-mqueue5-%u", getpid ());
629 struct mq_attr attr
= { .mq_maxmsg
= 1, .mq_msgsize
= 1 };
630 mqd_t q
= mq_open (name
, O_CREAT
| O_EXCL
| O_RDWR
, 0600, &attr
);
634 printf ("mq_open failed with: %m\n");
641 memset (&ev
, 0xaa, sizeof (ev
));
642 ev
.sigev_notify
= SIGEV_NONE
;
643 if (mq_notify (q
, &ev
) != 0)
645 printf ("mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
649 if (mq_notify (q
, &ev
) == 0)
651 puts ("second mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
654 else if (errno
!= EBUSY
)
656 printf ("second mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
660 result
|= mqsend (q
);
662 if (mq_notify (q
, &ev
) != 0)
664 printf ("third mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
668 result
|= mqrecv (q
);
670 if (mq_notify (q
, NULL
) != 0)
672 printf ("mq_notify (q, NULL) failed with: %m\n");
676 if (mq_notify (q
, NULL
) != 0)
678 /* Implementation-defined behaviour, so don't fail,
680 printf ("second mq_notify (q, NULL) failed with: %m\n");
683 struct sigaction sa
= { .sa_sigaction
= rtmin_handler
,
684 .sa_flags
= SA_SIGINFO
};
685 sigemptyset (&sa
.sa_mask
);
686 sigaction (SIGRTMIN
, &sa
, NULL
);
688 memset (&ev
, 0x55, sizeof (ev
));
689 ev
.sigev_notify
= SIGEV_SIGNAL
;
690 ev
.sigev_signo
= SIGRTMIN
;
691 ev
.sigev_value
.sival_int
= 26;
692 if (mq_notify (q
, &ev
) != 0)
694 printf ("mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
698 ev
.sigev_value
.sival_ptr
= &ev
;
699 if (mq_notify (q
, &ev
) == 0)
701 puts ("second mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
704 else if (errno
!= EBUSY
)
706 printf ("second mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
712 puts ("SIGRTMIN signal caught too early");
716 result
|= mqsend (q
);
720 puts ("SIGRTMIN signal did not arrive");
723 else if (rtmin_pid
!= getpid ()
724 || rtmin_uid
!= getuid ()
725 || rtmin_code
!= SI_MESGQ
726 || rtmin_sigval
.sival_int
!= 26)
728 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (26)\n",
729 rtmin_pid
, getpid (), rtmin_uid
, getuid (),
730 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
);
734 ev
.sigev_value
.sival_int
= 75;
735 if (mq_notify (q
, &ev
) != 0)
737 printf ("third mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
741 result
|= mqrecv (q
);
743 if (mq_notify (q
, NULL
) != 0)
745 printf ("mq_notify (q, NULL) failed with: %m\n");
749 memset (&ev
, 0x33, sizeof (ev
));
750 ev
.sigev_notify
= SIGEV_NONE
;
751 if (mq_notify (q
, &ev
) != 0)
753 printf ("fourth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
760 printf ("fork () failed: %m\n");
766 do_child (name
, b2
, b3
, q
);
768 /* Child unsuccessfully attempts to mq_notify. */
770 (void) pthread_barrier_wait (b2
);
772 result
|= mqsend (q
);
774 (void) pthread_barrier_wait (b2
);
776 /* Child successfully calls mq_notify SIGEV_SIGNAL now. */
778 result
|= mqrecv (q
);
780 (void) pthread_barrier_wait (b2
);
782 memset (&ev
, 0xbb, sizeof (ev
));
783 ev
.sigev_notify
= SIGEV_SIGNAL
;
784 ev
.sigev_signo
= SIGRTMIN
;
785 ev
.sigev_value
.sival_int
= 15;
786 if (mq_notify (q
, &ev
) == 0)
788 puts ("fourth mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
791 else if (errno
!= EBUSY
)
793 printf ("fourth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
797 result
|= mqsend (q
);
799 if (mq_notify (q
, &ev
) != 0)
801 printf ("fifth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
807 puts ("SIGRTMIN signal caught too early");
811 result
|= mqrecv (q
);
813 (void) pthread_barrier_wait (b2
);
815 /* Child verifies caught SIGRTMIN signal. */
816 /* Child calls mq_send (q) which triggers SIGRTMIN signal here. */
818 (void) pthread_barrier_wait (b2
);
820 /* Child mq_open's another mqd_t for the same queue (q2). */
824 puts ("SIGRTMIN signal did not arrive");
827 else if (rtmin_pid
!= pid
828 || rtmin_uid
!= getuid ()
829 || rtmin_code
!= SI_MESGQ
830 || rtmin_sigval
.sival_int
!= 15)
832 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (15)\n",
833 rtmin_pid
, pid
, rtmin_uid
, getuid (),
834 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
);
838 result
|= mqrecv (q
);
840 (void) pthread_barrier_wait (b2
);
842 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q2. */
844 (void) pthread_barrier_wait (b2
);
846 memset (&ev
, 0xbb, sizeof (ev
));
847 ev
.sigev_notify
= SIGEV_NONE
;
848 if (mq_notify (q
, &ev
) == 0)
850 puts ("fifth mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
853 else if (errno
!= EBUSY
)
855 printf ("fifth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
859 (void) pthread_barrier_wait (b2
);
861 /* Child calls mq_close on q2, which makes the queue available again for
864 mqd_t q3
= mq_open (name
, O_RDWR
);
865 if (q3
== (mqd_t
) -1)
867 printf ("mq_open q3 in parent failed with: %m\n");
871 (void) pthread_barrier_wait (b2
);
873 memset (&ev
, 0x12, sizeof (ev
));
874 ev
.sigev_notify
= SIGEV_NONE
;
875 if (mq_notify (q3
, &ev
) != 0)
877 printf ("mq_notify (q3, { SIGEV_NONE }) failed with: %m\n");
881 (void) pthread_barrier_wait (b2
);
883 /* Child unsuccessfully attempts to mq_notify { SIGEV_SIGNAL } on q. */
885 (void) pthread_barrier_wait (b2
);
887 if (mq_close (q3
) != 0)
889 printf ("mq_close failed: %m\n");
893 (void) pthread_barrier_wait (b2
);
895 /* Child successfully calls mq_notify { SIGEV_NONE } on q. */
896 /* Child successfully calls mq_notify NULL on q. */
898 (void) pthread_barrier_wait (b2
);
900 /* Child creates new thread. */
901 /* Thread blocks on mqrecv (q). */
902 /* Child sleeps for 1sec so that thread has time to reach that point. */
903 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q. */
905 (void) pthread_barrier_wait (b2
);
907 result
|= mqsend (q
);
909 (void) pthread_barrier_wait (b3
);
911 /* Child verifies SIGRTMIN has not been sent. */
913 (void) pthread_barrier_wait (b3
);
915 result
|= mqsend (q
);
917 (void) pthread_barrier_wait (b3
);
919 /* Thread verifies SIGRTMIN has been caught. */
920 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
921 available for registration. */
922 /* Thread calls mq_notify (q, NULL). */
924 (void) pthread_barrier_wait (b3
);
926 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
928 (void) pthread_barrier_wait (b3
);
930 /* Thread calls mq_notify (q, NULL). */
932 (void) pthread_barrier_wait (b3
);
934 result
|= mqsend (q
);
935 result
|= mqrecv (q
);
937 (void) pthread_barrier_wait (b3
);
939 /* Child verifies SIGRTMIN has not been sent. */
940 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
942 (void) pthread_barrier_wait (b3
);
944 /* Thread opens a new O_RDONLY mqd_t (q4). */
945 /* Thread calls mq_notify (q4, NULL). */
946 /* Thread calls mq_close (q4). */
948 (void) pthread_barrier_wait (b3
);
950 result
|= mqsend (q
);
951 result
|= mqrecv (q
);
953 (void) pthread_barrier_wait (b3
);
955 /* Child verifies SIGRTMIN has not been sent. */
956 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
958 (void) pthread_barrier_wait (b3
);
960 /* Thread opens a new O_WRONLY mqd_t (q5). */
961 /* Thread calls mq_notify (q5, NULL). */
962 /* Thread calls mq_close (q5). */
964 (void) pthread_barrier_wait (b3
);
966 result
|= mqsend (q
);
967 result
|= mqrecv (q
);
969 (void) pthread_barrier_wait (b3
);
971 /* Child verifies SIGRTMIN has not been sent. */
974 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
976 puts ("waitpid failed");
980 else if (!WIFEXITED (status
) || WEXITSTATUS (status
))
982 printf ("child failed with status %d\n", status
);
986 if (mq_unlink (name
) != 0)
988 printf ("mq_unlink failed: %m\n");
992 if (mq_close (q
) != 0)
994 printf ("mq_close failed: %m\n");
998 if (mq_notify (q
, NULL
) == 0)
1000 puts ("mq_notify on closed mqd_t unexpectedly succeeded");
1003 else if (errno
!= EBADF
)
1005 printf ("mq_notify on closed mqd_t did not fail with EBADF: %m\n");
1009 memset (&ev
, 0x55, sizeof (ev
));
1010 ev
.sigev_notify
= SIGEV_NONE
;
1011 if (mq_notify (q
, &ev
) == 0)
1013 puts ("mq_notify on closed mqd_t unexpectedly succeeded");
1016 else if (errno
!= EBADF
)
1018 printf ("mq_notify on closed mqd_t did not fail with EBADF: %m\n");
1025 # define TEST_FUNCTION 0
1028 #include "../test-skeleton.c"