tst-signal5.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <pthread.h>
  17. #include <signal.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <unistd.h>
  22. #include <sys/mman.h>
  23. #include <sys/wait.h>
  24. static sigset_t ss;
  25. static void *
  26. tf (void *arg)
  27. {
  28. sigset_t ss2;
  29. if (pthread_sigmask (SIG_SETMASK, NULL, &ss2) != 0)
  30. {
  31. puts ("child: sigmask failed");
  32. exit (1);
  33. }
  34. int i;
  35. for (i = 1; i < 32; ++i)
  36. if (sigismember (&ss, i) && ! sigismember (&ss2, i))
  37. {
  38. printf ("signal %d set in parent mask, but not in child\n", i);
  39. exit (1);
  40. }
  41. else if (! sigismember (&ss, i) && sigismember (&ss2, i))
  42. {
  43. printf ("signal %d set in child mask, but not in parent\n", i);
  44. exit (1);
  45. }
  46. return NULL;
  47. }
  48. static int
  49. do_test (void)
  50. {
  51. sigemptyset (&ss);
  52. sigaddset (&ss, SIGUSR1);
  53. if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
  54. {
  55. puts ("1st sigmask failed");
  56. exit (1);
  57. }
  58. pthread_t th;
  59. if (pthread_create (&th, NULL, tf, NULL) != 0)
  60. {
  61. puts ("1st create failed");
  62. exit (1);
  63. }
  64. void *r;
  65. if (pthread_join (th, &r) != 0)
  66. {
  67. puts ("1st join failed");
  68. exit (1);
  69. }
  70. sigemptyset (&ss);
  71. sigaddset (&ss, SIGUSR2);
  72. sigaddset (&ss, SIGFPE);
  73. if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
  74. {
  75. puts ("2nd sigmask failed");
  76. exit (1);
  77. }
  78. if (pthread_create (&th, NULL, tf, NULL) != 0)
  79. {
  80. puts ("2nd create failed");
  81. exit (1);
  82. }
  83. if (pthread_join (th, &r) != 0)
  84. {
  85. puts ("2nd join failed");
  86. exit (1);
  87. }
  88. return 0;
  89. }
  90. #define TEST_FUNCTION do_test ()
  91. #include "../test-skeleton.c"