landlock_restrict_self.2: tfix
[man-pages.git] / man2 / sigprocmask.2
blobc3cc8d22dc47a7893abc113ea340ae735a27703d
1 .\" Copyright (c) 2005 Michael Kerrisk
2 .\" based on earlier work by faith@cs.unc.edu and
3 .\" Mike Battersby <mib@deakin.edu.au>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .\" 2005-09-15, mtk, Created new page by splitting off from sigaction.2
8 .\"
9 .TH SIGPROCMASK 2 2021-03-22 "Linux" "Linux Programmer's Manual"
10 .SH NAME
11 sigprocmask, rt_sigprocmask \- examine and change blocked signals
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .B #include <signal.h>
17 .PP
18 .nf
19 /* Prototype for the glibc wrapper function */
20 .BI "int sigprocmask(int " how ", const sigset_t *restrict " set ,
21 .BI "                sigset_t *restrict " oldset );
22 .PP
23 .BR "#include <signal.h>" "           /* Definition of " SIG_* " constants */"
24 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
25 .B #include <unistd.h>
26 .PP
27 /* Prototype for the underlying system call */
28 .BI "int syscall(SYS_rt_sigprocmask, int " how ", const kernel_sigset_t *" set ,
29 .BI "                kernel_sigset_t *" oldset ", size_t " sigsetsize );
30 .PP
31 /* Prototype for the legacy system call (deprecated) */
32 .BI "int syscall(SYS_sigprocmask, int " how ", const old_kernel_sigset_t *" set ,
33 .BI "                old_kernel_sigset_t *" oldset );
34 .fi
35 .PP
36 .RS -4
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
39 .RE
40 .PP
41 .BR sigprocmask ():
42 .nf
43     _POSIX_C_SOURCE
44 .fi
45 .SH DESCRIPTION
46 .BR sigprocmask ()
47 is used to fetch and/or change the signal mask of the calling thread.
48 The signal mask is the set of signals whose delivery is currently
49 blocked for the caller
50 (see also
51 .BR signal (7)
52 for more details).
53 .PP
54 The behavior of the call is dependent on the value of
55 .IR how ,
56 as follows.
57 .TP
58 .B SIG_BLOCK
59 The set of blocked signals is the union of the current set and the
60 .I set
61 argument.
62 .TP
63 .B SIG_UNBLOCK
64 The signals in
65 .I set
66 are removed from the current set of blocked signals.
67 It is permissible to attempt to unblock a signal which is not blocked.
68 .TP
69 .B SIG_SETMASK
70 The set of blocked signals is set to the argument
71 .IR set .
72 .PP
74 .I oldset
75 is non-NULL, the previous value of the signal mask is stored in
76 .IR oldset .
77 .PP
79 .I set
80 is NULL, then the signal mask is unchanged (i.e.,
81 .I how
82 is ignored),
83 but the current value of the signal mask is nevertheless returned in
84 .I oldset
85 (if it is not NULL).
86 .PP
87 A set of functions for modifying and inspecting variables of type
88 .I sigset_t
89 ("signal sets") is described in
90 .BR sigsetops (3).
91 .PP
92 The use of
93 .BR sigprocmask ()
94 is unspecified in a multithreaded process; see
95 .BR pthread_sigmask (3).
96 .SH RETURN VALUE
97 .BR sigprocmask ()
98 returns 0 on success.
99 On failure, \-1 is returned and
100 .I errno
101 is set to indicate the error.
102 .SH ERRORS
104 .B EFAULT
106 .I set
108 .I oldset
109 argument points outside the process's allocated address space.
111 .B EINVAL
112 Either the value specified in
113 .I how
114 was invalid or the kernel does not support the size passed in
115 .I sigsetsize.
116 .SH STANDARDS
117 POSIX.1-2001, POSIX.1-2008.
118 .SH NOTES
119 It is not possible to block
120 .BR SIGKILL " or " SIGSTOP .
121 Attempts to do so are silently ignored.
123 Each of the threads in a process has its own signal mask.
125 A child created via
126 .BR fork (2)
127 inherits a copy of its parent's signal mask;
128 the signal mask is preserved across
129 .BR execve (2).
132 .BR SIGBUS ,
133 .BR SIGFPE ,
134 .BR SIGILL ,
136 .B SIGSEGV
137 are generated
138 while they are blocked, the result is undefined,
139 unless the signal was generated by
140 .BR kill (2),
141 .BR sigqueue (3),
143 .BR raise (3).
146 .BR sigsetops (3)
147 for details on manipulating signal sets.
149 Note that it is permissible (although not very useful) to specify both
150 .I set
152 .I oldset
153 as NULL.
155 .SS C library/kernel differences
156 The kernel's definition of
157 .I sigset_t
158 differs in size from that used
159 by the C library.
160 In this manual page, the former is referred to as
161 .I kernel_sigset_t
162 (it is nevertheless named
163 .I sigset_t
164 in the kernel sources).
166 The glibc wrapper function for
167 .BR sigprocmask ()
168 silently ignores attempts to block the two real-time signals that
169 are used internally by the NPTL threading implementation.
171 .BR nptl (7)
172 for details.
174 The original Linux system call was named
175 .BR sigprocmask ().
176 However, with the addition of real-time signals in Linux 2.2,
177 the fixed-size, 32-bit
178 .I sigset_t
179 (referred to as
180 .I old_kernel_sigset_t
181 in this manual page)
182 type supported by that system call was no longer fit for purpose.
183 Consequently, a new system call,
184 .BR rt_sigprocmask (),
185 was added to support an enlarged
186 .I sigset_t
187 type
188 (referred to as
189 .I kernel_sigset_t
190 in this manual page).
191 The new system call takes a fourth argument,
192 .IR "size_t sigsetsize" ,
193 which specifies the size in bytes of the signal sets in
194 .I set
196 .IR oldset .
197 This argument is currently required to have a fixed architecture specific value
198 (equal to
199 .IR sizeof(kernel_sigset_t) ).
200 .\" sizeof(kernel_sigset_t) == _NSIG / 8,
201 .\" which equals to 8 on most architectures, but e.g. on MIPS it's 16.
203 The glibc
204 .BR sigprocmask ()
205 wrapper function hides these details from us, transparently calling
206 .BR rt_sigprocmask ()
207 when the kernel provides it.
209 .SH SEE ALSO
210 .BR kill (2),
211 .BR pause (2),
212 .BR sigaction (2),
213 .BR signal (2),
214 .BR sigpending (2),
215 .BR sigsuspend (2),
216 .BR pthread_sigmask (3),
217 .BR sigqueue (3),
218 .BR sigsetops (3),
219 .BR signal (7)