tst-timer-sigmask.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Check resulting signal mask from POSIX timer using SIGEV_THREAD.
  2. Copyright (C) 2020-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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. <https://www.gnu.org/licenses/>. */
  15. #include <stdio.h>
  16. #include <time.h>
  17. #include <signal.h>
  18. #include <stdbool.h>
  19. #include <support/check.h>
  20. #include <support/test-driver.h>
  21. #include <support/xthread.h>
  22. #include <internal-signals.h>
  23. static pthread_barrier_t barrier;
  24. static void
  25. thread_handler (union sigval sv)
  26. {
  27. sigset_t ss;
  28. sigprocmask (SIG_BLOCK, NULL, &ss);
  29. if (test_verbose > 0)
  30. printf ("%s: blocked signal mask = { ", __func__);
  31. for (int sig = 1; sig < NSIG; sig++)
  32. {
  33. /* POSIX timers threads created to handle SIGEV_THREAD block all
  34. signals except SIGKILL, SIGSTOP and glibc internals ones. */
  35. if (sigismember (&ss, sig))
  36. {
  37. TEST_VERIFY (sig != SIGKILL && sig != SIGSTOP);
  38. TEST_VERIFY (!is_internal_signal (sig));
  39. }
  40. if (test_verbose && sigismember (&ss, sig))
  41. printf ("%d, ", sig);
  42. }
  43. if (test_verbose > 0)
  44. printf ("}\n");
  45. xpthread_barrier_wait (&barrier);
  46. }
  47. static int
  48. do_test (void)
  49. {
  50. struct sigevent sev = { };
  51. sev.sigev_notify = SIGEV_THREAD;
  52. sev.sigev_notify_function = &thread_handler;
  53. timer_t timerid;
  54. TEST_COMPARE (timer_create (CLOCK_REALTIME, &sev, &timerid), 0);
  55. xpthread_barrier_init (&barrier, NULL, 2);
  56. struct itimerspec trigger = { };
  57. trigger.it_value.tv_nsec = 1000000;
  58. TEST_COMPARE (timer_settime (timerid, 0, &trigger, NULL), 0);
  59. xpthread_barrier_wait (&barrier);
  60. return 0;
  61. }
  62. #include <support/test-driver.c>