2 Copyright (C) 2004-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
33 #include "tst-mqueue.h"
35 #if _POSIX_THREADS && defined SIGRTMIN && defined SA_SIGINFO
38 volatile int rtmin_cnt
;
39 volatile pid_t rtmin_pid
;
40 volatile uid_t rtmin_uid
;
41 volatile int rtmin_code
;
42 volatile union sigval rtmin_sigval
;
45 rtmin_handler (int sig
, siginfo_t
*info
, void *ctx
)
50 rtmin_pid
= info
->si_pid
;
51 rtmin_uid
= info
->si_uid
;
52 rtmin_code
= info
->si_code
;
53 rtmin_sigval
= info
->si_value
;
56 #define mqsend(q) (mqsend) (q, __LINE__)
58 (mqsend
) (mqd_t q
, int line
)
61 if (mq_send (q
, &c
, 1, 1) != 0)
63 printf ("mq_send on line %d failed with: %m\n", line
);
69 #define mqrecv(q) (mqrecv) (q, __LINE__)
71 (mqrecv
) (mqd_t q
, int line
)
74 ssize_t rets
= TEMP_FAILURE_RETRY (mq_receive (q
, &c
, 1, NULL
));
78 printf ("mq_receive on line %d failed with: %m\n", line
);
80 printf ("mq_receive on line %d returned %zd != 1\n",
90 pthread_barrier_t
*b3
;
97 pthread_barrier_t
*b3
= ((struct thr_data
*)arg
)->b3
;
98 mqd_t q
= ((struct thr_data
*)arg
)->q
;
99 const char *name
= ((struct thr_data
*)arg
)->name
;
102 result
|= mqrecv (q
);
104 (void) pthread_barrier_wait (b3
);
106 /* Child verifies SIGRTMIN has not been sent. */
108 (void) pthread_barrier_wait (b3
);
110 /* Parent calls mqsend (q), which should trigger notification. */
112 (void) pthread_barrier_wait (b3
);
116 puts ("SIGRTMIN signal in thread did not arrive");
119 else if (rtmin_pid
!= getppid ()
120 || rtmin_uid
!= getuid ()
121 || rtmin_code
!= SI_MESGQ
122 || rtmin_sigval
.sival_int
!= 0xdeadbeef)
124 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (%d)\n",
125 rtmin_pid
, getppid (), rtmin_uid
, getuid (),
126 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
, 0xdeadbeef);
131 memset (&ev
, 0x82, sizeof (ev
));
132 ev
.sigev_notify
= SIGEV_NONE
;
133 if (mq_notify (q
, &ev
) != 0)
135 printf ("mq_notify in thread (q, { SIGEV_NONE }) failed with: %m\n");
139 if (mq_notify (q
, NULL
) != 0)
141 printf ("mq_notify in thread (q, NULL) failed with: %m\n");
145 result
|= mqrecv (q
);
147 (void) pthread_barrier_wait (b3
);
149 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
151 (void) pthread_barrier_wait (b3
);
153 if (mq_notify (q
, NULL
) != 0)
155 printf ("second mq_notify in thread (q, NULL) failed with: %m\n");
159 (void) pthread_barrier_wait (b3
);
161 /* Parent calls mqsend (q), which should not trigger notification. */
163 (void) pthread_barrier_wait (b3
);
165 /* Child verifies SIGRTMIN has not been received. */
166 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
168 (void) pthread_barrier_wait (b3
);
170 mqd_t q4
= mq_open (name
, O_RDONLY
);
171 if (q4
== (mqd_t
) -1)
173 printf ("mq_open in thread failed with: %m\n");
177 if (mq_notify (q4
, NULL
) != 0)
179 printf ("mq_notify in thread (q4, NULL) failed with: %m\n");
183 if (mq_close (q4
) != 0)
185 printf ("mq_close in thread failed with: %m\n");
189 (void) pthread_barrier_wait (b3
);
191 /* Parent calls mqsend (q), which should not trigger notification. */
193 (void) pthread_barrier_wait (b3
);
195 /* Child verifies SIGRTMIN has not been received. */
196 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
198 (void) pthread_barrier_wait (b3
);
200 mqd_t q5
= mq_open (name
, O_WRONLY
);
201 if (q5
== (mqd_t
) -1)
203 printf ("mq_open O_WRONLY in thread failed with: %m\n");
207 if (mq_notify (q5
, NULL
) != 0)
209 printf ("mq_notify in thread (q5, NULL) failed with: %m\n");
213 if (mq_close (q5
) != 0)
215 printf ("mq_close in thread failed with: %m\n");
219 (void) pthread_barrier_wait (b3
);
221 /* Parent calls mqsend (q), which should not trigger notification. */
223 (void) pthread_barrier_wait (b3
);
225 /* Child verifies SIGRTMIN has not been received. */
227 return (void *) (long) result
;
231 do_child (const char *name
, pthread_barrier_t
*b2
, pthread_barrier_t
*b3
,
237 memset (&ev
, 0x55, sizeof (ev
));
238 ev
.sigev_notify
= SIGEV_SIGNAL
;
239 ev
.sigev_signo
= SIGRTMIN
;
240 ev
.sigev_value
.sival_ptr
= &ev
;
241 if (mq_notify (q
, &ev
) == 0)
243 puts ("first mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
246 else if (errno
!= EBUSY
)
248 printf ("first mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
252 (void) pthread_barrier_wait (b2
);
254 /* Parent calls mqsend (q), which makes notification available. */
256 (void) pthread_barrier_wait (b2
);
260 if (mq_notify (q
, &ev
) != 0)
262 printf ("second mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
268 puts ("SIGRTMIN signal in child caught too early");
272 (void) pthread_barrier_wait (b2
);
274 /* Parent unsuccessfully attempts to mq_notify. */
275 /* Parent calls mqsend (q), which makes notification available
276 and triggers a signal in the child. */
277 /* Parent successfully calls mq_notify SIGEV_SIGNAL. */
279 (void) pthread_barrier_wait (b2
);
283 puts ("SIGRTMIN signal in child did not arrive");
286 else if (rtmin_pid
!= getppid ()
287 || rtmin_uid
!= getuid ()
288 || rtmin_code
!= SI_MESGQ
289 || rtmin_sigval
.sival_ptr
!= &ev
)
291 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_ptr %p (%p)\n",
292 rtmin_pid
, getppid (), rtmin_uid
, getuid (),
293 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_ptr
, &ev
);
297 result
|= mqsend (q
);
299 (void) pthread_barrier_wait (b2
);
301 /* Parent verifies caught SIGRTMIN. */
303 mqd_t q2
= mq_open (name
, O_RDWR
);
304 if (q2
== (mqd_t
) -1)
306 printf ("mq_open in child failed with: %m\n");
310 (void) pthread_barrier_wait (b2
);
312 /* Parent mq_open's another mqd_t for the same queue (q3). */
314 memset (&ev
, 0x11, sizeof (ev
));
315 ev
.sigev_notify
= SIGEV_SIGNAL
;
316 ev
.sigev_signo
= SIGRTMIN
;
317 ev
.sigev_value
.sival_ptr
= &ev
;
318 if (mq_notify (q2
, &ev
) != 0)
320 printf ("mq_notify in child (q2, { SIGEV_SIGNAL }) failed with: %m\n");
324 (void) pthread_barrier_wait (b2
);
326 /* Parent unsuccessfully attempts to mq_notify { SIGEV_NONE } on q. */
328 (void) pthread_barrier_wait (b2
);
330 if (mq_close (q2
) != 0)
332 printf ("mq_close failed: %m\n");
336 (void) pthread_barrier_wait (b2
);
338 /* Parent successfully calls mq_notify { SIGEV_NONE } on q3. */
340 (void) pthread_barrier_wait (b2
);
342 memset (&ev
, 0xbb, sizeof (ev
));
343 ev
.sigev_notify
= SIGEV_SIGNAL
;
344 ev
.sigev_signo
= SIGRTMIN
;
345 ev
.sigev_value
.sival_ptr
= &b2
;
346 if (mq_notify (q
, &ev
) == 0)
348 puts ("third mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
351 else if (errno
!= EBUSY
)
353 printf ("third mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
357 (void) pthread_barrier_wait (b2
);
359 /* Parent calls mq_close on q3, which makes the queue available again for
362 (void) pthread_barrier_wait (b2
);
364 memset (&ev
, 0x13, sizeof (ev
));
365 ev
.sigev_notify
= SIGEV_NONE
;
366 if (mq_notify (q
, &ev
) != 0)
368 printf ("mq_notify in child (q, { SIGEV_NONE }) failed with: %m\n");
372 if (mq_notify (q
, NULL
) != 0)
374 printf ("mq_notify in child (q, NULL) failed with: %m\n");
378 (void) pthread_barrier_wait (b2
);
380 struct thr_data thr_data
= { .name
= name
, .b3
= b3
, .q
= q
};
382 int ret
= pthread_create (&th
, NULL
, thr
, &thr_data
);
386 printf ("pthread_created failed with: %m\n");
390 /* Wait till thr calls mq_receive on the empty queue q and blocks on it. */
393 memset (&ev
, 0x5f, sizeof (ev
));
394 ev
.sigev_notify
= SIGEV_SIGNAL
;
395 ev
.sigev_signo
= SIGRTMIN
;
396 ev
.sigev_value
.sival_int
= 0xdeadbeef;
397 if (mq_notify (q
, &ev
) != 0)
399 printf ("fourth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
403 /* Ensure the thr thread gets the signal, not us. */
406 sigaddset (&set
, SIGRTMIN
);
407 if (pthread_sigmask (SIG_BLOCK
, &set
, NULL
))
409 printf ("Failed to block SIGRTMIN in child: %m\n");
413 (void) pthread_barrier_wait (b2
);
415 /* Parent calls mqsend (q), which should wake up mqrecv (q)
416 in the thread but no notification should be sent. */
418 (void) pthread_barrier_wait (b3
);
422 puts ("SIGRTMIN signal caught while thr was blocked on mq_receive");
426 (void) pthread_barrier_wait (b3
);
428 /* Parent calls mqsend (q), which should trigger notification. */
430 (void) pthread_barrier_wait (b3
);
432 /* Thread verifies SIGRTMIN has been received. */
433 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
434 available for registration. */
435 /* Thread calls mq_notify (q, NULL). */
437 (void) pthread_barrier_wait (b3
);
439 memset (&ev
, 0x6a, sizeof (ev
));
440 ev
.sigev_notify
= SIGEV_SIGNAL
;
441 ev
.sigev_signo
= SIGRTMIN
;
442 ev
.sigev_value
.sival_ptr
= do_child
;
443 if (mq_notify (q
, &ev
) != 0)
445 printf ("fifth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
449 (void) pthread_barrier_wait (b3
);
451 /* Thread calls mq_notify (q, NULL), which should unregister the above
454 (void) pthread_barrier_wait (b3
);
456 /* Parent calls mqsend (q), which should not trigger notification. */
458 (void) pthread_barrier_wait (b3
);
462 puts ("SIGRTMIN signal caught while notification has been disabled");
466 memset (&ev
, 0x7b, sizeof (ev
));
467 ev
.sigev_notify
= SIGEV_SIGNAL
;
468 ev
.sigev_signo
= SIGRTMIN
;
469 ev
.sigev_value
.sival_ptr
= thr
;
470 if (mq_notify (q
, &ev
) != 0)
472 printf ("sixth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
476 (void) pthread_barrier_wait (b3
);
478 /* Thread opens a new O_RDONLY mqd_t (q4). */
479 /* Thread calls mq_notify (q4, NULL), which should unregister the above
481 /* Thread calls mq_close (q4). */
483 (void) pthread_barrier_wait (b3
);
485 /* Parent calls mqsend (q), which should not trigger notification. */
487 (void) pthread_barrier_wait (b3
);
491 puts ("SIGRTMIN signal caught while notification has been disabled");
495 memset (&ev
, 0xe1, sizeof (ev
));
496 ev
.sigev_notify
= SIGEV_SIGNAL
;
497 ev
.sigev_signo
= SIGRTMIN
;
498 ev
.sigev_value
.sival_int
= 127;
499 if (mq_notify (q
, &ev
) != 0)
501 printf ("seventh mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
505 (void) pthread_barrier_wait (b3
);
507 /* Thread opens a new O_WRONLY mqd_t (q5). */
508 /* Thread calls mq_notify (q5, NULL), which should unregister the above
510 /* Thread calls mq_close (q5). */
512 (void) pthread_barrier_wait (b3
);
514 /* Parent calls mqsend (q), which should not trigger notification. */
516 (void) pthread_barrier_wait (b3
);
520 puts ("SIGRTMIN signal caught while notification has been disabled");
524 /* Reenable test signals before cleaning up the thread. */
525 if (pthread_sigmask (SIG_UNBLOCK
, &set
, NULL
))
527 printf ("Failed to unblock SIGRTMIN in child: %m\n");
532 ret
= pthread_join (th
, &thr_ret
);
536 printf ("pthread_join failed: %m\n");
542 if (mq_close (q
) != 0)
544 printf ("mq_close failed: %m\n");
551 #define TEST_FUNCTION do_test ()
557 char tmpfname
[] = "/tmp/tst-mqueue5-barrier.XXXXXX";
558 int fd
= mkstemp (tmpfname
);
561 printf ("cannot open temporary file: %m\n");
565 /* Make sure it is always removed. */
568 /* Create one page of data. */
569 size_t ps
= sysconf (_SC_PAGESIZE
);
571 memset (data
, '\0', ps
);
573 /* Write the data to the file. */
574 if (write (fd
, data
, ps
) != (ssize_t
) ps
)
576 puts ("short write");
580 void *mem
= mmap (NULL
, ps
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
581 if (mem
== MAP_FAILED
)
583 printf ("mmap failed: %m\n");
587 pthread_barrier_t
*b2
;
588 b2
= (pthread_barrier_t
*) (((uintptr_t) mem
+ __alignof (pthread_barrier_t
))
589 & ~(__alignof (pthread_barrier_t
) - 1));
591 pthread_barrier_t
*b3
;
594 pthread_barrierattr_t a
;
595 if (pthread_barrierattr_init (&a
) != 0)
597 puts ("barrierattr_init failed");
601 if (pthread_barrierattr_setpshared (&a
, PTHREAD_PROCESS_SHARED
) != 0)
603 puts ("barrierattr_setpshared failed, could not test");
607 if (pthread_barrier_init (b2
, &a
, 2) != 0)
609 puts ("barrier_init failed");
613 if (pthread_barrier_init (b3
, &a
, 3) != 0)
615 puts ("barrier_init failed");
619 if (pthread_barrierattr_destroy (&a
) != 0)
621 puts ("barrierattr_destroy failed");
625 char name
[sizeof "/tst-mqueue5-" + sizeof (pid_t
) * 3];
626 snprintf (name
, sizeof (name
), "/tst-mqueue5-%u", getpid ());
628 struct mq_attr attr
= { .mq_maxmsg
= 1, .mq_msgsize
= 1 };
629 mqd_t q
= mq_open (name
, O_CREAT
| O_EXCL
| O_RDWR
, 0600, &attr
);
633 printf ("mq_open failed with: %m\n");
640 memset (&ev
, 0xaa, sizeof (ev
));
641 ev
.sigev_notify
= SIGEV_NONE
;
642 if (mq_notify (q
, &ev
) != 0)
644 printf ("mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
648 if (mq_notify (q
, &ev
) == 0)
650 puts ("second mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
653 else if (errno
!= EBUSY
)
655 printf ("second mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
659 result
|= mqsend (q
);
661 if (mq_notify (q
, &ev
) != 0)
663 printf ("third mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
667 result
|= mqrecv (q
);
669 if (mq_notify (q
, NULL
) != 0)
671 printf ("mq_notify (q, NULL) failed with: %m\n");
675 if (mq_notify (q
, NULL
) != 0)
677 /* Implementation-defined behaviour, so don't fail,
679 printf ("second mq_notify (q, NULL) failed with: %m\n");
682 struct sigaction sa
= { .sa_sigaction
= rtmin_handler
,
683 .sa_flags
= SA_SIGINFO
};
684 sigemptyset (&sa
.sa_mask
);
685 sigaction (SIGRTMIN
, &sa
, NULL
);
687 memset (&ev
, 0x55, sizeof (ev
));
688 ev
.sigev_notify
= SIGEV_SIGNAL
;
689 ev
.sigev_signo
= SIGRTMIN
;
690 ev
.sigev_value
.sival_int
= 26;
691 if (mq_notify (q
, &ev
) != 0)
693 printf ("mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
697 ev
.sigev_value
.sival_ptr
= &ev
;
698 if (mq_notify (q
, &ev
) == 0)
700 puts ("second mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
703 else if (errno
!= EBUSY
)
705 printf ("second mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
711 puts ("SIGRTMIN signal caught too early");
715 result
|= mqsend (q
);
719 puts ("SIGRTMIN signal did not arrive");
722 else if (rtmin_pid
!= getpid ()
723 || rtmin_uid
!= getuid ()
724 || rtmin_code
!= SI_MESGQ
725 || rtmin_sigval
.sival_int
!= 26)
727 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (26)\n",
728 rtmin_pid
, getpid (), rtmin_uid
, getuid (),
729 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
);
733 ev
.sigev_value
.sival_int
= 75;
734 if (mq_notify (q
, &ev
) != 0)
736 printf ("third mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
740 result
|= mqrecv (q
);
742 if (mq_notify (q
, NULL
) != 0)
744 printf ("mq_notify (q, NULL) failed with: %m\n");
748 memset (&ev
, 0x33, sizeof (ev
));
749 ev
.sigev_notify
= SIGEV_NONE
;
750 if (mq_notify (q
, &ev
) != 0)
752 printf ("fourth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
759 printf ("fork () failed: %m\n");
765 do_child (name
, b2
, b3
, q
);
767 /* Child unsuccessfully attempts to mq_notify. */
769 (void) pthread_barrier_wait (b2
);
771 result
|= mqsend (q
);
773 (void) pthread_barrier_wait (b2
);
775 /* Child successfully calls mq_notify SIGEV_SIGNAL now. */
777 result
|= mqrecv (q
);
779 (void) pthread_barrier_wait (b2
);
781 memset (&ev
, 0xbb, sizeof (ev
));
782 ev
.sigev_notify
= SIGEV_SIGNAL
;
783 ev
.sigev_signo
= SIGRTMIN
;
784 ev
.sigev_value
.sival_int
= 15;
785 if (mq_notify (q
, &ev
) == 0)
787 puts ("fourth mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
790 else if (errno
!= EBUSY
)
792 printf ("fourth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
796 result
|= mqsend (q
);
798 if (mq_notify (q
, &ev
) != 0)
800 printf ("fifth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
806 puts ("SIGRTMIN signal caught too early");
810 result
|= mqrecv (q
);
812 (void) pthread_barrier_wait (b2
);
814 /* Child verifies caught SIGRTMIN signal. */
815 /* Child calls mq_send (q) which triggers SIGRTMIN signal here. */
817 (void) pthread_barrier_wait (b2
);
819 /* Child mq_open's another mqd_t for the same queue (q2). */
823 puts ("SIGRTMIN signal did not arrive");
826 else if (rtmin_pid
!= pid
827 || rtmin_uid
!= getuid ()
828 || rtmin_code
!= SI_MESGQ
829 || rtmin_sigval
.sival_int
!= 15)
831 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (15)\n",
832 rtmin_pid
, pid
, rtmin_uid
, getuid (),
833 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
);
837 result
|= mqrecv (q
);
839 (void) pthread_barrier_wait (b2
);
841 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q2. */
843 (void) pthread_barrier_wait (b2
);
845 memset (&ev
, 0xbb, sizeof (ev
));
846 ev
.sigev_notify
= SIGEV_NONE
;
847 if (mq_notify (q
, &ev
) == 0)
849 puts ("fifth mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
852 else if (errno
!= EBUSY
)
854 printf ("fifth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
858 (void) pthread_barrier_wait (b2
);
860 /* Child calls mq_close on q2, which makes the queue available again for
863 mqd_t q3
= mq_open (name
, O_RDWR
);
864 if (q3
== (mqd_t
) -1)
866 printf ("mq_open q3 in parent failed with: %m\n");
870 (void) pthread_barrier_wait (b2
);
872 memset (&ev
, 0x12, sizeof (ev
));
873 ev
.sigev_notify
= SIGEV_NONE
;
874 if (mq_notify (q3
, &ev
) != 0)
876 printf ("mq_notify (q3, { SIGEV_NONE }) failed with: %m\n");
880 (void) pthread_barrier_wait (b2
);
882 /* Child unsuccessfully attempts to mq_notify { SIGEV_SIGNAL } on q. */
884 (void) pthread_barrier_wait (b2
);
886 if (mq_close (q3
) != 0)
888 printf ("mq_close failed: %m\n");
892 (void) pthread_barrier_wait (b2
);
894 /* Child successfully calls mq_notify { SIGEV_NONE } on q. */
895 /* Child successfully calls mq_notify NULL on q. */
897 (void) pthread_barrier_wait (b2
);
899 /* Child creates new thread. */
900 /* Thread blocks on mqrecv (q). */
901 /* Child sleeps for 1sec so that thread has time to reach that point. */
902 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q. */
904 (void) pthread_barrier_wait (b2
);
906 result
|= mqsend (q
);
908 (void) pthread_barrier_wait (b3
);
910 /* Child verifies SIGRTMIN has not been sent. */
912 (void) pthread_barrier_wait (b3
);
914 result
|= mqsend (q
);
916 (void) pthread_barrier_wait (b3
);
918 /* Thread verifies SIGRTMIN has been caught. */
919 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
920 available for registration. */
921 /* Thread calls mq_notify (q, NULL). */
923 (void) pthread_barrier_wait (b3
);
925 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
927 (void) pthread_barrier_wait (b3
);
929 /* Thread calls mq_notify (q, NULL). */
931 (void) pthread_barrier_wait (b3
);
933 result
|= mqsend (q
);
934 result
|= mqrecv (q
);
936 (void) pthread_barrier_wait (b3
);
938 /* Child verifies SIGRTMIN has not been sent. */
939 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
941 (void) pthread_barrier_wait (b3
);
943 /* Thread opens a new O_RDONLY mqd_t (q4). */
944 /* Thread calls mq_notify (q4, NULL). */
945 /* Thread calls mq_close (q4). */
947 (void) pthread_barrier_wait (b3
);
949 result
|= mqsend (q
);
950 result
|= mqrecv (q
);
952 (void) pthread_barrier_wait (b3
);
954 /* Child verifies SIGRTMIN has not been sent. */
955 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
957 (void) pthread_barrier_wait (b3
);
959 /* Thread opens a new O_WRONLY mqd_t (q5). */
960 /* Thread calls mq_notify (q5, NULL). */
961 /* Thread calls mq_close (q5). */
963 (void) pthread_barrier_wait (b3
);
965 result
|= mqsend (q
);
966 result
|= mqrecv (q
);
968 (void) pthread_barrier_wait (b3
);
970 /* Child verifies SIGRTMIN has not been sent. */
973 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
975 puts ("waitpid failed");
979 else if (!WIFEXITED (status
) || WEXITSTATUS (status
))
981 printf ("child failed with status %d\n", status
);
985 if (mq_unlink (name
) != 0)
987 printf ("mq_unlink failed: %m\n");
991 if (mq_close (q
) != 0)
993 printf ("mq_close failed: %m\n");
997 if (mq_notify (q
, NULL
) == 0)
999 puts ("mq_notify on closed mqd_t unexpectedly succeeded");
1002 else if (errno
!= EBADF
)
1004 printf ("mq_notify on closed mqd_t did not fail with EBADF: %m\n");
1008 memset (&ev
, 0x55, sizeof (ev
));
1009 ev
.sigev_notify
= SIGEV_NONE
;
1010 if (mq_notify (q
, &ev
) == 0)
1012 puts ("mq_notify on closed mqd_t unexpectedly succeeded");
1015 else if (errno
!= EBADF
)
1017 printf ("mq_notify on closed mqd_t did not fail with EBADF: %m\n");
1024 # define TEST_FUNCTION 0
1027 #include "../test-skeleton.c"