test-sig.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * This file is part of Quagga.
  3. *
  4. * Quagga is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2, or (at your option) any
  7. * later version.
  8. *
  9. * Quagga is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with Quagga; see the file COPYING. If not, write to the Free
  16. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  17. * 02111-1307, USA.
  18. */
  19. #include <zebra.h>
  20. #include <sigevent.h>
  21. #include "lib/log.h"
  22. #include "lib/memory.h"
  23. void
  24. sighup (void)
  25. {
  26. printf ("processed hup\n");
  27. }
  28. void
  29. sigusr1 (void)
  30. {
  31. printf ("processed usr1\n");
  32. }
  33. void
  34. sigusr2 (void)
  35. {
  36. printf ("processed usr2\n");
  37. }
  38. struct quagga_signal_t sigs[] =
  39. {
  40. {
  41. .signal = SIGHUP,
  42. .handler = &sighup,
  43. },
  44. {
  45. .signal = SIGUSR1,
  46. .handler = &sigusr1,
  47. },
  48. {
  49. .signal = SIGUSR2,
  50. .handler = &sigusr2,
  51. }
  52. };
  53. struct thread_master *master;
  54. struct thread t;
  55. int
  56. main (void)
  57. {
  58. master = thread_master_create ();
  59. signal_init (master, array_size(sigs), sigs);
  60. zlog_default = openzlog("testsig", ZLOG_NONE,
  61. LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
  62. zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
  63. zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG);
  64. zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
  65. while (thread_fetch (master, &t))
  66. thread_call (&t);
  67. exit (0);
  68. }