summaryrefslogtreecommitdiff
path: root/src/libstddjb/selfpipe_trapset.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2021-07-28 23:45:20 +0000
committerLaurent Bercot <ska@appnovation.com>2021-07-28 23:45:20 +0000
commit9592bfd0dda7c575de07bce2c7a81b8432d845a4 (patch)
tree57c66c3e0dfeb63cfd3ebfef18e30a2145ae3f88 /src/libstddjb/selfpipe_trapset.c
parentc15bccec3fd551583ff838673ba284ee6c7e788a (diff)
downloadskalibs-9592bfd0dda7c575de07bce2c7a81b8432d845a4.tar.xz
Huge incompatible changes.
- Obsolete skalibs/environ.h and skalibs/getpeereid.h removed. - rc4 and md5 removed. - All *_t types renamed to avoid treading on POSIX namespace. - subgetopt() renamed to lgetopt(). - signal functions reworked; skasigaction removed; sig_stack removed - Various functions removed: skaoffsetof(), selfpipe_untrap() - New posixplz function: munmap_void. Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/selfpipe_trapset.c')
-rw-r--r--src/libstddjb/selfpipe_trapset.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/libstddjb/selfpipe_trapset.c b/src/libstddjb/selfpipe_trapset.c
index 542ad10..9559c07 100644
--- a/src/libstddjb/selfpipe_trapset.c
+++ b/src/libstddjb/selfpipe_trapset.c
@@ -7,60 +7,66 @@
#include <errno.h>
#include <signal.h>
#include <sys/signalfd.h>
+
#include <skalibs/selfpipe.h>
#include "selfpipe-internal.h"
int selfpipe_trapset (sigset_t const *set)
{
sigset_t old ;
- if (selfpipe_fd < 0) return (errno = EBADF, -1) ;
- if (sigprocmask(SIG_BLOCK, set, &old) < 0) return -1 ;
+ if (selfpipe_fd < 0) return (errno = EBADF, 0) ;
+ if (sigprocmask(SIG_SETMASK, set, &old) < 0) return 0 ;
if (signalfd(selfpipe_fd, set, SFD_NONBLOCK | SFD_CLOEXEC) < 0)
{
int e = errno ;
sigprocmask(SIG_SETMASK, &old, 0) ;
errno = e ;
- return -1 ;
+ return 0 ;
}
selfpipe_caught = *set ;
- return 0 ;
+ return 1 ;
}
#else
#include <skalibs/nonposix.h>
+#include <skalibs/bsdsnowflake.h>
+
#include <errno.h>
#include <signal.h>
-#include <skalibs/sig.h>
+
#include <skalibs/nsig.h>
+#include <skalibs/sig.h>
#include <skalibs/selfpipe.h>
#include "selfpipe-internal.h"
int selfpipe_trapset (sigset_t const *set)
{
unsigned int i = 1 ;
- if (selfpipe_fd < 0) return (errno = EBADF, -1) ;
+ if (selfpipe_fd < 0) return (errno = EBADF, 0) ;
for (; i < SKALIBS_NSIG ; i++)
{
int h = sigismember(set, i) ;
if (h < 0) continue ;
if (h)
{
- if (sig_catcha(i, &selfpipe_ssa) < 0) break ;
+ if (!sig_catch(i, &selfpipe_tophalf)) goto err ;
}
else if (sigismember(&selfpipe_caught, i))
{
- if (sig_restore(i) < 0) break ;
+ if (!sig_restore(i)) goto err ;
}
}
- if (i < SKALIBS_NSIG || sigprocmask(SIG_UNBLOCK, set, 0) < 0)
+ sig_blocknone() ;
+ selfpipe_caught = *set ;
+ return 1 ;
+
+ err:
{
int e = errno ;
sig_restoreto(set, i) ;
errno = e ;
- return -1 ;
}
- selfpipe_caught = *set ;
return 0 ;
}