From: Jeff King <peff@peff.net>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Daniel Barkalow <barkalow@iabervon.org>,
Nguyen Thai Ngoc Duy <pclouds@gmail.com>,
Dun Peal <dunpealer@gmail.com>, Git ML <git@vger.kernel.org>,
Stefan Naewe <stefan.naewe@atlas-elektronik.com>,
Carl Worth <cworth@cworth.org>
Subject: Re: Scripted clone generating an incomplete, unusable .git/config
Date: Thu, 11 Nov 2010 23:24:56 -0500 [thread overview]
Message-ID: <20101112042455.GA20555@sigill.intra.peff.net> (raw)
In-Reply-To: <20101112021602.GA10765@burratino>
On Thu, Nov 11, 2010 at 08:16:02PM -0600, Jonathan Nieder wrote:
> > I don't think your patch is the right solution, but FWIW, sigchain was
> > explicitly intended to be able to take SIG_DFL and SIG_IGN. Probably
> > sigchain_fun should be removed and we should just use sighandler_t
> > explicitly
>
> Sorry, that was lazy of me. The name sighandler_t is a GNU extension[1].
Ah, you're right. ANSI C defines signal() without using a typedef at
all. Maybe that is why I didn't use it in the first place. I don't
recall.
> The following addresses my confusion but I doubt it's worth the
> syntactic ugliness.
>
> -- 8< --
> Subject: sigchain: hide sigchain_fun type
I think it makes the code uglier. Maybe this is a better solution:
-- >8 --
Subject: [PATCH] document sigchain api
It's pretty straightforward, but a stripped-down example
never hurts. And we should make clear that it is explicitly
OK to use SIG_DFL and SIG_IGN.
Signed-off-by: Jeff King <peff@peff.net>
---
Documentation/technical/api-sigchain.txt | 41 ++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)
create mode 100644 Documentation/technical/api-sigchain.txt
diff --git a/Documentation/technical/api-sigchain.txt b/Documentation/technical/api-sigchain.txt
new file mode 100644
index 0000000..535cdff
--- /dev/null
+++ b/Documentation/technical/api-sigchain.txt
@@ -0,0 +1,41 @@
+sigchain API
+============
+
+Code often wants to set a signal handler to clean up temporary files or
+other work-in-progress when we die unexpectedly. For multiple pieces of
+code to do this without conflicting, each piece of code must remember
+the old value of the handler and restore it either when:
+
+ 1. The work-in-progress is finished, and the handler is no longer
+ necessary. The handler should revert to the original behavior
+ (either another handler, SIG_DFL, or SIG_IGN).
+
+ 2. The signal is received. We should then do our cleanup, then chain
+ to the next handler (or die if it is SIG_DFL).
+
+Sigchain is a tiny library for keeping a stack of handlers. Your handler
+and installation code should look something like:
+
+------------------------------------------
+ void clean_foo_on_signal(int sig)
+ {
+ clean_foo();
+ sigchain_pop(sig);
+ raise(sig);
+ }
+
+ void other_func()
+ {
+ sigchain_push_common(clean_foo_on_signal);
+ mess_up_foo();
+ clean_foo();
+ }
+------------------------------------------
+
+Handlers are given the typdef of sigchain_fun. This is the same type
+that is given to signal() or sigaction(). It is perfectly reasonable to
+push SIG_DFL or SIG_IGN onto the stack.
+
+You can sigchain_push and sigchain_pop individual signals. For
+convenience, sigchain_push_common will push the handler onto the stack
+for many common signals.
--
1.7.3.2.362.g0e229.dirty
next prev parent reply other threads:[~2010-11-12 4:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-10 23:21 Scripted clone generating an incomplete, unusable .git/config Dun Peal
2010-11-11 7:55 ` Stefan Naewe
2010-11-11 8:00 ` Stefan Naewe
2010-11-11 10:37 ` Jonathan Nieder
2010-11-11 12:16 ` Nguyen Thai Ngoc Duy
2010-11-11 17:32 ` Jonathan Nieder
2010-11-11 17:55 ` Daniel Barkalow
2010-11-11 18:48 ` Jonathan Nieder
2010-11-11 19:05 ` Jeff King
2010-11-12 2:16 ` Jonathan Nieder
2010-11-12 4:24 ` Jeff King [this message]
2010-11-12 4:35 ` Jonathan Nieder
2010-11-12 4:32 ` Jonathan Nieder
2010-11-12 4:41 ` Jeff King
2010-11-12 5:18 ` Jonathan Nieder
2010-11-12 5:12 ` [RFC/PATCH] daemon, tag, verify-tag: do not pass ignored signals to child (Re: Scripted clone generating an incomplete, unusable .git/config) Jonathan Nieder
2010-11-11 17:39 ` Scripted clone generating an incomplete, unusable .git/config Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101112042455.GA20555@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=barkalow@iabervon.org \
--cc=cworth@cworth.org \
--cc=dunpealer@gmail.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=pclouds@gmail.com \
--cc=stefan.naewe@atlas-elektronik.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).