tst-signal5.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <errno.h>
  17. #include <pthread.h>
  18. #include <signal.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <unistd.h>
  23. #include <sys/mman.h>
  24. #include <sys/wait.h>
  25. static sigset_t ss;
  26. static void *
  27. tf (void *arg)
  28. {
  29. sigset_t ss2;
  30. if (pthread_sigmask (SIG_SETMASK, NULL, &ss2) != 0)
  31. {
  32. puts ("child: sigmask failed");
  33. exit (1);
  34. }
  35. int i;
  36. for (i = 1; i < 32; ++i)
  37. if (sigismember (&ss, i) && ! sigismember (&ss2, i))
  38. {
  39. printf ("signal %d set in parent mask, but not in child\n", i);
  40. exit (1);
  41. }
  42. else if (! sigismember (&ss, i) && sigismember (&ss2, i))
  43. {
  44. printf ("signal %d set in child mask, but not in parent\n", i);
  45. exit (1);
  46. }
  47. return NULL;
  48. }
  49. static int
  50. do_test (void)
  51. {
  52. sigemptyset (&ss);
  53. sigaddset (&ss, SIGUSR1);
  54. if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
  55. {
  56. puts ("1st sigmask failed");
  57. exit (1);
  58. }
  59. pthread_t th;
  60. if (pthread_create (&th, NULL, tf, NULL) != 0)
  61. {
  62. puts ("1st create failed");
  63. exit (1);
  64. }
  65. void *r;
  66. if (pthread_join (th, &r) != 0)
  67. {
  68. puts ("1st join failed");
  69. exit (1);
  70. }
  71. sigemptyset (&ss);
  72. sigaddset (&ss, SIGUSR2);
  73. sigaddset (&ss, SIGFPE);
  74. if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
  75. {
  76. puts ("2nd sigmask failed");
  77. exit (1);
  78. }
  79. if (pthread_create (&th, NULL, tf, NULL) != 0)
  80. {
  81. puts ("2nd create failed");
  82. exit (1);
  83. }
  84. if (pthread_join (th, &r) != 0)
  85. {
  86. puts ("2nd join failed");
  87. exit (1);
  88. }
  89. return 0;
  90. }
  91. #define TEST_FUNCTION do_test ()
  92. #include "../test-skeleton.c"