signal.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Tester for string functions.
  2. Copyright (C) 1995, 1996, 1997, 1998, 1999 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 Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. 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. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #include <errno.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <strings.h>
  21. #include <fcntl.h>
  22. #include <signal.h>
  23. /* -------------------------------------------------*/
  24. /* This stuff is common to all the testing routines */
  25. /* -------------------------------------------------*/
  26. const char *it = "<UNSET>"; /* Routine name for message routines. */
  27. size_t errors = 0;
  28. void check (int thing, int number)
  29. {
  30. if (!thing)
  31. {
  32. printf("%s flunked test %d\n", it, number);
  33. ++errors;
  34. }
  35. }
  36. void equal (const char *a, const char *b, int number)
  37. {
  38. check(a != NULL && b != NULL && (strcmp(a, b)==0), number);
  39. }
  40. /* -------------------------------------------------*/
  41. /* Let the tests begin.... */
  42. /* -------------------------------------------------*/
  43. int global_int = 0;
  44. void set_global_int_to_one(int signum)
  45. {
  46. printf("entering set_global_int_to_one\n");
  47. global_int = 1;
  48. return;
  49. }
  50. void
  51. signal_test_1 (void)
  52. {
  53. global_int = 0;
  54. signal(SIGUSR1, set_global_int_to_one);
  55. raise( SIGUSR1);
  56. /* This should have first jumped to the signal handler */
  57. check ( (global_int == 0), 0);
  58. signal(SIGUSR1, SIG_DFL);
  59. raise( SIGUSR1);
  60. printf("Here I am.\n");
  61. }
  62. int
  63. main (void)
  64. {
  65. int status;
  66. signal_test_1 ();
  67. if (errors == 0)
  68. {
  69. status = EXIT_SUCCESS;
  70. printf("No errors.\n");
  71. }
  72. else
  73. {
  74. status = EXIT_FAILURE;
  75. printf("%d errors.\n", errors);
  76. }
  77. exit(status);
  78. }