git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 9/9] sigchain.c: replace signal() with sigaction()

From
Jeremiah Mahler <jmmahler@gmail.com>
Date
Jun 1, 2014, 18:10 UTC
Message-ID
<06d9d4d29fc7ada8d6f4f3f1f1e3e2a764ba7c67.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
Previous: Jeremiah MahlerNext: Johannes Sixt
Message 11 of 15 in “replace signal() with sigaction()”
  1. 0/9 replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  2. 1/9 compat/mingw.c: expand MinGW support for sigactionJeremiah Mahler, Jun 1, 2014
  3. Johannes SixtJun 2, 2014
  4. 2/9 connect.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  5. 3/9 progress.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  6. 4/9 write_or_die.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  7. 5/9 daemon.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  8. 6/9 builtin/log.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  9. 7/9 builtin/merge-index.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  10. 8/9 builtin/verify-tag.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  11. 9/9 sigchain.c: replace signal() with sigaction()Jeremiah Mahler, Jun 1, 2014
  12. Johannes SixtJun 2, 2014
  13. Jeremiah MahlerJun 2, 2014
  14. Junio C HamanoJun 2, 2014
  15. Jeremiah MahlerJun 2, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.