Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / rt / tst-mqueue5.c
blobe96d7c3dc5e1dbd337f5628c4b08571105b1ee13
1 /* Test mq_notify.
2 Copyright (C) 2004-2018 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 <http://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <fcntl.h>
22 #include <mqueue.h>
23 #include <limits.h>
24 #include <signal.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/mman.h>
30 #include <sys/time.h>
31 #include <sys/wait.h>
32 #include <time.h>
33 #include <unistd.h>
34 #include "tst-mqueue.h"
36 #define TIMEOUT 3
38 #if _POSIX_THREADS && defined SIGRTMIN && defined SA_SIGINFO
39 # include <pthread.h>
41 volatile int rtmin_cnt;
42 volatile pid_t rtmin_pid;
43 volatile uid_t rtmin_uid;
44 volatile int rtmin_code;
45 volatile union sigval rtmin_sigval;
47 static void
48 rtmin_handler (int sig, siginfo_t *info, void *ctx)
50 if (sig != SIGRTMIN)
51 abort ();
52 ++rtmin_cnt;
53 rtmin_pid = info->si_pid;
54 rtmin_uid = info->si_uid;
55 rtmin_code = info->si_code;
56 rtmin_sigval = info->si_value;
59 #define mqsend(q) (mqsend) (q, __LINE__)
60 static int
61 (mqsend) (mqd_t q, int line)
63 char c;
64 if (mq_send (q, &c, 1, 1) != 0)
66 printf ("mq_send on line %d failed with: %m\n", line);
67 return 1;
69 return 0;
72 #define mqrecv(q) (mqrecv) (q, __LINE__)
73 static int
74 (mqrecv) (mqd_t q, int line)
76 char c;
77 ssize_t rets = TEMP_FAILURE_RETRY (mq_receive (q, &c, 1, NULL));
78 if (rets != 1)
80 if (rets == -1)
81 printf ("mq_receive on line %d failed with: %m\n", line);
82 else
83 printf ("mq_receive on line %d returned %zd != 1\n",
84 line, rets);
85 return 1;
87 return 0;
90 struct thr_data
92 const char *name;
93 pthread_barrier_t *b3;
94 mqd_t q;
97 static void *
98 thr (void *arg)
100 pthread_barrier_t *b3 = ((struct thr_data *)arg)->b3;
101 mqd_t q = ((struct thr_data *)arg)->q;
102 const char *name = ((struct thr_data *)arg)->name;
103 int result = 0;
105 result |= mqrecv (q);
107 (void) pthread_barrier_wait (b3);
109 /* Child verifies SIGRTMIN has not been sent. */
111 (void) pthread_barrier_wait (b3);
113 /* Parent calls mqsend (q), which should trigger notification. */
115 (void) pthread_barrier_wait (b3);
117 if (rtmin_cnt != 2)
119 puts ("SIGRTMIN signal in thread did not arrive");
120 result = 1;
122 else if (rtmin_pid != getppid ()
123 || rtmin_uid != getuid ()
124 || rtmin_code != SI_MESGQ
125 || rtmin_sigval.sival_int != 0xdeadbeef)
127 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (%d)\n",
128 rtmin_pid, getppid (), rtmin_uid, getuid (),
129 rtmin_code, SI_MESGQ, rtmin_sigval.sival_int, 0xdeadbeef);
130 result = 1;
133 struct sigevent ev;
134 memset (&ev, 0x82, sizeof (ev));
135 ev.sigev_notify = SIGEV_NONE;
136 if (mq_notify (q, &ev) != 0)
138 printf ("mq_notify in thread (q, { SIGEV_NONE }) failed with: %m\n");
139 result = 1;
142 if (mq_notify (q, NULL) != 0)
144 printf ("mq_notify in thread (q, NULL) failed with: %m\n");
145 result = 1;
148 result |= mqrecv (q);
150 (void) pthread_barrier_wait (b3);
152 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
154 (void) pthread_barrier_wait (b3);
156 if (mq_notify (q, NULL) != 0)
158 printf ("second mq_notify in thread (q, NULL) failed with: %m\n");
159 result = 1;
162 (void) pthread_barrier_wait (b3);
164 /* Parent calls mqsend (q), which should not trigger notification. */
166 (void) pthread_barrier_wait (b3);
168 /* Child verifies SIGRTMIN has not been received. */
169 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
171 (void) pthread_barrier_wait (b3);
173 mqd_t q4 = mq_open (name, O_RDONLY);
174 if (q4 == (mqd_t) -1)
176 printf ("mq_open in thread failed with: %m\n");
177 result = 1;
180 if (mq_notify (q4, NULL) != 0)
182 printf ("mq_notify in thread (q4, NULL) failed with: %m\n");
183 result = 1;
186 if (mq_close (q4) != 0)
188 printf ("mq_close in thread failed with: %m\n");
189 result = 1;
192 (void) pthread_barrier_wait (b3);
194 /* Parent calls mqsend (q), which should not trigger notification. */
196 (void) pthread_barrier_wait (b3);
198 /* Child verifies SIGRTMIN has not been received. */
199 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
201 (void) pthread_barrier_wait (b3);
203 mqd_t q5 = mq_open (name, O_WRONLY);
204 if (q5 == (mqd_t) -1)
206 printf ("mq_open O_WRONLY in thread failed with: %m\n");
207 result = 1;
210 if (mq_notify (q5, NULL) != 0)
212 printf ("mq_notify in thread (q5, NULL) failed with: %m\n");
213 result = 1;
216 if (mq_close (q5) != 0)
218 printf ("mq_close in thread failed with: %m\n");
219 result = 1;
222 (void) pthread_barrier_wait (b3);
224 /* Parent calls mqsend (q), which should not trigger notification. */
226 (void) pthread_barrier_wait (b3);
228 /* Child verifies SIGRTMIN has not been received. */
230 return (void *) (long) result;
233 static void
234 do_child (const char *name, pthread_barrier_t *b2, pthread_barrier_t *b3,
235 mqd_t q)
237 int result = 0;
239 struct sigevent ev;
240 memset (&ev, 0x55, sizeof (ev));
241 ev.sigev_notify = SIGEV_SIGNAL;
242 ev.sigev_signo = SIGRTMIN;
243 ev.sigev_value.sival_ptr = &ev;
244 if (mq_notify (q, &ev) == 0)
246 puts ("first mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
247 result = 1;
249 else if (errno != EBUSY)
251 printf ("first mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
252 result = 1;
255 (void) pthread_barrier_wait (b2);
257 /* Parent calls mqsend (q), which makes notification available. */
259 (void) pthread_barrier_wait (b2);
261 rtmin_cnt = 0;
263 if (mq_notify (q, &ev) != 0)
265 printf ("second mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
266 result = 1;
269 if (rtmin_cnt != 0)
271 puts ("SIGRTMIN signal in child caught too early");
272 result = 1;
275 (void) pthread_barrier_wait (b2);
277 /* Parent unsuccessfully attempts to mq_notify. */
278 /* Parent calls mqsend (q), which makes notification available
279 and triggers a signal in the child. */
280 /* Parent successfully calls mq_notify SIGEV_SIGNAL. */
282 (void) pthread_barrier_wait (b2);
284 if (rtmin_cnt != 1)
286 puts ("SIGRTMIN signal in child did not arrive");
287 result = 1;
289 else if (rtmin_pid != getppid ()
290 || rtmin_uid != getuid ()
291 || rtmin_code != SI_MESGQ
292 || rtmin_sigval.sival_ptr != &ev)
294 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_ptr %p (%p)\n",
295 rtmin_pid, getppid (), rtmin_uid, getuid (),
296 rtmin_code, SI_MESGQ, rtmin_sigval.sival_ptr, &ev);
297 result = 1;
300 result |= mqsend (q);
302 (void) pthread_barrier_wait (b2);
304 /* Parent verifies caught SIGRTMIN. */
306 mqd_t q2 = mq_open (name, O_RDWR);
307 if (q2 == (mqd_t) -1)
309 printf ("mq_open in child failed with: %m\n");
310 result = 1;
313 (void) pthread_barrier_wait (b2);
315 /* Parent mq_open's another mqd_t for the same queue (q3). */
317 memset (&ev, 0x11, sizeof (ev));
318 ev.sigev_notify = SIGEV_SIGNAL;
319 ev.sigev_signo = SIGRTMIN;
320 ev.sigev_value.sival_ptr = &ev;
321 if (mq_notify (q2, &ev) != 0)
323 printf ("mq_notify in child (q2, { SIGEV_SIGNAL }) failed with: %m\n");
324 result = 1;
327 (void) pthread_barrier_wait (b2);
329 /* Parent unsuccessfully attempts to mq_notify { SIGEV_NONE } on q. */
331 (void) pthread_barrier_wait (b2);
333 if (mq_close (q2) != 0)
335 printf ("mq_close failed: %m\n");
336 result = 1;
339 (void) pthread_barrier_wait (b2);
341 /* Parent successfully calls mq_notify { SIGEV_NONE } on q3. */
343 (void) pthread_barrier_wait (b2);
345 memset (&ev, 0xbb, sizeof (ev));
346 ev.sigev_notify = SIGEV_SIGNAL;
347 ev.sigev_signo = SIGRTMIN;
348 ev.sigev_value.sival_ptr = &b2;
349 if (mq_notify (q, &ev) == 0)
351 puts ("third mq_notify in child (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
352 result = 1;
354 else if (errno != EBUSY)
356 printf ("third mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
357 result = 1;
360 (void) pthread_barrier_wait (b2);
362 /* Parent calls mq_close on q3, which makes the queue available again for
363 notification. */
365 (void) pthread_barrier_wait (b2);
367 memset (&ev, 0x13, sizeof (ev));
368 ev.sigev_notify = SIGEV_NONE;
369 if (mq_notify (q, &ev) != 0)
371 printf ("mq_notify in child (q, { SIGEV_NONE }) failed with: %m\n");
372 result = 1;
375 if (mq_notify (q, NULL) != 0)
377 printf ("mq_notify in child (q, NULL) failed with: %m\n");
378 result = 1;
381 (void) pthread_barrier_wait (b2);
383 struct thr_data thr_data = { .name = name, .b3 = b3, .q = q };
384 pthread_t th;
385 int ret = pthread_create (&th, NULL, thr, &thr_data);
386 if (ret)
388 errno = ret;
389 printf ("pthread_created failed with: %m\n");
390 result = 1;
393 /* Wait till thr calls mq_receive on the empty queue q and blocks on it. */
394 sleep (1);
396 memset (&ev, 0x5f, sizeof (ev));
397 ev.sigev_notify = SIGEV_SIGNAL;
398 ev.sigev_signo = SIGRTMIN;
399 ev.sigev_value.sival_int = 0xdeadbeef;
400 if (mq_notify (q, &ev) != 0)
402 printf ("fourth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
403 result = 1;
406 /* Ensure the thr thread gets the signal, not us. */
407 sigset_t set;
408 sigemptyset (&set);
409 sigaddset (&set, SIGRTMIN);
410 if (pthread_sigmask (SIG_BLOCK, &set, NULL))
412 printf ("Failed to block SIGRTMIN in child: %m\n");
413 result = 1;
416 (void) pthread_barrier_wait (b2);
418 /* Parent calls mqsend (q), which should wake up mqrecv (q)
419 in the thread but no notification should be sent. */
421 (void) pthread_barrier_wait (b3);
423 if (rtmin_cnt != 1)
425 puts ("SIGRTMIN signal caught while thr was blocked on mq_receive");
426 result = 1;
429 (void) pthread_barrier_wait (b3);
431 /* Parent calls mqsend (q), which should trigger notification. */
433 (void) pthread_barrier_wait (b3);
435 /* Thread verifies SIGRTMIN has been received. */
436 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
437 available for registration. */
438 /* Thread calls mq_notify (q, NULL). */
440 (void) pthread_barrier_wait (b3);
442 memset (&ev, 0x6a, sizeof (ev));
443 ev.sigev_notify = SIGEV_SIGNAL;
444 ev.sigev_signo = SIGRTMIN;
445 ev.sigev_value.sival_ptr = do_child;
446 if (mq_notify (q, &ev) != 0)
448 printf ("fifth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
449 result = 1;
452 (void) pthread_barrier_wait (b3);
454 /* Thread calls mq_notify (q, NULL), which should unregister the above
455 notification. */
457 (void) pthread_barrier_wait (b3);
459 /* Parent calls mqsend (q), which should not trigger notification. */
461 (void) pthread_barrier_wait (b3);
463 if (rtmin_cnt != 2)
465 puts ("SIGRTMIN signal caught while notification has been disabled");
466 result = 1;
469 memset (&ev, 0x7b, sizeof (ev));
470 ev.sigev_notify = SIGEV_SIGNAL;
471 ev.sigev_signo = SIGRTMIN;
472 ev.sigev_value.sival_ptr = thr;
473 if (mq_notify (q, &ev) != 0)
475 printf ("sixth mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
476 result = 1;
479 (void) pthread_barrier_wait (b3);
481 /* Thread opens a new O_RDONLY mqd_t (q4). */
482 /* Thread calls mq_notify (q4, NULL), which should unregister the above
483 notification. */
484 /* Thread calls mq_close (q4). */
486 (void) pthread_barrier_wait (b3);
488 /* Parent calls mqsend (q), which should not trigger notification. */
490 (void) pthread_barrier_wait (b3);
492 if (rtmin_cnt != 2)
494 puts ("SIGRTMIN signal caught while notification has been disabled");
495 result = 1;
498 memset (&ev, 0xe1, sizeof (ev));
499 ev.sigev_notify = SIGEV_SIGNAL;
500 ev.sigev_signo = SIGRTMIN;
501 ev.sigev_value.sival_int = 127;
502 if (mq_notify (q, &ev) != 0)
504 printf ("seventh mq_notify in child (q, { SIGEV_SIGNAL }) failed with: %m\n");
505 result = 1;
508 (void) pthread_barrier_wait (b3);
510 /* Thread opens a new O_WRONLY mqd_t (q5). */
511 /* Thread calls mq_notify (q5, NULL), which should unregister the above
512 notification. */
513 /* Thread calls mq_close (q5). */
515 (void) pthread_barrier_wait (b3);
517 /* Parent calls mqsend (q), which should not trigger notification. */
519 (void) pthread_barrier_wait (b3);
521 if (rtmin_cnt != 2)
523 puts ("SIGRTMIN signal caught while notification has been disabled");
524 result = 1;
527 /* Reenable test signals before cleaning up the thread. */
528 if (pthread_sigmask (SIG_UNBLOCK, &set, NULL))
530 printf ("Failed to unblock SIGRTMIN in child: %m\n");
531 result = 1;
534 void *thr_ret;
535 ret = pthread_join (th, &thr_ret);
536 if (ret)
538 errno = ret;
539 printf ("pthread_join failed: %m\n");
540 result = 1;
542 else if (thr_ret)
543 result = 1;
545 if (mq_close (q) != 0)
547 printf ("mq_close failed: %m\n");
548 result = 1;
551 exit (result);
554 #define TEST_FUNCTION do_test ()
555 static int
556 do_test (void)
558 int result = 0;
560 char tmpfname[] = "/tmp/tst-mqueue5-barrier.XXXXXX";
561 int fd = mkstemp (tmpfname);
562 if (fd == -1)
564 printf ("cannot open temporary file: %m\n");
565 return 1;
568 /* Make sure it is always removed. */
569 unlink (tmpfname);
571 /* Create one page of data. */
572 size_t ps = sysconf (_SC_PAGESIZE);
573 char data[ps];
574 memset (data, '\0', ps);
576 /* Write the data to the file. */
577 if (write (fd, data, ps) != (ssize_t) ps)
579 puts ("short write");
580 return 1;
583 void *mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
584 if (mem == MAP_FAILED)
586 printf ("mmap failed: %m\n");
587 return 1;
590 pthread_barrier_t *b2;
591 b2 = (pthread_barrier_t *) (((uintptr_t) mem + __alignof (pthread_barrier_t))
592 & ~(__alignof (pthread_barrier_t) - 1));
594 pthread_barrier_t *b3;
595 b3 = b2 + 1;
597 pthread_barrierattr_t a;
598 if (pthread_barrierattr_init (&a) != 0)
600 puts ("barrierattr_init failed");
601 return 1;
604 if (pthread_barrierattr_setpshared (&a, PTHREAD_PROCESS_SHARED) != 0)
606 puts ("barrierattr_setpshared failed, could not test");
607 return 0;
610 if (pthread_barrier_init (b2, &a, 2) != 0)
612 puts ("barrier_init failed");
613 return 1;
616 if (pthread_barrier_init (b3, &a, 3) != 0)
618 puts ("barrier_init failed");
619 return 1;
622 if (pthread_barrierattr_destroy (&a) != 0)
624 puts ("barrierattr_destroy failed");
625 return 1;
628 char name[sizeof "/tst-mqueue5-" + sizeof (pid_t) * 3];
629 snprintf (name, sizeof (name), "/tst-mqueue5-%u", getpid ());
631 struct mq_attr attr = { .mq_maxmsg = 1, .mq_msgsize = 1 };
632 mqd_t q = mq_open (name, O_CREAT | O_EXCL | O_RDWR, 0600, &attr);
634 if (q == (mqd_t) -1)
636 printf ("mq_open failed with: %m\n");
637 return result;
639 else
640 add_temp_mq (name);
642 struct sigevent ev;
643 memset (&ev, 0xaa, sizeof (ev));
644 ev.sigev_notify = SIGEV_NONE;
645 if (mq_notify (q, &ev) != 0)
647 printf ("mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
648 result = 1;
651 if (mq_notify (q, &ev) == 0)
653 puts ("second mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
654 result = 1;
656 else if (errno != EBUSY)
658 printf ("second mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
659 result = 1;
662 result |= mqsend (q);
664 if (mq_notify (q, &ev) != 0)
666 printf ("third mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
667 result = 1;
670 result |= mqrecv (q);
672 if (mq_notify (q, NULL) != 0)
674 printf ("mq_notify (q, NULL) failed with: %m\n");
675 result = 1;
678 if (mq_notify (q, NULL) != 0)
680 /* Implementation-defined behaviour, so don't fail,
681 just inform. */
682 printf ("second mq_notify (q, NULL) failed with: %m\n");
685 struct sigaction sa = { .sa_sigaction = rtmin_handler,
686 .sa_flags = SA_SIGINFO };
687 sigemptyset (&sa.sa_mask);
688 sigaction (SIGRTMIN, &sa, NULL);
690 memset (&ev, 0x55, sizeof (ev));
691 ev.sigev_notify = SIGEV_SIGNAL;
692 ev.sigev_signo = SIGRTMIN;
693 ev.sigev_value.sival_int = 26;
694 if (mq_notify (q, &ev) != 0)
696 printf ("mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
697 result = 1;
700 ev.sigev_value.sival_ptr = &ev;
701 if (mq_notify (q, &ev) == 0)
703 puts ("second mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
704 result = 1;
706 else if (errno != EBUSY)
708 printf ("second mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
709 result = 1;
712 if (rtmin_cnt != 0)
714 puts ("SIGRTMIN signal caught too early");
715 result = 1;
718 result |= mqsend (q);
720 if (rtmin_cnt != 1)
722 puts ("SIGRTMIN signal did not arrive");
723 result = 1;
725 else if (rtmin_pid != getpid ()
726 || rtmin_uid != getuid ()
727 || rtmin_code != SI_MESGQ
728 || rtmin_sigval.sival_int != 26)
730 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (26)\n",
731 rtmin_pid, getpid (), rtmin_uid, getuid (),
732 rtmin_code, SI_MESGQ, rtmin_sigval.sival_int);
733 result = 1;
736 ev.sigev_value.sival_int = 75;
737 if (mq_notify (q, &ev) != 0)
739 printf ("third mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
740 result = 1;
743 result |= mqrecv (q);
745 if (mq_notify (q, NULL) != 0)
747 printf ("mq_notify (q, NULL) failed with: %m\n");
748 result = 1;
751 memset (&ev, 0x33, sizeof (ev));
752 ev.sigev_notify = SIGEV_NONE;
753 if (mq_notify (q, &ev) != 0)
755 printf ("fourth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
756 result = 1;
759 pid_t pid = fork ();
760 if (pid == -1)
762 printf ("fork () failed: %m\n");
763 mq_unlink (name);
764 return 1;
767 if (pid == 0)
768 do_child (name, b2, b3, q);
770 /* Child unsuccessfully attempts to mq_notify. */
772 (void) pthread_barrier_wait (b2);
774 result |= mqsend (q);
776 (void) pthread_barrier_wait (b2);
778 /* Child successfully calls mq_notify SIGEV_SIGNAL now. */
780 result |= mqrecv (q);
782 (void) pthread_barrier_wait (b2);
784 memset (&ev, 0xbb, sizeof (ev));
785 ev.sigev_notify = SIGEV_SIGNAL;
786 ev.sigev_signo = SIGRTMIN;
787 ev.sigev_value.sival_int = 15;
788 if (mq_notify (q, &ev) == 0)
790 puts ("fourth mq_notify (q, { SIGEV_SIGNAL }) unexpectedly succeeded");
791 result = 1;
793 else if (errno != EBUSY)
795 printf ("fourth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
796 result = 1;
799 result |= mqsend (q);
801 if (mq_notify (q, &ev) != 0)
803 printf ("fifth mq_notify (q, { SIGEV_SIGNAL }) failed with: %m\n");
804 result = 1;
807 if (rtmin_cnt != 1)
809 puts ("SIGRTMIN signal caught too early");
810 result = 1;
813 result |= mqrecv (q);
815 (void) pthread_barrier_wait (b2);
817 /* Child verifies caught SIGRTMIN signal. */
818 /* Child calls mq_send (q) which triggers SIGRTMIN signal here. */
820 (void) pthread_barrier_wait (b2);
822 /* Child mq_open's another mqd_t for the same queue (q2). */
824 if (rtmin_cnt != 2)
826 puts ("SIGRTMIN signal did not arrive");
827 result = 1;
829 else if (rtmin_pid != pid
830 || rtmin_uid != getuid ()
831 || rtmin_code != SI_MESGQ
832 || rtmin_sigval.sival_int != 15)
834 printf ("unexpected siginfo_t fields: pid %u (%u), uid %u (%u), code %d (%d), si_int %d (15)\n",
835 rtmin_pid, pid, rtmin_uid, getuid (),
836 rtmin_code, SI_MESGQ, rtmin_sigval.sival_int);
837 result = 1;
840 result |= mqrecv (q);
842 (void) pthread_barrier_wait (b2);
844 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q2. */
846 (void) pthread_barrier_wait (b2);
848 memset (&ev, 0xbb, sizeof (ev));
849 ev.sigev_notify = SIGEV_NONE;
850 if (mq_notify (q, &ev) == 0)
852 puts ("fifth mq_notify (q, { SIGEV_NONE }) unexpectedly succeeded");
853 result = 1;
855 else if (errno != EBUSY)
857 printf ("fifth mq_notify (q, { SIGEV_NONE }) failed with: %m\n");
858 result = 1;
861 (void) pthread_barrier_wait (b2);
863 /* Child calls mq_close on q2, which makes the queue available again for
864 notification. */
866 mqd_t q3 = mq_open (name, O_RDWR);
867 if (q3 == (mqd_t) -1)
869 printf ("mq_open q3 in parent failed with: %m\n");
870 result = 1;
873 (void) pthread_barrier_wait (b2);
875 memset (&ev, 0x12, sizeof (ev));
876 ev.sigev_notify = SIGEV_NONE;
877 if (mq_notify (q3, &ev) != 0)
879 printf ("mq_notify (q3, { SIGEV_NONE }) failed with: %m\n");
880 result = 1;
883 (void) pthread_barrier_wait (b2);
885 /* Child unsuccessfully attempts to mq_notify { SIGEV_SIGNAL } on q. */
887 (void) pthread_barrier_wait (b2);
889 if (mq_close (q3) != 0)
891 printf ("mq_close failed: %m\n");
892 result = 1;
895 (void) pthread_barrier_wait (b2);
897 /* Child successfully calls mq_notify { SIGEV_NONE } on q. */
898 /* Child successfully calls mq_notify NULL on q. */
900 (void) pthread_barrier_wait (b2);
902 /* Child creates new thread. */
903 /* Thread blocks on mqrecv (q). */
904 /* Child sleeps for 1sec so that thread has time to reach that point. */
905 /* Child successfully calls mq_notify { SIGEV_SIGNAL } on q. */
907 (void) pthread_barrier_wait (b2);
909 result |= mqsend (q);
911 (void) pthread_barrier_wait (b3);
913 /* Child verifies SIGRTMIN has not been sent. */
915 (void) pthread_barrier_wait (b3);
917 result |= mqsend (q);
919 (void) pthread_barrier_wait (b3);
921 /* Thread verifies SIGRTMIN has been caught. */
922 /* Thread calls mq_notify (q, { SIGEV_NONE }) to verify notification is now
923 available for registration. */
924 /* Thread calls mq_notify (q, NULL). */
926 (void) pthread_barrier_wait (b3);
928 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
930 (void) pthread_barrier_wait (b3);
932 /* Thread calls mq_notify (q, NULL). */
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_RDONLY mqd_t (q4). */
947 /* Thread calls mq_notify (q4, NULL). */
948 /* Thread calls mq_close (q4). */
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. */
958 /* Child calls mq_notify (q, { SIGEV_SIGNAL }). */
960 (void) pthread_barrier_wait (b3);
962 /* Thread opens a new O_WRONLY mqd_t (q5). */
963 /* Thread calls mq_notify (q5, NULL). */
964 /* Thread calls mq_close (q5). */
966 (void) pthread_barrier_wait (b3);
968 result |= mqsend (q);
969 result |= mqrecv (q);
971 (void) pthread_barrier_wait (b3);
973 /* Child verifies SIGRTMIN has not been sent. */
975 int status;
976 if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
978 puts ("waitpid failed");
979 kill (pid, SIGKILL);
980 result = 1;
982 else if (!WIFEXITED (status) || WEXITSTATUS (status))
984 printf ("child failed with status %d\n", status);
985 result = 1;
988 if (mq_unlink (name) != 0)
990 printf ("mq_unlink failed: %m\n");
991 result = 1;
994 if (mq_close (q) != 0)
996 printf ("mq_close failed: %m\n");
997 result = 1;
1000 if (mq_notify (q, NULL) == 0)
1002 puts ("mq_notify on closed mqd_t unexpectedly succeeded");
1003 result = 1;
1005 else if (errno != EBADF)
1007 printf ("mq_notify on closed mqd_t did not fail with EBADF: %m\n");
1008 result = 1;
1011 memset (&ev, 0x55, sizeof (ev));
1012 ev.sigev_notify = SIGEV_NONE;
1013 if (mq_notify (q, &ev) == 0)
1015 puts ("mq_notify on closed mqd_t unexpectedly succeeded");
1016 result = 1;
1018 else if (errno != EBADF)
1020 printf ("mq_notify on closed mqd_t did not fail with EBADF: %m\n");
1021 result = 1;
1024 return result;
1026 #else
1027 # define TEST_FUNCTION 0
1028 #endif
1030 #include "../test-skeleton.c"