xref: /illumos-gate/usr/src/man/man3c/signalfd.3c (revision 447b1e1fca22e4de5e04623965fbb1460857930c)
1.\"
2.\"  This file and its contents are supplied under the terms of the
3.\"  Common Development and Distribution License ("CDDL"), version 1.0.
4.\"  You may only use this file in accordance with the terms of version
5.\"  1.0 of the CDDL.
6.\"
7.\"  A full copy of the text of the CDDL should have accompanied this
8.\"  source.  A copy of the CDDL is also available via the Internet at
9.\"  http://www.illumos.org/license/CDDL.
10.\"
11.\"  Copyright 2015, Joyent, Inc.
12.\"
13.Dd "April 9, 2016"
14.Dt SIGNALFD 3C
15.Os
16.Sh NAME
17.Nm signalfd
18.Nd create or modify a file descriptor for signal handling
19.Sh SYNOPSIS
20.In sys/signalfd.h
21.
22.Ft int
23.Fo signalfd
24.Fa "int fd"
25.Fa "const sigset_t *mask"
26.Fa "int flags"
27.Fc
28.
29.Sh DESCRIPTION
30The
31.Fn signalfd
32function returns a file descriptor that can be used
33for synchronous consumption of signals. The file descriptor can be operated
34upon via
35.Xr read 2
36and the facilities that notify of file descriptor activity (e.g.
37.Xr poll 2 ,
38.Xr port_get 3C ,
39.Xr epoll_wait 3C
40). To dispose of the instance
41.Xr close 2
42should be called on the file descriptor.
43.Pp
44If the
45.Va fd
46argument is -1, a new signalfd file descriptor will be
47returned, otherwise the
48.Va fd
49argument should be an existing signalfd file descriptor whose signal mask will
50be updated.
51.Pp
52The
53.Va mask
54argument specifies the set of signals that are relevant to the file descriptor.
55It may be manipulated with the standard signal set manipulation functions
56documented in
57.Xr sigsetops 3C .
58Signals in the mask which cannot be caught (e.g.
59.Fa SIGKILL )
60are ignored.
61.Pp
62The
63.Va flags
64argument specifies additional parameters for the instance, and can have any of
65the following values:
66.Bl -tag -width Dv
67.It Sy SFD_CLOEXEC
68Instance will be closed upon an
69.Xr exec 2 ;
70see description for
71.Fa O_CLOEXEC
72in
73.Xr open 2 .
74.It Sy SFD_NONBLOCK
75Instance will be set to be non-blocking. A
76.Xr read 2
77on a signalfd instance that has been initialized with
78.Fa SFD_NONBLOCK ,
79or made non-blocking in other ways, will return
80.Er EAGAIN
81in lieu of blocking if there are no signals from the
82.Va mask
83that are pending.
84.El
85.Pp
86As with
87.Xr sigwait 2 ,
88reading a signal from the file descriptor will consume the signal. The signals
89used with signalfd file descriptors are normally first blocked so that their
90handler does not run when a signal arrives. If the signal is not blocked the
91behavior matches that of
92.Xr sigwait 2 ;
93if a
94.Xr read 2
95is pending then the signal is consumed by the read, otherwise the signal is
96consumed by the handler.
97.Pp
98The following operations can be performed upon a signalfd file descriptor:
99.Bl -tag -width Dv
100.It Sy read(2)
101Reads and consumes one or more of the pending signals that match the file
102descriptor's
103.Va mask .
104The read buffer must be large enough to hold one or more
105.Vt signalfd_siginfo
106structures, which is described below.
107.Xr read 2
108will block if there are no matching signals pending, or return
109.Er EAGAIN
110if the instance was created with
111.Fa SFD_NONBLOCK .
112After a
113.Xr fork 2 ,
114if the child reads from the descriptor it will only consume signals from itself.
115.It Sy poll(2)
116Provide notification when one of the signals from the
117.Va mask
118arrives.
119.Fa POLLIN
120and
121.Fa POLLRDNORM
122will be set.
123.It Sy close(2)
124Closes the desriptor.
125.El
126.Pp
127The
128.Vt signalfd_siginfo
129structure returned from
130.Xr read 2
131is a fixed size 128 byte structure defined as follows:
132.Bd -literal
133typedef struct signalfd_siginfo {
134        uint32_t ssi_signo;     /* signal from signal.h */
135        int32_t  ssi_errno;     /* error from errno.h */
136        int32_t  ssi_code;      /* signal code */
137        uint32_t ssi_pid;       /* PID of sender */
138        uint32_t ssi_uid;       /* real UID of sender */
139        int32_t  ssi_fd;        /* file descriptor (SIGIO) */
140        uint32_t ssi_tid;       /* unused */
141        uint32_t ssi_band;      /* band event (SIGIO) */
142        uint32_t ssi_overrun;   /* unused */
143        uint32_t ssi_trapno;    /* trap number that caused signal */
144        int32_t  ssi_status;    /* exit status or signal (SIGCHLD) */
145        int32_t  ssi_int;       /* unused */
146        uint64_t ssi_ptr;       /* unused */
147        uint64_t ssi_utime;     /* user CPU time consumed (SIGCHLD) */
148        uint64_t ssi_stime;     /* system CPU time consumed (SIGCHLD) */
149        uint64_t ssi_addr;      /* address that generated signal */
150        uint8_t  ssi_pad[48];   /* pad size to 128 bytes */
151} signalfd_siginfo_t;
152.Ed
153.Sh RETURN VALUES
154Upon successful completion, a file descriptor associated with the instance
155is returned. Otherwise, -1 is returned and errno is set to indicate the error.
156When
157.Va fd
158is not -1 and there is no error, the value of
159.Va fd
160is returned.
161.Sh ERRORS
162The
163.Fn signalfd function
164will fail if:
165.Bl -tag -width Er
166.It Er EBADF
167The
168.Va fd
169descriptor is invalid.
170.It Er EFAULT
171The
172.Va mask
173address is invalid.
174.It Er EINVAL
175The
176.Va fd
177descriptor is not a signalfd descriptor or the
178.Va flags
179are invalid.
180.It Er EMFILE
181There are currently
182.Va  OPEN_MAX
183file descriptors open in the calling process.
184.It Er ENODEV
185Unable to allocate state for the file descriptor.
186.El
187.Sh SEE ALSO
188.Xr poll 2 ,
189.Xr sigwait 2 ,
190.Xr sigsetops 3C ,
191.Xr sigwaitinfo 3C ,
192.Xr signal.h 3HEAD
193