summaryrefslogtreecommitdiff
path: root/src/libstddjb/selfpipe_init.c
blob: 8dcdcca3f32f5a89429cbb83f1cb73ce24006ce4 (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
/* ISC license. */

/* MT-unsafe */

#include <signal.h>

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

#ifdef SKALIBS_HASSIGNALFD

#include <sys/signalfd.h>

int selfpipe_init (void)
{
  sigemptyset(&selfpipe_caught) ;
  selfpipe_fd = signalfd(selfpipe_fd, &selfpipe_caught, SFD_NONBLOCK | SFD_CLOEXEC) ;
  sig_blocknone() ;
  return selfpipe_fd ;
}

#else

#include <skalibs/djbunix.h>

int selfpipe_init (void)
{
  if (selfpipe_fd >= 0) selfpipe_finish() ;
  sigemptyset(&selfpipe_caught) ;
  sig_blocknone() ;
  return pipenbcoe(selfpipe) < 0 ? -1 : selfpipe_fd ;
}

#endif