2 Copyright (C) 2004 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
35 #include "tst-mqueue.h"
42 volatile int rtmin_cnt
;
43 volatile pid_t rtmin_pid
;
44 volatile uid_t rtmin_uid
;
45 volatile int rtmin_code
;
46 volatile union sigval rtmin_sigval
;
49 rtmin_handler (int sig
, siginfo_t
*info
, void *ctx
)
54 rtmin_pid
= info
->si_pid
;
55 rtmin_uid
= info
->si_uid
;
56 rtmin_code
= info
->si_code
;
57 rtmin_sigval
= info
->si_value
;
60 #define mqsend(q) (mqsend) (q, __LINE__)
62 (mqsend
) (mqd_t q
, int line
)
65 if (mq_send (q
, &c
, 1, 1) != 0)
67 printf ("mq_send on line %d failed with: %m\n", line
);
73 #define mqrecv(q) (mqrecv) (q, __LINE__)
75 (mqrecv
) (mqd_t q
, int line
)
78 ssize_t rets
= TEMP_FAILURE_RETRY (mq_receive (q
, &c
, 1, NULL
));
82 printf ("mq_receive on line %d failed with: %m\n", line
);
84 printf ("mq_receive on line %d returned %zd != 1\n",
94 pthread_barrier_t
*b3
;
101 pthread_barrier_t
*b3
= ((struct thr_data
*)arg
)->b3
;
102 mqd_t q
= ((struct thr_data
*)arg
)->q
;
103 const char *name
= ((struct thr_data
*)arg
)->name
;
106 result
|= mqrecv (q
);
108 (void) pthread_barrier_wait (b3
);
110 /* Child verifies SIGRTMIN has not been sent. */
112 (void) pthread_barrier_wait (b3
);
114 /* Parent calls mqsend (q), which should trigger notification. */
116 (void) pthread_barrier_wait (b3
);
120 puts ("SIGRTMIN signal in child did not arrive");
123 else if (rtmin_pid
!= getppid ()
124 || rtmin_uid
!= getuid ()
125 || rtmin_code
!= SI_MESGQ
126 || rtmin_sigval
.sival_int
!= 0xdeadbeef)
128 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (%d)\n",
129 rtmin_pid
, getppid (), rtmin_uid
, getuid (),
130 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
, 0xdeadbeef);
135 memset (&ev
, 0x82, sizeof (ev
));
136 ev
.sigev_notify
= SIGEV_NONE
;
137 if (mq_notify (q
, &ev
) != 0)
139 printf ("mq_notify in thread (q, { SIGEV_NONE }) failed with: %m\n");
143 if (mq_notify (q
, NULL
) != 0)
145 printf ("mq_notify in thread (q, NULL) failed with: %m\n");
149 result
|= mqrecv (q
);
151 (void) pthread_barrier_wait (b3
);
153 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
155 (void) pthread_barrier_wait (b3
);
157 if (mq_notify (q
, NULL
) != 0)
159 printf ("second mq_notify in thread (q, NULL) failed with: %m\n");
163 (void) pthread_barrier_wait (b3
);
165 /* Parent calls mqsend (q), which should not trigger notification. */
167 (void) pthread_barrier_wait (b3
);
169 /* Child verifies SIGRTMIN has not been received. */
170 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
172 (void) pthread_barrier_wait (b3
);
174 mqd_t q4
= mq_open (name
, O_RDONLY
);
175 if (q4
== (mqd_t
) -1)
177 printf ("mq_open in thread failed with: %m\n");
181 if (mq_notify (q4
, NULL
) != 0)
183 printf ("mq_notify in thread (q4, NULL) failed with: %m\n");
187 if (mq_close (q4
) != 0)
189 printf ("mq_close in thread failed with: %m\n");
193 (void) pthread_barrier_wait (b3
);
195 /* Parent calls mqsend (q), which should not trigger notification. */
197 (void) pthread_barrier_wait (b3
);
199 /* Child verifies SIGRTMIN has not been received. */
200 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
202 (void) pthread_barrier_wait (b3
);
204 mqd_t q5
= mq_open (name
, O_WRONLY
);
205 if (q5
== (mqd_t
) -1)
207 printf ("mq_open O_WRONLY in thread failed with: %m\n");
211 if (mq_notify (q5
, NULL
) != 0)
213 printf ("mq_notify in thread (q5, NULL) failed with: %m\n");
217 if (mq_close (q5
) != 0)
219 printf ("mq_close in thread failed with: %m\n");
223 (void) pthread_barrier_wait (b3
);
225 /* Parent calls mqsend (q), which should not trigger notification. */
227 (void) pthread_barrier_wait (b3
);
229 /* Child verifies SIGRTMIN has not been received. */
231 return (void *) (long) result
;
235 do_child (const char *name
, pthread_barrier_t
*b2
, pthread_barrier_t
*b3
,
241 memset (&ev
, 0x55, sizeof (ev
));
242 ev
.sigev_notify
= SIGEV_SIGNAL
;
243 ev
.sigev_signo
= SIGRTMIN
;
244 ev
.sigev_value
.sival_ptr
= &ev
;
245 if (mq_notify (q
, &ev
) == 0)
247 puts ("first mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
250 else if (errno
!= EBUSY
)
252 printf ("first mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
256 (void) pthread_barrier_wait (b2
);
258 /* Parent calls mqsend (q), which makes notification available. */
260 (void) pthread_barrier_wait (b2
);
264 if (mq_notify (q
, &ev
) != 0)
266 printf ("second mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
272 puts ("SIGRTMIN signal in child caught too early");
276 (void) pthread_barrier_wait (b2
);
278 /* Parent unsuccessfully attempts to mq_notify. */
279 /* Parent calls mqsend (q), which makes notification available
280 and triggers a signal in the child. */
281 /* Parent successfully calls mq_notify SIGEV_SIGNAL. */
283 (void) pthread_barrier_wait (b2
);
287 puts ("SIGRTMIN signal in child did not arrive");
290 else if (rtmin_pid
!= getppid ()
291 || rtmin_uid
!= getuid ()
292 || rtmin_code
!= SI_MESGQ
293 || rtmin_sigval
.sival_ptr
!= &ev
)
295 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_ptr %p (%p)\n",
296 rtmin_pid
, getppid (), rtmin_uid
, getuid (),
297 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_ptr
, &ev
);
301 result
|= mqsend (q
);
303 (void) pthread_barrier_wait (b2
);
305 /* Parent verifies caught SIGRTMIN. */
307 mqd_t q2
= mq_open (name
, O_RDWR
);
308 if (q2
== (mqd_t
) -1)
310 printf ("mq_open in child failed with: %m\n");
314 (void) pthread_barrier_wait (b2
);
316 /* Parent mq_open's another mqd_t for the same queue (q3). */
318 memset (&ev
, 0x11, sizeof (ev
));
319 ev
.sigev_notify
= SIGEV_SIGNAL
;
320 ev
.sigev_signo
= SIGRTMIN
;
321 ev
.sigev_value
.sival_ptr
= &ev
;
322 if (mq_notify (q2
, &ev
) != 0)
324 printf ("mq_notify in child (q2, { SIGEV_SIGNAL }) failed with: %m\n");
328 (void) pthread_barrier_wait (b2
);
330 /* Parent unsuccessfully attempts to mq_notify { SIGEV_NONE } on q. */
332 (void) pthread_barrier_wait (b2
);
334 if (mq_close (q2
) != 0)
336 printf ("mq_close failed: %m\n");
340 (void) pthread_barrier_wait (b2
);
342 /* Parent successfully calls mq_notify { SIGEV_NONE } on q3. */
344 (void) pthread_barrier_wait (b2
);
346 memset (&ev
, 0xbb, sizeof (ev
));
347 ev
.sigev_notify
= SIGEV_SIGNAL
;
348 ev
.sigev_signo
= SIGRTMIN
;
349 ev
.sigev_value
.sival_ptr
= &b2
;
350 if (mq_notify (q
, &ev
) == 0)
352 puts ("third mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
355 else if (errno
!= EBUSY
)
357 printf ("third mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
361 (void) pthread_barrier_wait (b2
);
363 /* Parent calls mq_close on q3, which makes the queue available again for
366 (void) pthread_barrier_wait (b2
);
368 memset (&ev
, 0x13, sizeof (ev
));
369 ev
.sigev_notify
= SIGEV_NONE
;
370 if (mq_notify (q
, &ev
) != 0)
372 printf ("mq_notify in child (q, { SIGEV_NONE }) failed with: %m\n");
376 if (mq_notify (q
, NULL
) != 0)
378 printf ("mq_notify in child (q, NULL) failed with: %m\n");
382 (void) pthread_barrier_wait (b2
);
384 struct thr_data thr_data
= { .name
= name
, .b3
= b3
, .q
= q
};
386 int ret
= pthread_create (&th
, NULL
, thr
, &thr_data
);
390 printf ("pthread_created failed with: %m\n");
394 /* Wait till thr calls mq_receive on the empty queue q and blocks on it. */
397 memset (&ev
, 0x5f, sizeof (ev
));
398 ev
.sigev_notify
= SIGEV_SIGNAL
;
399 ev
.sigev_signo
= SIGRTMIN
;
400 ev
.sigev_value
.sival_int
= 0xdeadbeef;
401 if (mq_notify (q
, &ev
) != 0)
403 printf ("fourth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
407 (void) pthread_barrier_wait (b2
);
409 /* Parent calls mqsend (q), which should wake up mqrecv (q)
410 in the thread but no notification should be sent. */
412 (void) pthread_barrier_wait (b3
);
416 puts ("SIGRTMIN signal caught while thr was blocked on mq_receive");
420 (void) pthread_barrier_wait (b3
);
422 /* Parent calls mqsend (q), which should trigger notification. */
424 (void) pthread_barrier_wait (b3
);
426 /* Thread verifies SIGRTMIN has been received. */
427 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
428 available for registration. */
429 /* Thread calls mq_notify (q, NULL). */
431 (void) pthread_barrier_wait (b3
);
433 memset (&ev
, 0x6a, sizeof (ev
));
434 ev
.sigev_notify
= SIGEV_SIGNAL
;
435 ev
.sigev_signo
= SIGRTMIN
;
436 ev
.sigev_value
.sival_ptr
= do_child
;
437 if (mq_notify (q
, &ev
) != 0)
439 printf ("fifth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
443 (void) pthread_barrier_wait (b3
);
445 /* Thread calls mq_notify (q, NULL), which should unregister the above
448 (void) pthread_barrier_wait (b3
);
450 /* Parent calls mqsend (q), which should not trigger notification. */
452 (void) pthread_barrier_wait (b3
);
456 puts ("SIGRTMIN signal caught while notification has been disabled");
460 memset (&ev
, 0x7b, sizeof (ev
));
461 ev
.sigev_notify
= SIGEV_SIGNAL
;
462 ev
.sigev_signo
= SIGRTMIN
;
463 ev
.sigev_value
.sival_ptr
= thr
;
464 if (mq_notify (q
, &ev
) != 0)
466 printf ("sixth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
470 (void) pthread_barrier_wait (b3
);
472 /* Thread opens a new O_RDONLY mqd_t (q4). */
473 /* Thread calls mq_notify (q4, NULL), which should unregister the above
475 /* Thread calls mq_close (q4). */
477 (void) pthread_barrier_wait (b3
);
479 /* Parent calls mqsend (q), which should not trigger notification. */
481 (void) pthread_barrier_wait (b3
);
485 puts ("SIGRTMIN signal caught while notification has been disabled");
489 memset (&ev
, 0xe1, sizeof (ev
));
490 ev
.sigev_notify
= SIGEV_SIGNAL
;
491 ev
.sigev_signo
= SIGRTMIN
;
492 ev
.sigev_value
.sival_int
= 127;
493 if (mq_notify (q
, &ev
) != 0)
495 printf ("seventh mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
499 (void) pthread_barrier_wait (b3
);
501 /* Thread opens a new O_WRONLY mqd_t (q5). */
502 /* Thread calls mq_notify (q5, NULL), which should unregister the above
504 /* Thread calls mq_close (q5). */
506 (void) pthread_barrier_wait (b3
);
508 /* Parent calls mqsend (q), which should not trigger notification. */
510 (void) pthread_barrier_wait (b3
);
514 puts ("SIGRTMIN signal caught while notification has been disabled");
519 ret
= pthread_join (th
, &thr_ret
);
523 printf ("pthread_join failed: %m\n");
529 if (mq_close (q
) != 0)
531 printf ("mq_close failed: %m\n");
538 #define TEST_FUNCTION do_test ()
544 char tmpfname
[] = "/tmp/tst-mqueue5-barrier.XXXXXX";
545 int fd
= mkstemp (tmpfname
);
548 printf ("cannot open temporary file: %m\n");
552 /* Make sure it is always removed. */
555 /* Create one page of data. */
556 size_t ps
= sysconf (_SC_PAGESIZE
);
558 memset (data
, '\0', ps
);
560 /* Write the data to the file. */
561 if (write (fd
, data
, ps
) != (ssize_t
) ps
)
563 puts ("short write");
567 void *mem
= mmap (NULL
, ps
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
568 if (mem
== MAP_FAILED
)
570 printf ("mmap failed: %m\n");
574 pthread_barrier_t
*b2
;
575 b2
= (pthread_barrier_t
*) (((uintptr_t) mem
+ __alignof (pthread_barrier_t
))
576 & ~(__alignof (pthread_barrier_t
) - 1));
578 pthread_barrier_t
*b3
;
581 pthread_barrierattr_t a
;
582 if (pthread_barrierattr_init (&a
) != 0)
584 puts ("barrierattr_init failed");
588 if (pthread_barrierattr_setpshared (&a
, PTHREAD_PROCESS_SHARED
) != 0)
590 puts ("barrierattr_setpshared failed, could not test");
594 if (pthread_barrier_init (b2
, &a
, 2) != 0)
596 puts ("barrier_init failed");
600 if (pthread_barrier_init (b3
, &a
, 3) != 0)
602 puts ("barrier_init failed");
606 if (pthread_barrierattr_destroy (&a
) != 0)
608 puts ("barrierattr_destroy failed");
612 char name
[sizeof "/tst-mqueue5-" + sizeof (pid_t
) * 3];
613 snprintf (name
, sizeof (name
), "/tst-mqueue5-%u", getpid ());
615 struct mq_attr attr
= { .mq_maxmsg
= 1, .mq_msgsize
= 1 };
616 mqd_t q
= mq_open (name
, O_CREAT
| O_EXCL
| O_RDWR
, 0600, &attr
);
620 printf ("mq_open failed with: %m\n");
627 memset (&ev
, 0xaa, sizeof (ev
));
628 ev
.sigev_notify
= SIGEV_NONE
;
629 if (mq_notify (q
, &ev
) != 0)
631 printf ("mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
635 if (mq_notify (q
, &ev
) == 0)
637 puts ("second mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
640 else if (errno
!= EBUSY
)
642 printf ("second mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
646 result
|= mqsend (q
);
648 if (mq_notify (q
, &ev
) != 0)
650 printf ("third mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
654 result
|= mqrecv (q
);
656 if (mq_notify (q
, NULL
) != 0)
658 printf ("mq_notify (q, NULL) failed with: %m\n");
662 if (mq_notify (q
, NULL
) != 0)
664 /* Implementation-defined behaviour, so don't fail,
666 printf ("second mq_notify (q, NULL) failed with: %m\n");
669 struct sigaction sa
= { .sa_sigaction
= rtmin_handler
,
670 .sa_flags
= SA_SIGINFO
};
671 sigemptyset (&sa
.sa_mask
);
672 sigaction (SIGRTMIN
, &sa
, NULL
);
674 memset (&ev
, 0x55, sizeof (ev
));
675 ev
.sigev_notify
= SIGEV_SIGNAL
;
676 ev
.sigev_signo
= SIGRTMIN
;
677 ev
.sigev_value
.sival_int
= 26;
678 if (mq_notify (q
, &ev
) != 0)
680 printf ("mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
684 ev
.sigev_value
.sival_ptr
= &ev
;
685 if (mq_notify (q
, &ev
) == 0)
687 puts ("second mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
690 else if (errno
!= EBUSY
)
692 printf ("second mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
698 puts ("SIGRTMIN signal caught too early");
702 result
|= mqsend (q
);
706 puts ("SIGRTMIN signal did not arrive");
709 else if (rtmin_pid
!= getpid ()
710 || rtmin_uid
!= getuid ()
711 || rtmin_code
!= SI_MESGQ
712 || rtmin_sigval
.sival_int
!= 26)
714 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (26)\n",
715 rtmin_pid
, getpid (), rtmin_uid
, getuid (),
716 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
);
720 ev
.sigev_value
.sival_int
= 75;
721 if (mq_notify (q
, &ev
) != 0)
723 printf ("third mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
727 result
|= mqrecv (q
);
729 if (mq_notify (q
, NULL
) != 0)
731 printf ("mq_notify (q, NULL) failed with: %m\n");
735 memset (&ev
, 0x33, sizeof (ev
));
736 ev
.sigev_notify
= SIGEV_NONE
;
737 if (mq_notify (q
, &ev
) != 0)
739 printf ("fourth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
746 printf ("fork () failed: %m\n");
752 do_child (name
, b2
, b3
, q
);
754 /* Child unsuccessfully attempts to mq_notify. */
756 (void) pthread_barrier_wait (b2
);
758 result
|= mqsend (q
);
760 (void) pthread_barrier_wait (b2
);
762 /* Child successfully calls mq_notify SIGEV_SIGNAL now. */
764 result
|= mqrecv (q
);
766 (void) pthread_barrier_wait (b2
);
768 memset (&ev
, 0xbb, sizeof (ev
));
769 ev
.sigev_notify
= SIGEV_SIGNAL
;
770 ev
.sigev_signo
= SIGRTMIN
;
771 ev
.sigev_value
.sival_int
= 15;
772 if (mq_notify (q
, &ev
) == 0)
774 puts ("fourth mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
777 else if (errno
!= EBUSY
)
779 printf ("fourth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
783 result
|= mqsend (q
);
785 if (mq_notify (q
, &ev
) != 0)
787 printf ("fifth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
793 puts ("SIGRTMIN signal caught too early");
797 result
|= mqrecv (q
);
799 (void) pthread_barrier_wait (b2
);
801 /* Child verifies caught SIGRTMIN signal. */
802 /* Child calls mq_send (q) which triggers SIGRTMIN signal here. */
804 (void) pthread_barrier_wait (b2
);
806 /* Child mq_open's another mqd_t for the same queue (q2). */
810 puts ("SIGRTMIN signal did not arrive");
813 else if (rtmin_pid
!= pid
814 || rtmin_uid
!= getuid ()
815 || rtmin_code
!= SI_MESGQ
816 || rtmin_sigval
.sival_int
!= 15)
818 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (15)\n",
819 rtmin_pid
, pid
, rtmin_uid
, getuid (),
820 rtmin_code
, SI_MESGQ
, rtmin_sigval
.sival_int
);
824 result
|= mqrecv (q
);
826 (void) pthread_barrier_wait (b2
);
828 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q2. */
830 (void) pthread_barrier_wait (b2
);
832 memset (&ev
, 0xbb, sizeof (ev
));
833 ev
.sigev_notify
= SIGEV_NONE
;
834 if (mq_notify (q
, &ev
) == 0)
836 puts ("fifth mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
839 else if (errno
!= EBUSY
)
841 printf ("fifth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
845 (void) pthread_barrier_wait (b2
);
847 /* Child calls mq_close on q2, which makes the queue available again for
850 mqd_t q3
= mq_open (name
, O_RDWR
);
851 if (q3
== (mqd_t
) -1)
853 printf ("mq_open q3 in parent failed with: %m\n");
857 (void) pthread_barrier_wait (b2
);
859 memset (&ev
, 0x12, sizeof (ev
));
860 ev
.sigev_notify
= SIGEV_NONE
;
861 if (mq_notify (q3
, &ev
) != 0)
863 printf ("mq_notify (q3, { SIGEV_NONE }) failed with: %m\n");
867 (void) pthread_barrier_wait (b2
);
869 /* Child unsuccessfully attempts to mq_notify { SIGEV_SIGNAL } on q. */
871 (void) pthread_barrier_wait (b2
);
873 if (mq_close (q3
) != 0)
875 printf ("mq_close failed: %m\n");
879 (void) pthread_barrier_wait (b2
);
881 /* Child successfully calls mq_notify { SIGEV_NONE } on q. */
882 /* Child successfully calls mq_notify NULL on q. */
884 (void) pthread_barrier_wait (b2
);
886 /* Child creates new thread. */
887 /* Thread blocks on mqrecv (q). */
888 /* Child sleeps for 1sec so that thread has time to reach that point. */
889 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q. */
891 (void) pthread_barrier_wait (b2
);
893 result
|= mqsend (q
);
895 (void) pthread_barrier_wait (b3
);
897 /* Child verifies SIGRTMIN has not been sent. */
899 (void) pthread_barrier_wait (b3
);
901 result
|= mqsend (q
);
903 (void) pthread_barrier_wait (b3
);
905 /* Thread verifies SIGRTMIN has been caught. */
906 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
907 available for registration. */
908 /* Thread calls mq_notify (q, NULL). */
910 (void) pthread_barrier_wait (b3
);
912 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
914 (void) pthread_barrier_wait (b3
);
916 /* Thread calls mq_notify (q, NULL). */
918 (void) pthread_barrier_wait (b3
);
920 result
|= mqsend (q
);
921 result
|= mqrecv (q
);
923 (void) pthread_barrier_wait (b3
);
925 /* Child verifies SIGRTMIN has not been sent. */
926 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
928 (void) pthread_barrier_wait (b3
);
930 /* Thread opens a new O_RDONLY mqd_t (q4). */
931 /* Thread calls mq_notify (q4, NULL). */
932 /* Thread calls mq_close (q4). */
934 (void) pthread_barrier_wait (b3
);
936 result
|= mqsend (q
);
937 result
|= mqrecv (q
);
939 (void) pthread_barrier_wait (b3
);
941 /* Child verifies SIGRTMIN has not been sent. */
942 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
944 (void) pthread_barrier_wait (b3
);
946 /* Thread opens a new O_WRONLY mqd_t (q5). */
947 /* Thread calls mq_notify (q5, NULL). */
948 /* Thread calls mq_close (q5). */
950 (void) pthread_barrier_wait (b3
);
952 result
|= mqsend (q
);
953 result
|= mqrecv (q
);
955 (void) pthread_barrier_wait (b3
);
957 /* Child verifies SIGRTMIN has not been sent. */
960 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
962 puts ("waitpid failed");
966 else if (!WIFEXITED (status
) || WEXITSTATUS (status
))
968 printf ("child failed with status %d\n", status
);
972 if (mq_unlink (name
) != 0)
974 printf ("mq_unlink failed: %m\n");
978 if (mq_close (q
) != 0)
980 printf ("mq_close failed: %m\n");
984 if (mq_notify (q
, NULL
) == 0)
986 puts ("mq_notify on closed mqd_t unexpectedly succeeded");
989 else if (errno
!= EBADF
)
991 printf ("mq_notify on closed mqd_t did not fail with EBADF: %m\n");
995 memset (&ev
, 0x55, sizeof (ev
));
996 ev
.sigev_notify
= SIGEV_NONE
;
997 if (mq_notify (q
, &ev
) == 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");
1011 # define TEST_FUNCTION 0
1014 #include "../test-skeleton.c"