xref: /freebsd/lib/libsys/sigwaitinfo.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
2*8269e767SBrooks Davis.\" All rights reserved.
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
6*8269e767SBrooks Davis.\" are met:
7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*8269e767SBrooks Davis.\"    notice(s), this list of conditions and the following disclaimer as
9*8269e767SBrooks Davis.\"    the first lines of this file unmodified other than the possible
10*8269e767SBrooks Davis.\"    addition of one or more copyright notices.
11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
12*8269e767SBrooks Davis.\"    notice(s), this list of conditions and the following disclaimer in
13*8269e767SBrooks Davis.\"    the documentation and/or other materials provided with the
14*8269e767SBrooks Davis.\"    distribution.
15*8269e767SBrooks Davis.\"
16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17*8269e767SBrooks Davis.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*8269e767SBrooks Davis.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20*8269e767SBrooks Davis.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*8269e767SBrooks Davis.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*8269e767SBrooks Davis.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23*8269e767SBrooks Davis.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24*8269e767SBrooks Davis.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25*8269e767SBrooks Davis.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26*8269e767SBrooks Davis.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*8269e767SBrooks Davis.\"
28*8269e767SBrooks Davis.Dd April 21, 2022
29*8269e767SBrooks Davis.Dt SIGTIMEDWAIT 2
30*8269e767SBrooks Davis.Os
31*8269e767SBrooks Davis.Sh NAME
32*8269e767SBrooks Davis.Nm sigtimedwait , sigwaitinfo
33*8269e767SBrooks Davis.Nd "wait for queued signals (REALTIME)"
34*8269e767SBrooks Davis.Sh LIBRARY
35*8269e767SBrooks Davis.Lb libc
36*8269e767SBrooks Davis.Sh SYNOPSIS
37*8269e767SBrooks Davis.In signal.h
38*8269e767SBrooks Davis.Ft int
39*8269e767SBrooks Davis.Fo sigtimedwait
40*8269e767SBrooks Davis.Fa "const sigset_t *restrict set" "siginfo_t *restrict info"
41*8269e767SBrooks Davis.Fa "const struct timespec *restrict timeout"
42*8269e767SBrooks Davis.Fc
43*8269e767SBrooks Davis.Ft int
44*8269e767SBrooks Davis.Fn sigwaitinfo "const sigset_t * restrict set" "siginfo_t * restrict info"
45*8269e767SBrooks Davis.Sh DESCRIPTION
46*8269e767SBrooks DavisThe
47*8269e767SBrooks Davis.Fn sigtimedwait
48*8269e767SBrooks Davissystem call is equivalent to
49*8269e767SBrooks Davis.Fn sigwaitinfo
50*8269e767SBrooks Davisexcept that if none of the signals specified by
51*8269e767SBrooks Davis.Fa set
52*8269e767SBrooks Davisare pending,
53*8269e767SBrooks Davis.Fn sigtimedwait
54*8269e767SBrooks Daviswaits for the time interval specified in the
55*8269e767SBrooks Davis.Vt timespec
56*8269e767SBrooks Davisstructure referenced by
57*8269e767SBrooks Davis.Fa timeout .
58*8269e767SBrooks DavisIf the
59*8269e767SBrooks Davis.Vt timespec
60*8269e767SBrooks Davisstructure pointed to by
61*8269e767SBrooks Davis.Fa timeout
62*8269e767SBrooks Davisis zero-valued and if none of the signals specified by
63*8269e767SBrooks Davis.Fa set
64*8269e767SBrooks Davisare pending, then
65*8269e767SBrooks Davis.Fn sigtimedwait
66*8269e767SBrooks Davisreturns immediately with an error.
67*8269e767SBrooks DavisIf
68*8269e767SBrooks Davis.Fa timeout
69*8269e767SBrooks Davisis the
70*8269e767SBrooks Davis.Dv NULL
71*8269e767SBrooks Davispointer,
72*8269e767SBrooks Davis.Fn sigtimedwait
73*8269e767SBrooks Davisblocks indefinitely.
74*8269e767SBrooks Davis.Dv CLOCK_MONOTONIC
75*8269e767SBrooks Davisclock is used to measure the time interval specified by the
76*8269e767SBrooks Davis.Fa timeout
77*8269e767SBrooks Davisargument.
78*8269e767SBrooks Davis.Pp
79*8269e767SBrooks DavisThe
80*8269e767SBrooks Davis.Fn sigwaitinfo
81*8269e767SBrooks Davissystem call selects the pending signal from the set specified by
82*8269e767SBrooks Davis.Fa set .
83*8269e767SBrooks DavisShould any of multiple pending signals in the range
84*8269e767SBrooks Davis.Dv SIGRTMIN
85*8269e767SBrooks Davisto
86*8269e767SBrooks Davis.Dv SIGRTMAX
87*8269e767SBrooks Davisbe selected, it shall be the lowest numbered one.
88*8269e767SBrooks DavisThe
89*8269e767SBrooks Davisselection order between realtime and non-realtime signals, or
90*8269e767SBrooks Davisbetween multiple pending non-realtime signals, is unspecified.
91*8269e767SBrooks DavisIf no signal in
92*8269e767SBrooks Davis.Fa set
93*8269e767SBrooks Davisis pending at the time of the call, the calling thread
94*8269e767SBrooks Davisis suspended until one or more signals in
95*8269e767SBrooks Davis.Fa set
96*8269e767SBrooks Davisbecome pending or until it is interrupted by an unblocked, caught signal.
97*8269e767SBrooks Davis.Pp
98*8269e767SBrooks DavisThe
99*8269e767SBrooks Davis.Fn sigwaitinfo
100*8269e767SBrooks Davissystem call is equivalent to the
101*8269e767SBrooks Davis.Fn sigwait
102*8269e767SBrooks Davissystem call if the
103*8269e767SBrooks Davis.Fa info
104*8269e767SBrooks Davisargument is
105*8269e767SBrooks Davis.Dv NULL .
106*8269e767SBrooks DavisIf the
107*8269e767SBrooks Davis.Fa info
108*8269e767SBrooks Davisargument is
109*8269e767SBrooks Davis.Pf non- Dv NULL ,
110*8269e767SBrooks Davisthe
111*8269e767SBrooks Davis.Fn sigwaitinfo
112*8269e767SBrooks Davisfunction is equivalent to
113*8269e767SBrooks Davis.Fn sigwait ,
114*8269e767SBrooks Davisexcept that the selected signal number shall be stored in the
115*8269e767SBrooks Davis.Va si_signo
116*8269e767SBrooks Davismember, and the cause of the signal shall be stored in the
117*8269e767SBrooks Davis.Va si_code
118*8269e767SBrooks Davismember.
119*8269e767SBrooks DavisBesides this, the
120*8269e767SBrooks Davis.Fn sigwaitinfo
121*8269e767SBrooks Davisand
122*8269e767SBrooks Davis.Fn sigtimedwait
123*8269e767SBrooks Davissystem calls may return
124*8269e767SBrooks Davis.Er EINTR
125*8269e767SBrooks Davisif interrupted by signal, which is not allowed for the
126*8269e767SBrooks Davis.Fn sigwait
127*8269e767SBrooks Davisfunction.
128*8269e767SBrooks Davis.Pp
129*8269e767SBrooks DavisIf any value is queued to the selected signal, the first such queued
130*8269e767SBrooks Davisvalue is dequeued and, if the info argument is
131*8269e767SBrooks Davis.Pf non- Dv NULL ,
132*8269e767SBrooks Davisthe value is stored in the
133*8269e767SBrooks Davis.Va si_value
134*8269e767SBrooks Davismember of
135*8269e767SBrooks Davis.Fa info .
136*8269e767SBrooks DavisThe system resource used to queue the signal
137*8269e767SBrooks Davisis released and returned to the system for other use.
138*8269e767SBrooks DavisIf no value is queued,
139*8269e767SBrooks Davisthe content of the
140*8269e767SBrooks Davis.Va si_value
141*8269e767SBrooks Davismember is zero-valued.
142*8269e767SBrooks DavisIf no further signals are
143*8269e767SBrooks Davisqueued for the selected signal, the pending indication for that signal
144*8269e767SBrooks Davisis reset.
145*8269e767SBrooks Davis.Sh RETURN VALUES
146*8269e767SBrooks DavisUpon successful completion (that is, one of the signals specified by
147*8269e767SBrooks Davis.Fa set
148*8269e767SBrooks Davisis pending or is generated)
149*8269e767SBrooks Davis.Fn sigwaitinfo
150*8269e767SBrooks Davisand
151*8269e767SBrooks Davis.Fn sigtimedwait
152*8269e767SBrooks Davisreturn the selected signal number.
153*8269e767SBrooks DavisOtherwise, the functions return a value of \-1
154*8269e767SBrooks Davisand set the global variable
155*8269e767SBrooks Davis.Va errno
156*8269e767SBrooks Davisto indicate the error.
157*8269e767SBrooks Davis.Sh ERRORS
158*8269e767SBrooks DavisThe
159*8269e767SBrooks Davis.Fn sigtimedwait
160*8269e767SBrooks Davissystem call
161*8269e767SBrooks Daviswill fail if:
162*8269e767SBrooks Davis.Bl -tag -width Er
163*8269e767SBrooks Davis.It Bq Er EAGAIN
164*8269e767SBrooks DavisNo signal specified by set was generated within the specified timeout period.
165*8269e767SBrooks Davis.El
166*8269e767SBrooks Davis.Pp
167*8269e767SBrooks DavisThe
168*8269e767SBrooks Davis.Fn sigtimedwait
169*8269e767SBrooks Davisand
170*8269e767SBrooks Davis.Fn sigwaitinfo
171*8269e767SBrooks Davissystem calls fail if:
172*8269e767SBrooks Davis.Bl -tag -width Er
173*8269e767SBrooks Davis.It Bq Er EINTR
174*8269e767SBrooks DavisThe wait was interrupted by an unblocked, caught signal.
175*8269e767SBrooks Davis.El
176*8269e767SBrooks Davis.Pp
177*8269e767SBrooks DavisThe
178*8269e767SBrooks Davis.Fn sigtimedwait
179*8269e767SBrooks Davissystem call may also fail if:
180*8269e767SBrooks Davis.Bl -tag -width Er
181*8269e767SBrooks Davis.It Bq Er EINVAL
182*8269e767SBrooks DavisThe
183*8269e767SBrooks Davis.Fa timeout
184*8269e767SBrooks Davisargument specified a
185*8269e767SBrooks Davis.Va tv_nsec
186*8269e767SBrooks Davisvalue less than zero or greater than or equal
187*8269e767SBrooks Davisto 1000 million.
188*8269e767SBrooks DavisKernel only checks for this error if no signal is pending in set and it
189*8269e767SBrooks Davisis necessary to wait.
190*8269e767SBrooks Davis.El
191*8269e767SBrooks Davis.Sh SEE ALSO
192*8269e767SBrooks Davis.Xr sigaction 2 ,
193*8269e767SBrooks Davis.Xr sigpending 2 ,
194*8269e767SBrooks Davis.Xr sigqueue 2 ,
195*8269e767SBrooks Davis.Xr sigsuspend 2 ,
196*8269e767SBrooks Davis.Xr sigwait 2 ,
197*8269e767SBrooks Davis.Xr pause 3 ,
198*8269e767SBrooks Davis.Xr pthread_sigmask 3 ,
199*8269e767SBrooks Davis.Xr siginfo 3
200*8269e767SBrooks Davis.Sh STANDARDS
201*8269e767SBrooks DavisThe
202*8269e767SBrooks Davis.Fn sigtimedwait
203*8269e767SBrooks Davisand
204*8269e767SBrooks Davis.Fn sigwaitinfo
205*8269e767SBrooks Davissystem calls conform to
206*8269e767SBrooks Davis.St -p1003.1-96 .
207*8269e767SBrooks DavisPOSIX
208*8269e767SBrooks Davisleaves the behavior of
209*8269e767SBrooks Davis.Fn sigtimedwait
210*8269e767SBrooks Daviswith a
211*8269e767SBrooks Davis.Dv NULL
212*8269e767SBrooks Davis.Fa timeout
213*8269e767SBrooks Davispointer unspecified.
214