test-sig.c 948 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <zebra.h>
  2. #include <sigevent.h>
  3. #include "lib/log.h"
  4. void
  5. sighup (void)
  6. {
  7. printf ("processed hup\n");
  8. }
  9. void
  10. sigusr1 (void)
  11. {
  12. printf ("processed usr1\n");
  13. }
  14. void
  15. sigusr2 (void)
  16. {
  17. printf ("processed usr2\n");
  18. }
  19. struct quagga_signal_t sigs[] =
  20. {
  21. {
  22. .signal = SIGHUP,
  23. .handler = &sighup,
  24. },
  25. {
  26. .signal = SIGUSR1,
  27. .handler = &sigusr1,
  28. },
  29. {
  30. .signal = SIGUSR2,
  31. .handler = &sigusr2,
  32. }
  33. };
  34. struct thread_master *master;
  35. struct thread t;
  36. int
  37. main (void)
  38. {
  39. master = thread_master_create ();
  40. signal_init (master, Q_SIGC(sigs), sigs);
  41. zlog_default = openzlog("testsig", ZLOG_NONE,
  42. LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
  43. zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
  44. zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG);
  45. zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
  46. while (thread_fetch (master, &t))
  47. thread_call (&t);
  48. exit (0);
  49. }