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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]