signal.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * signal testing function for uClibc
  4. *
  5. * Copyright (C) 2000 by Lineo, inc. Written by Erik Andersen
  6. * <andersen@lineo.com>, <andersee@debian.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU Library General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <errno.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <strings.h>
  28. #include <fcntl.h>
  29. #include <signal.h>
  30. /* -------------------------------------------------*/
  31. /* This stuff is common to all the testing routines */
  32. /* -------------------------------------------------*/
  33. const char *it = "<UNSET>"; /* Routine name for message routines. */
  34. size_t errors = 0;
  35. void check(int thing, int number)
  36. {
  37. if (!thing) {
  38. printf("%s: flunked test %d\n", it, number);
  39. ++errors;
  40. }
  41. }
  42. void equal(const char *a, const char *b, int number)
  43. {
  44. check(a != NULL && b != NULL && (strcmp(a, b) == 0), number);
  45. }
  46. /* -------------------------------------------------*/
  47. /* Let the tests begin.... */
  48. /* -------------------------------------------------*/
  49. int global_int = 0;
  50. void set_global_int_to_one(int signum)
  51. {
  52. printf ("Received signal %d (%s).\n", signum, strsignal(signum));
  53. global_int = 1;
  54. return;
  55. }
  56. void signal_test_1(void)
  57. {
  58. global_int = 0;
  59. it = "global variable set from signal handler";
  60. signal(SIGUSR1, set_global_int_to_one);
  61. raise(SIGUSR1);
  62. /* This should already have jumped to the signal handler */
  63. check((global_int == 1), 1);
  64. global_int = 0;
  65. signal(SIGUSR1, SIG_IGN);
  66. raise(SIGUSR1);
  67. /* This should not go to the signal handler this time since we */
  68. check((global_int == 0), 1);
  69. }
  70. int main(void)
  71. {
  72. int status;
  73. signal_test_1();
  74. if (errors == 0) {
  75. status = EXIT_SUCCESS;
  76. printf("No errors.\n");
  77. } else {
  78. status = EXIT_FAILURE;
  79. printf("%d errors.\n", errors);
  80. }
  81. exit(status);
  82. }