tst-raise1.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@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 <error.h>
  17. #include <signal.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. volatile int count;
  21. void
  22. sh (int sig)
  23. {
  24. ++count;
  25. }
  26. int
  27. main (void)
  28. {
  29. struct sigaction sa;
  30. sa.sa_handler = sh;
  31. sigemptyset (&sa.sa_mask);
  32. sa.sa_flags = 0;
  33. if (sigaction (SIGUSR1, &sa, NULL) < 0)
  34. {
  35. printf ("sigaction failed: %m\n");
  36. exit (1);
  37. }
  38. if (raise (SIGUSR1) < 0)
  39. {
  40. printf ("first raise failed: %m\n");
  41. exit (1);
  42. }
  43. if (raise (SIGUSR1) < 0)
  44. {
  45. printf ("second raise failed: %m\n");
  46. exit (1);
  47. }
  48. if (count != 2)
  49. {
  50. printf ("signal handler not called 2 times\n");
  51. exit (1);
  52. }
  53. exit (0);
  54. }