summaryrefslogtreecommitdiff
path: root/src/libstddjb/selfpipe_finish.c
blob: db42430b4d2960250be0a9367f9038e84f106c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* ISC license. */

/* MT-unsafe */

#include <skalibs/sysdeps.h>

#ifdef SKALIBS_HASSIGNALFD

#include <errno.h>
#include <signal.h>

#include <skalibs/djbunix.h>
#include <skalibs/selfpipe.h>
#include "selfpipe-internal.h"

void selfpipe_finish (void)
{
  int e = errno ;
  fd_close(selfpipe_fd) ;
  sigprocmask(SIG_UNBLOCK, &selfpipe_caught, 0) ;
  sigemptyset(&selfpipe_caught) ;
  selfpipe_fd = -1 ;
  errno = e ;
}

#else

#include <skalibs/nonposix.h>
#include <skalibs/bsdsnowflake.h>

#include <errno.h>
#include <signal.h>

#include <skalibs/nsig.h>
#include <skalibs/sig.h>
#include <skalibs/djbunix.h>
#include <skalibs/selfpipe.h>
#include "selfpipe-internal.h"

void selfpipe_finish (void)
{
  int e = errno ;
  sigprocmask(SIG_BLOCK, &selfpipe_caught, 0) ;
  sig_restoreto(&selfpipe_caught, SKALIBS_NSIG) ;
  fd_close(selfpipe[1]) ;
  fd_close(selfpipe[0]) ;
  sigprocmask(SIG_UNBLOCK, &selfpipe_caught, 0) ;
  sigemptyset(&selfpipe_caught) ;
  selfpipe[0] = selfpipe[1] = -1 ;
  errno = e ;
}

#endif