From: Jeremiah Mahler <jmmahler@gmail.com>
To: Chris Packham <judge.packham@gmail.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
git@vger.kernel.org, Jeremiah Mahler <jmmahler@gmail.com>
Subject: [PATCH v3 9/9] sigchain.c: replace signal() with sigaction()
Date: Sun, 1 Jun 2014 11:10:18 -0700 [thread overview]
Message-ID: <06d9d4d29fc7ada8d6f4f3f1f1e3e2a764ba7c67.1401645403.git.jmmahler@gmail.com> (raw)
In-Reply-To: <cover.1401645403.git.jmmahler@gmail.com>
In-Reply-To: <cover.1401645403.git.jmmahler@gmail.com>
From the signal(2) man page:
The behavior of signal() varies across UNIX versions, and has also var‐
ied historically across different versions of Linux. Avoid its use:
use sigaction(2) instead.
Replaced signal() with sigaction() in sigchain.c
Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
sigchain.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/sigchain.c b/sigchain.c
index 1118b99..deab262 100644
--- a/sigchain.c
+++ b/sigchain.c
@@ -19,11 +19,16 @@ static void check_signum(int sig)
int sigchain_push(int sig, sigchain_fun f)
{
struct sigchain_signal *s = signals + sig;
+ struct sigaction sa, sa_old;
+ int result;
check_signum(sig);
ALLOC_GROW(s->old, s->n + 1, s->alloc);
- s->old[s->n] = signal(sig, f);
- if (s->old[s->n] == SIG_ERR)
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = f;
+ result = sigaction(sig, &sa, &sa_old);
+ s->old[s->n] = sa_old.sa_handler;
+ if (result == -1)
return -1;
s->n++;
return 0;
@@ -32,11 +37,14 @@ int sigchain_push(int sig, sigchain_fun f)
int sigchain_pop(int sig)
{
struct sigchain_signal *s = signals + sig;
+ struct sigaction sa, sa_old;
check_signum(sig);
if (s->n < 1)
return 0;
- if (signal(sig, s->old[s->n - 1]) == SIG_ERR)
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = s->old[s->n - 1];
+ if (sigaction(sig, &sa, &sa_old) == -1)
return -1;
s->n--;
return 0;
--
2.0.0.8.g7bf6e1f.dirty
next prev parent reply other threads:[~2014-06-01 18:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-01 18:10 [PATCH v3 0/9] replace signal() with sigaction() Jeremiah Mahler
2014-06-01 18:10 ` [PATCH v3 1/9] compat/mingw.c: expand MinGW support for sigaction Jeremiah Mahler
2014-06-02 5:57 ` Johannes Sixt
2014-06-01 18:10 ` [PATCH v3 2/9] connect.c: replace signal() with sigaction() Jeremiah Mahler
2014-06-01 18:10 ` [PATCH v3 3/9] progress.c: " Jeremiah Mahler
2014-06-01 18:10 ` [PATCH v3 4/9] write_or_die.c: " Jeremiah Mahler
2014-06-01 18:10 ` [PATCH v3 5/9] daemon.c: " Jeremiah Mahler
2014-06-01 18:10 ` [PATCH v3 6/9] builtin/log.c: " Jeremiah Mahler
2014-06-01 18:10 ` [PATCH v3 7/9] builtin/merge-index.c: " Jeremiah Mahler
2014-06-01 18:10 ` [PATCH v3 8/9] builtin/verify-tag.c: " Jeremiah Mahler
2014-06-01 18:10 ` Jeremiah Mahler [this message]
2014-06-02 11:28 ` [PATCH v3 0/9] " Johannes Sixt
2014-06-02 14:39 ` Jeremiah Mahler
2014-06-02 19:05 ` Junio C Hamano
2014-06-02 20:25 ` Jeremiah Mahler
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=06d9d4d29fc7ada8d6f4f3f1f1e3e2a764ba7c67.1401645403.git.jmmahler@gmail.com \
--to=jmmahler@gmail.com \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
--cc=judge.packham@gmail.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).