summaryrefslogtreecommitdiff
path: root/libc/signal
diff options
context:
space:
mode:
Diffstat (limited to 'libc/signal')
-rw-r--r--libc/signal/sigblock.c6
-rw-r--r--libc/signal/sigignore.c6
-rw-r--r--libc/signal/signal.c5
-rw-r--r--libc/signal/sigpause.c9
-rw-r--r--libc/signal/sigset-cvt-mask.h18
-rw-r--r--libc/signal/sigset.c38
-rw-r--r--libc/signal/sigsetmask.c7
-rw-r--r--libc/signal/sigwait.c6
-rw-r--r--libc/signal/sysv_signal.c6
9 files changed, 39 insertions, 62 deletions
diff --git a/libc/signal/sigblock.c b/libc/signal/sigblock.c
index 7051a94ce..72b42c45e 100644
--- a/libc/signal/sigblock.c
+++ b/libc/signal/sigblock.c
@@ -19,6 +19,7 @@
#define __UCLIBC_HIDE_DEPRECATED__
#include <errno.h>
#include <signal.h>
+#include <string.h>
/* libc_hidden_proto(sigprocmask) */
@@ -30,12 +31,9 @@ int sigblock (int mask)
{
sigset_t set, oset;
- if (sigset_set_old_mask (&set, mask) < 0)
- return -1;
-
+ sigset_set_old_mask (&set, mask);
if (sigprocmask (SIG_BLOCK, &set, &oset) < 0)
return -1;
-
return sigset_get_old_mask (&oset);
}
libc_hidden_def(sigblock)
diff --git a/libc/signal/sigignore.c b/libc/signal/sigignore.c
index 58d1c9bfd..9e658c6c6 100644
--- a/libc/signal/sigignore.c
+++ b/libc/signal/sigignore.c
@@ -30,10 +30,10 @@ int sigignore (int sig)
{
struct sigaction act;
+ memset(&act, 0, sizeof(act));
+ /*__sigemptyset (&act.sa_mask);*/
+ /*act.sa_flags = 0;*/
act.sa_handler = SIG_IGN;
- if (__sigemptyset (&act.sa_mask) < 0)
- return -1;
- act.sa_flags = 0;
return sigaction (sig, &act, NULL);
}
diff --git a/libc/signal/signal.c b/libc/signal/signal.c
index 4d379606f..0ed281ab1 100644
--- a/libc/signal/signal.c
+++ b/libc/signal/signal.c
@@ -42,9 +42,8 @@ __bsd_signal (int sig, __sighandler_t handler)
}
act.sa_handler = handler;
- if (__sigemptyset (&act.sa_mask) < 0
- || __sigaddset (&act.sa_mask, sig) < 0)
- return SIG_ERR;
+ __sigemptyset (&act.sa_mask);
+ __sigaddset (&act.sa_mask, sig);
act.sa_flags = __sigismember (&_sigintr, sig) ? 0 : SA_RESTART;
if (sigaction (sig, &act, &oact) < 0)
return SIG_ERR;
diff --git a/libc/signal/sigpause.c b/libc/signal/sigpause.c
index 195e88efc..96dd93368 100644
--- a/libc/signal/sigpause.c
+++ b/libc/signal/sigpause.c
@@ -23,6 +23,7 @@
#define __FAVOR_BSD
#include <signal.h>
#include <stddef.h> /* For NULL. */
+#include <string.h>
/* libc_hidden_proto(sigprocmask) */
/* libc_hidden_proto(sigdelset) */
@@ -37,16 +38,18 @@ int __sigpause (int sig_or_mask, int is_sig)
{
sigset_t set;
- if (is_sig != 0)
+ if (is_sig)
{
+//TODO: error check for sig_or_mask = BIGNUM?
+
/* The modern X/Open implementation is requested. */
if (sigprocmask (0, NULL, &set) < 0
/* Yes, we call `sigdelset' and not `__sigdelset'. */
|| sigdelset (&set, sig_or_mask) < 0)
return -1;
}
- else if (sigset_set_old_mask (&set, sig_or_mask) < 0)
- return -1;
+ else
+ sigset_set_old_mask (&set, sig_or_mask);
return sigsuspend (&set);
}
diff --git a/libc/signal/sigset-cvt-mask.h b/libc/signal/sigset-cvt-mask.h
index 7b2f4cdce..83be40a51 100644
--- a/libc/signal/sigset-cvt-mask.h
+++ b/libc/signal/sigset-cvt-mask.h
@@ -19,22 +19,12 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-static __inline__ int __attribute__ ((unused))
+static __inline__ void __attribute__ ((unused))
sigset_set_old_mask (sigset_t *set, int mask)
{
- unsigned long int *ptr;
- int cnt;
-
- ptr = &set->__val[0];
-
- *ptr++ = (unsigned int) mask;
-
- cnt = _SIGSET_NWORDS - 2;
- do
- *ptr++ = 0ul;
- while (--cnt >= 0);
-
- return 0;
+ if (_SIGSET_NWORDS > 1)
+ memset(set, 0, sizeof(*set));
+ set->__val[0] = (unsigned int) mask;
}
static __inline__ int __attribute__ ((unused))
diff --git a/libc/signal/sigset.c b/libc/signal/sigset.c
index f4c04dc3e..3efbf3ea3 100644
--- a/libc/signal/sigset.c
+++ b/libc/signal/sigset.c
@@ -31,17 +31,20 @@ __sighandler_t sigset (int sig, __sighandler_t disp)
struct sigaction act, oact;
sigset_t set;
+ /* Check signal extents to protect __sigismember. */
+ if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
+ {
+ __set_errno (EINVAL);
+ return SIG_ERR;
+ }
+
#ifdef SIG_HOLD
/* Handle SIG_HOLD first. */
if (disp == SIG_HOLD)
{
/* Create an empty signal set. */
- if (__sigemptyset (&set) < 0)
- return SIG_ERR;
-
- /* Add the specified signal. */
- if (__sigaddset (&set, sig) < 0)
- return SIG_ERR;
+ __sigemptyset (&set);
+ __sigaddset (&set, sig);
/* Add the signal set to the current signal mask. */
if (sigprocmask (SIG_BLOCK, &set, NULL) < 0)
@@ -51,27 +54,16 @@ __sighandler_t sigset (int sig, __sighandler_t disp)
}
#endif /* SIG_HOLD */
- /* Check signal extents to protect __sigismember. */
- if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
- {
- __set_errno (EINVAL);
- return SIG_ERR;
- }
-
+ memset(&act, 0, sizeof(act));
+ //__sigemptyset (&act.sa_mask);
+ //act.sa_flags = 0;
act.sa_handler = disp;
- if (__sigemptyset (&act.sa_mask) < 0)
- return SIG_ERR;
- act.sa_flags = 0;
if (sigaction (sig, &act, &oact) < 0)
return SIG_ERR;
- /* Create an empty signal set. */
- if (__sigemptyset (&set) < 0)
- return SIG_ERR;
-
- /* Add the specified signal. */
- if (__sigaddset (&set, sig) < 0)
- return SIG_ERR;
+ /* Create an empty signal set. Add the specified signal. */
+ __sigemptyset (&set);
+ __sigaddset (&set, sig);
/* Remove the signal set from the current signal mask. */
if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0)
diff --git a/libc/signal/sigsetmask.c b/libc/signal/sigsetmask.c
index 5de4b59e4..9349deb38 100644
--- a/libc/signal/sigsetmask.c
+++ b/libc/signal/sigsetmask.c
@@ -19,6 +19,7 @@
#define __UCLIBC_HIDE_DEPRECATED__
#include <errno.h>
#include <signal.h>
+#include <string.h>
/* libc_hidden_proto(sigprocmask) */
@@ -31,13 +32,9 @@ sigsetmask (int mask)
{
sigset_t set, oset;
- if (sigset_set_old_mask (&set, mask) < 0)
- return -1;
-
+ sigset_set_old_mask (&set, mask);
if (sigprocmask (SIG_SETMASK, &set, &oset) < 0)
return -1;
-
-
return sigset_get_old_mask (&oset);
}
libc_hidden_def(sigsetmask)
diff --git a/libc/signal/sigwait.c b/libc/signal/sigwait.c
index c902ee888..9b2c32079 100644
--- a/libc/signal/sigwait.c
+++ b/libc/signal/sigwait.c
@@ -28,8 +28,8 @@
int __sigwait (const sigset_t *set, int *sig) attribute_hidden;
int __sigwait (const sigset_t *set, int *sig)
{
- int ret = 1;
- if ((ret = sigwaitinfo(set, NULL)) != -1) {
+ int ret = sigwaitinfo(set, NULL);
+ if (ret != -1) {
*sig = ret;
return 0;
}
@@ -41,7 +41,7 @@ int __sigwait (const sigset_t *set, int *sig)
/* libc_hidden_proto(sigaction) */
/* libc_hidden_proto(sigsuspend) */
-static int was_sig; /* obviously not thread-safe */
+static smallint was_sig; /* obviously not thread-safe */
static void ignore_signal(int sig)
{
was_sig = sig;
diff --git a/libc/signal/sysv_signal.c b/libc/signal/sysv_signal.c
index c0cd19a95..f573482f9 100644
--- a/libc/signal/sysv_signal.c
+++ b/libc/signal/sysv_signal.c
@@ -47,10 +47,8 @@ __sighandler_t __sysv_signal (int sig, __sighandler_t handler)
}
act.sa_handler = handler;
- if (__sigemptyset (&act.sa_mask) < 0)
- return SIG_ERR;
- act.sa_flags = SA_ONESHOT | SA_NOMASK | SA_INTERRUPT;
- act.sa_flags &= ~SA_RESTART;
+ __sigemptyset (&act.sa_mask);
+ act.sa_flags = (SA_ONESHOT | SA_NOMASK | SA_INTERRUPT) & ~SA_RESTART;
if (sigaction (sig, &act, &oact) < 0)
return SIG_ERR;