THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7KB

  1. #ifndef SIGCHAIN_H
  2. #define SIGCHAIN_H
  3. /**
  4. * Code often wants to set a signal handler to clean up temporary files or
  5. * other work-in-progress when we die unexpectedly. For multiple pieces of
  6. * code to do this without conflicting, each piece of code must remember
  7. * the old value of the handler and restore it either when:
  8. *
  9. * 1. The work-in-progress is finished, and the handler is no longer
  10. * necessary. The handler should revert to the original behavior
  11. * (either another handler, SIG_DFL, or SIG_IGN).
  12. *
  13. * 2. The signal is received. We should then do our cleanup, then chain
  14. * to the next handler (or die if it is SIG_DFL).
  15. *
  16. * Sigchain is a tiny library for keeping a stack of handlers. Your handler
  17. * and installation code should look something like:
  18. *
  19. * ------------------------------------------
  20. * void clean_foo_on_signal(int sig)
  21. * {
  22. * clean_foo();
  23. * sigchain_pop(sig);
  24. * raise(sig);
  25. * }
  26. *
  27. * void other_func()
  28. * {
  29. * sigchain_push_common(clean_foo_on_signal);
  30. * mess_up_foo();
  31. * clean_foo();
  32. * }
  33. * ------------------------------------------
  34. *
  35. */
  36. /**
  37. * Handlers are given the typedef of sigchain_fun. This is the same type
  38. * that is given to signal() or sigaction(). It is perfectly reasonable to
  39. * push SIG_DFL or SIG_IGN onto the stack.
  40. */
  41. typedef void (*sigchain_fun)(int);
  42. /* You can sigchain_push and sigchain_pop individual signals. */
  43. int sigchain_push(int sig, sigchain_fun f);
  44. int sigchain_pop(int sig);
  45. /**
  46. * push the handler onto the stack for the common signals:
  47. * SIGINT, SIGHUP, SIGTERM, SIGQUIT and SIGPIPE.
  48. */
  49. void sigchain_push_common(sigchain_fun f);
  50. void sigchain_pop_common(void);
  51. #endif /* SIGCHAIN_H */