Commit Graph

4 Commits (master)

Author SHA1 Message Date
Heba Waly c0be43f898 sigchain: move doc to sigchain.h
Move the documentation from Documentation/technical/api-sigchain.txt
to sigchain.h as it's easier for the developers to find the usage
information beside the code instead of looking for it in another doc file.

Also documentation/technical/api-sigchain.txt is removed because the
information it has is now redundant and it'll be hard to keep it up to
date and synchronized with the documentation in the header file.

Signed-off-by: Heba Waly <>
Signed-off-by: Junio C Hamano <>
2019-11-18 15:21:29 +09:00
Stefan Beller bfb6b53c05 sigchain: add command to pop all common signals
The new method removes all common signal handlers that were installed
by sigchain_push.

CC: Jeff King <>
Signed-off-by: Stefan Beller <>
Signed-off-by: Junio C Hamano <>
2015-12-16 12:06:08 -08:00
Jeff King 57b235a4bc refactor signal handling for cleanup functions
The current code is very inconsistent about which signals
are caught for doing cleanup of temporary files and lock
files. Some callsites checked only SIGINT, while others
checked a variety of death-dealing signals.

This patch factors out those signals to a single function,
and then calls it everywhere. For some sites, that means
this is a simple clean up. For others, it is an improvement
in that they will now properly clean themselves up after a
larger variety of signals.

Signed-off-by: Jeff King <>
Signed-off-by: Junio C Hamano <>
2009-01-21 22:46:53 -08:00
Jeff King 4a16d07272 chain kill signals for cleanup functions
If a piece of code wanted to do some cleanup before exiting
(e.g., cleaning up a lockfile or a tempfile), our usual
strategy was to install a signal handler that did something
like this:

  do_cleanup(); /* actual work */
  signal(signo, SIG_DFL); /* restore previous behavior */
  raise(signo); /* deliver signal, killing ourselves */

For a single handler, this works fine. However, if we want
to clean up two _different_ things, we run into a problem.
The most recently installed handler will run, but when it
removes itself as a handler, it doesn't put back the first

This patch introduces sigchain, a tiny library for handling
a stack of signal handlers. You sigchain_push each handler,
and use sigchain_pop to restore whoever was before you in
the stack.

Signed-off-by: Jeff King <>
Signed-off-by: Junio C Hamano <>
2009-01-21 22:46:52 -08:00