Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Josh Gao | 61cf3f3 | 2016-03-08 15:27:15 -0800 | [diff] [blame] | 17 | #include <errno.h> |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 18 | #include <signal.h> |
Josh Gao | 61cf3f3 | 2016-03-08 15:27:15 -0800 | [diff] [blame] | 19 | #include <sys/syscall.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <unistd.h> |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 22 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 23 | #include <thread> |
| 24 | |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 25 | #include <android-base/macros.h> |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 26 | #include <gtest/gtest.h> |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 27 | |
Elliott Hughes | 71ba589 | 2018-02-07 12:44:45 -0800 | [diff] [blame] | 28 | #include "SignalUtils.h" |
Christopher Ferris | 1361313 | 2013-10-28 15:24:04 -0700 | [diff] [blame] | 29 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 30 | static int SIGNAL_MIN() { |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 31 | return 1; // Signals start at 1 (SIGHUP), not 0. |
| 32 | } |
| 33 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 34 | template <typename SigSetT> |
| 35 | static int SIGNAL_MAX(SigSetT* set) { |
| 36 | return sizeof(*set) * 8; |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 39 | template <typename SigSetT> |
| 40 | static void TestSigSet1(int (fn)(SigSetT*)) { |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 41 | // nullptr sigset_t*/sigset64_t*. |
| 42 | SigSetT* set_ptr = nullptr; |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 43 | errno = 0; |
| 44 | ASSERT_EQ(-1, fn(set_ptr)); |
| 45 | ASSERT_EQ(EINVAL, errno); |
| 46 | |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 47 | // Non-nullptr. |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 48 | SigSetT set = {}; |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 49 | errno = 0; |
| 50 | ASSERT_EQ(0, fn(&set)); |
| 51 | ASSERT_EQ(0, errno); |
| 52 | } |
| 53 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 54 | template <typename SigSetT> |
| 55 | static void TestSigSet2(int (fn)(SigSetT*, int)) { |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 56 | // nullptr sigset_t*/sigset64_t*. |
| 57 | SigSetT* set_ptr = nullptr; |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 58 | errno = 0; |
| 59 | ASSERT_EQ(-1, fn(set_ptr, SIGSEGV)); |
| 60 | ASSERT_EQ(EINVAL, errno); |
| 61 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 62 | SigSetT set = {}; |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 63 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 64 | // Bad signal number: too small. |
| 65 | errno = 0; |
| 66 | ASSERT_EQ(-1, fn(&set, 0)); |
| 67 | ASSERT_EQ(EINVAL, errno); |
| 68 | |
| 69 | // Bad signal number: too high. |
| 70 | errno = 0; |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 71 | ASSERT_EQ(-1, fn(&set, SIGNAL_MAX(&set) + 1)); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 72 | ASSERT_EQ(EINVAL, errno); |
| 73 | |
| 74 | // Good signal numbers, low and high ends of range. |
| 75 | errno = 0; |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 76 | ASSERT_EQ(0, fn(&set, SIGNAL_MIN())); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 77 | ASSERT_EQ(0, errno); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 78 | ASSERT_EQ(0, fn(&set, SIGNAL_MAX(&set))); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 79 | ASSERT_EQ(0, errno); |
| 80 | } |
| 81 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 82 | TEST(signal, sigaddset_invalid) { |
| 83 | TestSigSet2(sigaddset); |
| 84 | } |
| 85 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 86 | TEST(signal, sigaddset64_invalid) { |
| 87 | #if defined(__BIONIC__) |
| 88 | TestSigSet2(sigaddset64); |
| 89 | #endif |
| 90 | } |
| 91 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 92 | TEST(signal, sigdelset_invalid) { |
| 93 | TestSigSet2(sigdelset); |
| 94 | } |
| 95 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 96 | TEST(signal, sigdelset64_invalid) { |
| 97 | #if defined(__BIONIC__) |
| 98 | TestSigSet2(sigdelset64); |
| 99 | #endif |
| 100 | } |
| 101 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 102 | TEST(signal, sigemptyset_invalid) { |
| 103 | TestSigSet1(sigemptyset); |
| 104 | } |
| 105 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 106 | TEST(signal, sigemptyset64_invalid) { |
| 107 | #if defined(__BIONIC__) |
| 108 | TestSigSet1(sigemptyset64); |
| 109 | #endif |
| 110 | } |
| 111 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 112 | TEST(signal, sigfillset_invalid) { |
| 113 | TestSigSet1(sigfillset); |
| 114 | } |
Chris Dearman | d8a5a6f | 2012-12-07 18:41:10 -0800 | [diff] [blame] | 115 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 116 | TEST(signal, sigfillset64_invalid) { |
| 117 | #if defined(__BIONIC__) |
| 118 | TestSigSet1(sigfillset64); |
| 119 | #endif |
| 120 | } |
| 121 | |
| 122 | TEST(signal, sigismember_invalid) { |
| 123 | TestSigSet2(sigismember); |
| 124 | } |
| 125 | |
| 126 | TEST(signal, sigismember64_invalid) { |
| 127 | #if defined(__BIONIC__) |
| 128 | TestSigSet2(sigismember64); |
| 129 | #endif |
| 130 | } |
| 131 | |
Chris Dearman | d8a5a6f | 2012-12-07 18:41:10 -0800 | [diff] [blame] | 132 | TEST(signal, raise_invalid) { |
| 133 | errno = 0; |
| 134 | ASSERT_EQ(-1, raise(-1)); |
| 135 | ASSERT_EQ(EINVAL, errno); |
| 136 | } |
Elliott Hughes | c5d028f | 2013-01-10 14:42:14 -0800 | [diff] [blame] | 137 | |
Elliott Hughes | fae89fc | 2013-02-21 11:22:23 -0800 | [diff] [blame] | 138 | static void raise_in_signal_handler_helper(int signal_number) { |
| 139 | ASSERT_EQ(SIGALRM, signal_number); |
| 140 | static int count = 0; |
| 141 | if (++count == 1) { |
| 142 | raise(SIGALRM); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | TEST(signal, raise_in_signal_handler) { |
| 147 | ScopedSignalHandler ssh(SIGALRM, raise_in_signal_handler_helper); |
| 148 | raise(SIGALRM); |
| 149 | } |
| 150 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 151 | TEST(signal, sigwait_SIGALRM) { |
| 152 | ScopedSignalHandler ssh(SIGALRM, [](int sig) { ASSERT_EQ(SIGALRM, sig); }); |
Elliott Hughes | c5d028f | 2013-01-10 14:42:14 -0800 | [diff] [blame] | 153 | |
| 154 | sigset_t wait_set; |
| 155 | sigemptyset(&wait_set); |
| 156 | sigaddset(&wait_set, SIGALRM); |
| 157 | |
| 158 | alarm(1); |
| 159 | |
| 160 | int received_signal; |
| 161 | errno = 0; |
| 162 | ASSERT_EQ(0, sigwait(&wait_set, &received_signal)); |
| 163 | ASSERT_EQ(0, errno); |
| 164 | ASSERT_EQ(SIGALRM, received_signal); |
| 165 | } |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 166 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 167 | TEST(signal, sigwait64_SIGRTMIN) { |
| 168 | ScopedSignalHandler ssh(SIGRTMIN, [](int sig) { ASSERT_EQ(SIGRTMIN, sig); }); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 169 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 170 | sigset64_t wait_set; |
| 171 | sigemptyset64(&wait_set); |
| 172 | sigaddset64(&wait_set, SIGRTMIN); |
| 173 | |
| 174 | pid_t pid = getpid(); |
| 175 | std::thread thread([&pid]() { |
| 176 | usleep(5000); |
| 177 | kill(pid, SIGRTMIN); |
| 178 | }); |
| 179 | |
| 180 | int received_signal; |
| 181 | errno = 0; |
| 182 | ASSERT_EQ(0, sigwait64(&wait_set, &received_signal)); |
| 183 | ASSERT_EQ(0, errno); |
| 184 | ASSERT_EQ(SIGRTMIN, received_signal); |
| 185 | |
| 186 | thread.join(); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 189 | static int g_sigsuspend_signal_handler_call_count = 0; |
| 190 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 191 | TEST(signal, sigsuspend_sigpending) { |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 192 | SignalMaskRestorer smr; |
| 193 | |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 194 | // Block SIGALRM. |
| 195 | sigset_t just_SIGALRM; |
| 196 | sigemptyset(&just_SIGALRM); |
| 197 | sigaddset(&just_SIGALRM, SIGALRM); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 198 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr)); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 199 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 200 | ScopedSignalHandler ssh(SIGALRM, [](int) { ++g_sigsuspend_signal_handler_call_count; }); |
Elliott Hughes | 1195207 | 2013-10-24 15:15:14 -0700 | [diff] [blame] | 201 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 202 | // There should be no pending signals. |
| 203 | sigset_t pending; |
| 204 | sigemptyset(&pending); |
| 205 | ASSERT_EQ(0, sigpending(&pending)); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 206 | for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 207 | EXPECT_FALSE(sigismember(&pending, i)) << i; |
| 208 | } |
| 209 | |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 210 | // Raise SIGALRM and check our signal handler wasn't called. |
| 211 | raise(SIGALRM); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 212 | ASSERT_EQ(0, g_sigsuspend_signal_handler_call_count); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 213 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 214 | // We should now have a pending SIGALRM but nothing else. |
| 215 | sigemptyset(&pending); |
| 216 | ASSERT_EQ(0, sigpending(&pending)); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 217 | for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 218 | EXPECT_EQ((i == SIGALRM), sigismember(&pending, i)); |
| 219 | } |
| 220 | |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 221 | // Use sigsuspend to block everything except SIGALRM... |
| 222 | sigset_t not_SIGALRM; |
| 223 | sigfillset(¬_SIGALRM); |
| 224 | sigdelset(¬_SIGALRM, SIGALRM); |
| 225 | ASSERT_EQ(-1, sigsuspend(¬_SIGALRM)); |
| 226 | ASSERT_EQ(EINTR, errno); |
| 227 | // ...and check that we now receive our pending SIGALRM. |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 228 | ASSERT_EQ(1, g_sigsuspend_signal_handler_call_count); |
| 229 | } |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 230 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 231 | static int g_sigsuspend64_signal_handler_call_count = 0; |
| 232 | |
| 233 | TEST(signal, sigsuspend64_sigpending64) { |
| 234 | SignalMaskRestorer smr; |
| 235 | |
| 236 | // Block SIGRTMIN. |
| 237 | sigset64_t just_SIGRTMIN; |
| 238 | sigemptyset64(&just_SIGRTMIN); |
| 239 | sigaddset64(&just_SIGRTMIN, SIGRTMIN); |
| 240 | ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr)); |
| 241 | |
| 242 | ScopedSignalHandler ssh(SIGRTMIN, [](int) { ++g_sigsuspend64_signal_handler_call_count; }); |
| 243 | |
| 244 | // There should be no pending signals. |
| 245 | sigset64_t pending; |
| 246 | sigemptyset64(&pending); |
| 247 | ASSERT_EQ(0, sigpending64(&pending)); |
| 248 | for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { |
| 249 | EXPECT_FALSE(sigismember64(&pending, i)) << i; |
| 250 | } |
| 251 | |
| 252 | // Raise SIGRTMIN and check our signal handler wasn't called. |
| 253 | raise(SIGRTMIN); |
| 254 | ASSERT_EQ(0, g_sigsuspend64_signal_handler_call_count); |
| 255 | |
| 256 | // We should now have a pending SIGRTMIN but nothing else. |
| 257 | sigemptyset64(&pending); |
| 258 | ASSERT_EQ(0, sigpending64(&pending)); |
| 259 | for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { |
| 260 | EXPECT_EQ((i == SIGRTMIN), sigismember64(&pending, i)); |
| 261 | } |
| 262 | |
| 263 | // Use sigsuspend64 to block everything except SIGRTMIN... |
| 264 | sigset64_t not_SIGRTMIN; |
| 265 | sigfillset64(¬_SIGRTMIN); |
| 266 | sigdelset64(¬_SIGRTMIN, SIGRTMIN); |
| 267 | ASSERT_EQ(-1, sigsuspend64(¬_SIGRTMIN)); |
| 268 | ASSERT_EQ(EINTR, errno); |
| 269 | // ...and check that we now receive our pending SIGRTMIN. |
| 270 | ASSERT_EQ(1, g_sigsuspend64_signal_handler_call_count); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 271 | } |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 272 | |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 273 | template <typename SigActionT, typename SigSetT> |
| 274 | static void TestSigAction(int (sigaction_fn)(int, const SigActionT*, SigActionT*), |
| 275 | int (sigaddset_fn)(SigSetT*, int), |
| 276 | int sig) { |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 277 | // Both bionic and glibc set SA_RESTORER when talking to the kernel on arm, |
| 278 | // arm64, x86, and x86-64. The version of glibc we're using also doesn't |
| 279 | // define SA_RESTORER, but luckily it's the same value everywhere, and mips |
| 280 | // doesn't use the bit for anything. |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 281 | static const unsigned sa_restorer = 0x4000000; |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 282 | |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 283 | // See what's currently set for this signal. |
| 284 | SigActionT original_sa = {}; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 285 | ASSERT_EQ(0, sigaction_fn(sig, nullptr, &original_sa)); |
| 286 | ASSERT_TRUE(original_sa.sa_handler == nullptr); |
| 287 | ASSERT_TRUE(original_sa.sa_sigaction == nullptr); |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 288 | ASSERT_EQ(0U, original_sa.sa_flags & ~sa_restorer); |
Goran Jakovljevic | 3796669 | 2018-02-12 09:03:10 +0100 | [diff] [blame] | 289 | #ifdef SA_RESTORER |
Evgeny Eltsin | 11f6076 | 2018-02-05 13:33:35 +0100 | [diff] [blame] | 290 | ASSERT_EQ(bool(original_sa.sa_flags & sa_restorer), bool(original_sa.sa_restorer)); |
Goran Jakovljevic | 3796669 | 2018-02-12 09:03:10 +0100 | [diff] [blame] | 291 | #endif |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 292 | |
| 293 | // Set a traditional sa_handler signal handler. |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 294 | auto no_op_signal_handler = [](int) {}; |
| 295 | SigActionT sa = {}; |
| 296 | sigaddset_fn(&sa.sa_mask, sig); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 297 | sa.sa_flags = SA_ONSTACK; |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 298 | sa.sa_handler = no_op_signal_handler; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 299 | ASSERT_EQ(0, sigaction_fn(sig, &sa, nullptr)); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 300 | |
| 301 | // Check that we can read it back. |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 302 | sa = {}; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 303 | ASSERT_EQ(0, sigaction_fn(sig, nullptr, &sa)); |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 304 | ASSERT_TRUE(sa.sa_handler == no_op_signal_handler); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 305 | ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler); |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 306 | ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK), sa.sa_flags & ~sa_restorer); |
Goran Jakovljevic | 3796669 | 2018-02-12 09:03:10 +0100 | [diff] [blame] | 307 | #ifdef SA_RESTORER |
Evgeny Eltsin | 11f6076 | 2018-02-05 13:33:35 +0100 | [diff] [blame] | 308 | ASSERT_EQ(bool(sa.sa_flags & sa_restorer), bool(sa.sa_restorer)); |
Goran Jakovljevic | 3796669 | 2018-02-12 09:03:10 +0100 | [diff] [blame] | 309 | #endif |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 310 | |
| 311 | // Set a new-style sa_sigaction signal handler. |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 312 | auto no_op_sigaction = [](int, siginfo_t*, void*) {}; |
| 313 | sa = {}; |
| 314 | sigaddset_fn(&sa.sa_mask, sig); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 315 | sa.sa_flags = SA_ONSTACK | SA_SIGINFO; |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 316 | sa.sa_sigaction = no_op_sigaction; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 317 | ASSERT_EQ(0, sigaction_fn(sig, &sa, nullptr)); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 318 | |
| 319 | // Check that we can read it back. |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 320 | sa = {}; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 321 | ASSERT_EQ(0, sigaction_fn(sig, nullptr, &sa)); |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 322 | ASSERT_TRUE(sa.sa_sigaction == no_op_sigaction); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 323 | ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler); |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 324 | ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK | SA_SIGINFO), sa.sa_flags & ~sa_restorer); |
Goran Jakovljevic | 3796669 | 2018-02-12 09:03:10 +0100 | [diff] [blame] | 325 | #ifdef SA_RESTORER |
Evgeny Eltsin | 11f6076 | 2018-02-05 13:33:35 +0100 | [diff] [blame] | 326 | ASSERT_EQ(bool(sa.sa_flags & sa_restorer), bool(sa.sa_restorer)); |
Goran Jakovljevic | 3796669 | 2018-02-12 09:03:10 +0100 | [diff] [blame] | 327 | #endif |
Elliott Hughes | 1195207 | 2013-10-24 15:15:14 -0700 | [diff] [blame] | 328 | |
| 329 | // Put everything back how it was. |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 330 | ASSERT_EQ(0, sigaction_fn(sig, &original_sa, nullptr)); |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | TEST(signal, sigaction) { |
| 334 | TestSigAction(sigaction, sigaddset, SIGALRM); |
| 335 | } |
| 336 | |
| 337 | TEST(signal, sigaction64_SIGRTMIN) { |
| 338 | TestSigAction(sigaction64, sigaddset64, SIGRTMIN); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 339 | } |
Elliott Hughes | aa0ebda | 2014-02-11 19:57:06 -0800 | [diff] [blame] | 340 | |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 341 | static void ClearSignalMask() { |
| 342 | uint64_t sigset = 0; |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 343 | SignalSetAdd(&sigset, __SIGRTMIN); |
| 344 | if (syscall(__NR_rt_sigprocmask, SIG_SETMASK, &sigset, nullptr, sizeof(sigset)) != 0) { |
| 345 | abort(); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | static void FillSignalMask() { |
| 350 | uint64_t sigset = ~0ULL; |
| 351 | for (int signo = __SIGRTMIN + 1; signo < SIGRTMIN; ++signo) { |
| 352 | SignalSetDel(&sigset, signo); |
| 353 | } |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 354 | if (syscall(__NR_rt_sigprocmask, SIG_SETMASK, &sigset, nullptr, sizeof(sigset)) != 0) { |
| 355 | abort(); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | static uint64_t GetSignalMask() { |
| 360 | uint64_t sigset; |
| 361 | if (syscall(__NR_rt_sigprocmask, SIG_SETMASK, nullptr, &sigset, sizeof(sigset)) != 0) { |
| 362 | abort(); |
| 363 | } |
| 364 | return sigset; |
| 365 | } |
| 366 | |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 367 | static void TestSignalMaskFiltered(uint64_t sigset) { |
| 368 | #if defined(__BIONIC__) |
| 369 | for (int signo = __SIGRTMIN; signo < SIGRTMIN; ++signo) { |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 370 | bool signal_blocked = sigset & (1ULL << (signo - 1)); |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 371 | if (signo == __SIGRTMIN) { |
| 372 | // TIMER_SIGNAL must be blocked. |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 373 | EXPECT_EQ(true, signal_blocked) << "signal " << signo; |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 374 | } else { |
| 375 | // The other reserved signals must not be blocked. |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 376 | EXPECT_EQ(false, signal_blocked) << "signal " << signo; |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 377 | } |
| 378 | } |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 379 | #else |
| 380 | UNUSED(sigset); |
| 381 | #endif |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 384 | static void TestSignalMaskFunction(std::function<void()> fn) { |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 385 | ClearSignalMask(); |
| 386 | fn(); |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 387 | TestSignalMaskFiltered(GetSignalMask()); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | TEST(signal, sigaction_filter) { |
| 391 | ClearSignalMask(); |
| 392 | static uint64_t sigset; |
| 393 | struct sigaction sa = {}; |
| 394 | sa.sa_handler = [](int) { sigset = GetSignalMask(); }; |
| 395 | sigfillset(&sa.sa_mask); |
| 396 | sigaction(SIGUSR1, &sa, nullptr); |
| 397 | raise(SIGUSR1); |
| 398 | ASSERT_NE(0ULL, sigset); |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 399 | TestSignalMaskFiltered(sigset); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | TEST(signal, sigaction64_filter) { |
| 403 | ClearSignalMask(); |
| 404 | static uint64_t sigset; |
| 405 | struct sigaction64 sa = {}; |
| 406 | sa.sa_handler = [](int) { sigset = GetSignalMask(); }; |
| 407 | sigfillset64(&sa.sa_mask); |
| 408 | sigaction64(SIGUSR1, &sa, nullptr); |
| 409 | raise(SIGUSR1); |
| 410 | ASSERT_NE(0ULL, sigset); |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 411 | TestSignalMaskFiltered(sigset); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | TEST(signal, sigprocmask_setmask_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 415 | TestSignalMaskFunction([]() { |
| 416 | ClearSignalMask(); |
| 417 | sigset_t sigset_libc; |
| 418 | sigfillset(&sigset_libc); |
| 419 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &sigset_libc, nullptr)); |
| 420 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | TEST(signal, sigprocmask64_setmask_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 424 | TestSignalMaskFunction([]() { |
| 425 | ClearSignalMask(); |
| 426 | sigset64_t sigset_libc; |
| 427 | sigfillset64(&sigset_libc); |
| 428 | ASSERT_EQ(0, sigprocmask64(SIG_SETMASK, &sigset_libc, nullptr)); |
| 429 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | TEST(signal, pthread_sigmask_setmask_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 433 | TestSignalMaskFunction([]() { |
| 434 | ClearSignalMask(); |
| 435 | sigset_t sigset_libc; |
| 436 | sigfillset(&sigset_libc); |
| 437 | ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &sigset_libc, nullptr)); |
| 438 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | TEST(signal, pthread_sigmask64_setmask_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 442 | TestSignalMaskFunction([]() { |
| 443 | ClearSignalMask(); |
| 444 | sigset64_t sigset_libc; |
| 445 | sigfillset64(&sigset_libc); |
| 446 | ASSERT_EQ(0, pthread_sigmask64(SIG_SETMASK, &sigset_libc, nullptr)); |
| 447 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | TEST(signal, sigprocmask_block_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 451 | TestSignalMaskFunction([]() { |
| 452 | ClearSignalMask(); |
| 453 | sigset_t sigset_libc; |
| 454 | sigfillset(&sigset_libc); |
| 455 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &sigset_libc, nullptr)); |
| 456 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | TEST(signal, sigprocmask64_block_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 460 | TestSignalMaskFunction([]() { |
| 461 | ClearSignalMask(); |
| 462 | sigset64_t sigset_libc; |
| 463 | sigfillset64(&sigset_libc); |
| 464 | ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &sigset_libc, nullptr)); |
| 465 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | TEST(signal, pthread_sigmask_block_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 469 | TestSignalMaskFunction([]() { |
| 470 | ClearSignalMask(); |
| 471 | sigset_t sigset_libc; |
| 472 | sigfillset(&sigset_libc); |
| 473 | ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &sigset_libc, nullptr)); |
| 474 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | TEST(signal, pthread_sigmask64_block_filter) { |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 478 | TestSignalMaskFunction([]() { |
| 479 | ClearSignalMask(); |
| 480 | sigset64_t sigset_libc; |
| 481 | sigfillset64(&sigset_libc); |
| 482 | ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, &sigset_libc, nullptr)); |
| 483 | }); |
| 484 | } |
| 485 | |
| 486 | TEST(signal, sigprocmask_unblock_filter) { |
| 487 | TestSignalMaskFunction([]() { |
| 488 | FillSignalMask(); |
| 489 | sigset_t sigset_libc; |
| 490 | sigfillset(&sigset_libc); |
| 491 | ASSERT_EQ(0, sigprocmask(SIG_UNBLOCK, &sigset_libc, nullptr)); |
| 492 | }); |
| 493 | } |
| 494 | |
| 495 | TEST(signal, sigprocmask64_unblock_filter) { |
| 496 | TestSignalMaskFunction([]() { |
| 497 | FillSignalMask(); |
| 498 | sigset64_t sigset_libc; |
| 499 | sigfillset64(&sigset_libc); |
| 500 | ASSERT_EQ(0, sigprocmask64(SIG_UNBLOCK, &sigset_libc, nullptr)); |
| 501 | }); |
| 502 | } |
| 503 | |
| 504 | TEST(signal, pthread_sigmask_unblock_filter) { |
| 505 | TestSignalMaskFunction([]() { |
| 506 | FillSignalMask(); |
| 507 | sigset_t sigset_libc; |
| 508 | sigfillset(&sigset_libc); |
| 509 | ASSERT_EQ(0, pthread_sigmask(SIG_UNBLOCK, &sigset_libc, nullptr)); |
| 510 | }); |
| 511 | } |
| 512 | |
| 513 | TEST(signal, pthread_sigmask64_unblock_filter) { |
| 514 | TestSignalMaskFunction([]() { |
| 515 | FillSignalMask(); |
| 516 | sigset64_t sigset_libc; |
| 517 | sigfillset64(&sigset_libc); |
| 518 | ASSERT_EQ(0, pthread_sigmask64(SIG_UNBLOCK, &sigset_libc, nullptr)); |
| 519 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | // glibc filters out signals via sigfillset, not the actual underlying functions. |
| 523 | TEST(signal, sigset_filter) { |
| 524 | #if defined(__BIONIC__) |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 525 | TestSignalMaskFunction([]() { |
| 526 | for (int i = 1; i <= 64; ++i) { |
| 527 | sigset(i, SIG_HOLD); |
| 528 | } |
| 529 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 530 | #endif |
| 531 | } |
| 532 | |
| 533 | TEST(signal, sighold_filter) { |
| 534 | #if defined(__BIONIC__) |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 535 | TestSignalMaskFunction([]() { |
| 536 | for (int i = 1; i <= 64; ++i) { |
| 537 | sighold(i); |
| 538 | } |
| 539 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 540 | #endif |
| 541 | } |
| 542 | |
| 543 | #if defined(__BIONIC__) |
| 544 | // Not exposed via headers, but the symbols are available if you declare them yourself. |
| 545 | extern "C" int sigblock(int); |
| 546 | extern "C" int sigsetmask(int); |
| 547 | #endif |
| 548 | |
| 549 | TEST(signal, sigblock_filter) { |
| 550 | #if defined(__BIONIC__) |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 551 | TestSignalMaskFunction([]() { |
| 552 | sigblock(~0U); |
| 553 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 554 | #endif |
| 555 | } |
| 556 | |
| 557 | TEST(signal, sigsetmask_filter) { |
| 558 | #if defined(__BIONIC__) |
Josh Gao | baf20fc | 2018-10-08 17:28:07 -0700 | [diff] [blame^] | 559 | TestSignalMaskFunction([]() { |
| 560 | sigsetmask(~0U); |
| 561 | }); |
Josh Gao | 6fcba93 | 2018-02-09 13:38:32 -0800 | [diff] [blame] | 562 | #endif |
| 563 | } |
| 564 | |
Elliott Hughes | aa0ebda | 2014-02-11 19:57:06 -0800 | [diff] [blame] | 565 | TEST(signal, sys_signame) { |
Elliott Hughes | 671e236 | 2014-02-12 19:04:27 -0800 | [diff] [blame] | 566 | #if defined(__BIONIC__) |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 567 | ASSERT_TRUE(sys_signame[0] == nullptr); |
Elliott Hughes | aa0ebda | 2014-02-11 19:57:06 -0800 | [diff] [blame] | 568 | ASSERT_STREQ("HUP", sys_signame[SIGHUP]); |
| 569 | #else |
| 570 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 571 | #endif |
| 572 | } |
| 573 | |
| 574 | TEST(signal, sys_siglist) { |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 575 | ASSERT_TRUE(sys_siglist[0] == nullptr); |
Elliott Hughes | aa0ebda | 2014-02-11 19:57:06 -0800 | [diff] [blame] | 576 | ASSERT_STREQ("Hangup", sys_siglist[SIGHUP]); |
| 577 | } |
Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 578 | |
| 579 | TEST(signal, limits) { |
| 580 | // This comes from the kernel. |
| 581 | ASSERT_EQ(32, __SIGRTMIN); |
| 582 | |
| 583 | // We reserve a non-zero number at the bottom for ourselves. |
| 584 | ASSERT_GT(SIGRTMIN, __SIGRTMIN); |
| 585 | |
| 586 | // MIPS has more signals than everyone else. |
| 587 | #if defined(__mips__) |
| 588 | ASSERT_EQ(128, __SIGRTMAX); |
| 589 | #else |
| 590 | ASSERT_EQ(64, __SIGRTMAX); |
| 591 | #endif |
| 592 | |
| 593 | // We don't currently reserve any at the top. |
| 594 | ASSERT_EQ(SIGRTMAX, __SIGRTMAX); |
| 595 | } |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 596 | |
| 597 | static int g_sigqueue_signal_handler_call_count = 0; |
| 598 | |
| 599 | static void SigqueueSignalHandler(int signum, siginfo_t* info, void*) { |
| 600 | ASSERT_EQ(SIGALRM, signum); |
| 601 | ASSERT_EQ(SIGALRM, info->si_signo); |
| 602 | ASSERT_EQ(SI_QUEUE, info->si_code); |
| 603 | ASSERT_EQ(1, info->si_value.sival_int); |
| 604 | ++g_sigqueue_signal_handler_call_count; |
| 605 | } |
| 606 | |
| 607 | TEST(signal, sigqueue) { |
| 608 | ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO); |
| 609 | sigval_t sigval; |
| 610 | sigval.sival_int = 1; |
| 611 | errno = 0; |
| 612 | ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); |
| 613 | ASSERT_EQ(0, errno); |
| 614 | ASSERT_EQ(1, g_sigqueue_signal_handler_call_count); |
| 615 | } |
| 616 | |
Josh Gao | 726b63f | 2018-08-27 16:00:58 -0700 | [diff] [blame] | 617 | TEST(signal, pthread_sigqueue_self) { |
| 618 | ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO); |
| 619 | sigval_t sigval; |
| 620 | sigval.sival_int = 1; |
| 621 | errno = 0; |
| 622 | ASSERT_EQ(0, pthread_sigqueue(pthread_self(), SIGALRM, sigval)); |
| 623 | ASSERT_EQ(0, errno); |
| 624 | ASSERT_EQ(1, g_sigqueue_signal_handler_call_count); |
| 625 | } |
| 626 | |
| 627 | TEST(signal, pthread_sigqueue_other) { |
| 628 | ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO); |
| 629 | sigval_t sigval; |
| 630 | sigval.sival_int = 1; |
| 631 | |
| 632 | sigset_t mask; |
| 633 | sigfillset(&mask); |
| 634 | pthread_sigmask(SIG_SETMASK, &mask, nullptr); |
| 635 | pthread_t thread; |
| 636 | int rc = pthread_create(&thread, nullptr, |
| 637 | [](void*) -> void* { |
| 638 | sigset_t mask; |
| 639 | sigemptyset(&mask); |
| 640 | sigsuspend(&mask); |
| 641 | return nullptr; |
| 642 | }, |
| 643 | nullptr); |
| 644 | ASSERT_EQ(0, rc); |
| 645 | |
| 646 | errno = 0; |
| 647 | ASSERT_EQ(0, pthread_sigqueue(thread, SIGALRM, sigval)); |
| 648 | ASSERT_EQ(0, errno); |
| 649 | pthread_join(thread, nullptr); |
| 650 | ASSERT_EQ(1, g_sigqueue_signal_handler_call_count); |
| 651 | } |
| 652 | |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 653 | TEST(signal, sigwaitinfo) { |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 654 | SignalMaskRestorer smr; |
| 655 | |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 656 | // Block SIGALRM. |
| 657 | sigset_t just_SIGALRM; |
| 658 | sigemptyset(&just_SIGALRM); |
| 659 | sigaddset(&just_SIGALRM, SIGALRM); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 660 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr)); |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 661 | |
| 662 | // Raise SIGALRM. |
| 663 | sigval_t sigval; |
| 664 | sigval.sival_int = 1; |
| 665 | ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); |
| 666 | |
| 667 | // Get pending SIGALRM. |
| 668 | siginfo_t info; |
| 669 | errno = 0; |
| 670 | ASSERT_EQ(SIGALRM, sigwaitinfo(&just_SIGALRM, &info)); |
| 671 | ASSERT_EQ(0, errno); |
| 672 | ASSERT_EQ(SIGALRM, info.si_signo); |
| 673 | ASSERT_EQ(1, info.si_value.sival_int); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 674 | } |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 675 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 676 | TEST(signal, sigwaitinfo64_SIGRTMIN) { |
| 677 | SignalMaskRestorer smr; |
| 678 | |
| 679 | // Block SIGRTMIN. |
| 680 | sigset64_t just_SIGRTMIN; |
| 681 | sigemptyset64(&just_SIGRTMIN); |
| 682 | sigaddset64(&just_SIGRTMIN, SIGRTMIN); |
| 683 | ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr)); |
| 684 | |
| 685 | // Raise SIGRTMIN. |
| 686 | sigval_t sigval; |
| 687 | sigval.sival_int = 1; |
| 688 | ASSERT_EQ(0, sigqueue(getpid(), SIGRTMIN, sigval)); |
| 689 | |
| 690 | // Get pending SIGRTMIN. |
| 691 | siginfo_t info; |
| 692 | errno = 0; |
| 693 | ASSERT_EQ(SIGRTMIN, sigwaitinfo64(&just_SIGRTMIN, &info)); |
| 694 | ASSERT_EQ(0, errno); |
| 695 | ASSERT_EQ(SIGRTMIN, info.si_signo); |
| 696 | ASSERT_EQ(1, info.si_value.sival_int); |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | TEST(signal, sigtimedwait) { |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 700 | SignalMaskRestorer smr; |
| 701 | |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 702 | // Block SIGALRM. |
| 703 | sigset_t just_SIGALRM; |
| 704 | sigemptyset(&just_SIGALRM); |
| 705 | sigaddset(&just_SIGALRM, SIGALRM); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 706 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr)); |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 707 | |
| 708 | // Raise SIGALRM. |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 709 | sigval_t sigval = { .sival_int = 1 }; |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 710 | ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); |
| 711 | |
| 712 | // Get pending SIGALRM. |
| 713 | siginfo_t info; |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 714 | timespec timeout = { .tv_sec = 2, .tv_nsec = 0 }; |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 715 | errno = 0; |
| 716 | ASSERT_EQ(SIGALRM, sigtimedwait(&just_SIGALRM, &info, &timeout)); |
| 717 | ASSERT_EQ(0, errno); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 718 | } |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 719 | |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 720 | TEST(signal, sigtimedwait64_SIGRTMIN) { |
| 721 | SignalMaskRestorer smr; |
| 722 | |
| 723 | // Block SIGRTMIN. |
| 724 | sigset64_t just_SIGRTMIN; |
| 725 | sigemptyset64(&just_SIGRTMIN); |
| 726 | sigaddset64(&just_SIGRTMIN, SIGRTMIN); |
| 727 | ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr)); |
| 728 | |
| 729 | // Raise SIGALRM. |
| 730 | sigval_t sigval = { .sival_int = 1 }; |
| 731 | ASSERT_EQ(0, sigqueue(getpid(), SIGRTMIN, sigval)); |
| 732 | |
| 733 | // Get pending SIGALRM. |
| 734 | siginfo_t info; |
| 735 | timespec timeout = { .tv_sec = 2, .tv_nsec = 0 }; |
| 736 | errno = 0; |
| 737 | ASSERT_EQ(SIGRTMIN, sigtimedwait64(&just_SIGRTMIN, &info, &timeout)); |
| 738 | ASSERT_EQ(0, errno); |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static int64_t NanoTime() { |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 742 | timespec t; |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 743 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 744 | return static_cast<int64_t>(t.tv_sec) * 1000000000LL + t.tv_nsec; |
| 745 | } |
| 746 | |
| 747 | TEST(signal, sigtimedwait_timeout) { |
| 748 | // Block SIGALRM. |
| 749 | sigset_t just_SIGALRM; |
| 750 | sigemptyset(&just_SIGALRM); |
| 751 | sigaddset(&just_SIGALRM, SIGALRM); |
| 752 | sigset_t original_set; |
| 753 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set)); |
| 754 | |
| 755 | // Wait timeout. |
| 756 | int64_t start_time = NanoTime(); |
| 757 | siginfo_t info; |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 758 | timespec timeout = { .tv_sec = 0, .tv_nsec = 1000000 }; |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 759 | errno = 0; |
| 760 | ASSERT_EQ(-1, sigtimedwait(&just_SIGALRM, &info, &timeout)); |
| 761 | ASSERT_EQ(EAGAIN, errno); |
| 762 | ASSERT_GE(NanoTime() - start_time, 1000000); |
| 763 | |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 764 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, nullptr)); |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 765 | } |
Josh Gao | 61cf3f3 | 2016-03-08 15:27:15 -0800 | [diff] [blame] | 766 | |
| 767 | #if defined(__BIONIC__) |
| 768 | TEST(signal, rt_tgsigqueueinfo) { |
| 769 | // Test whether rt_tgsigqueueinfo allows sending arbitrary si_code values to self. |
| 770 | // If this fails, your kernel needs commit 66dd34a to be backported. |
| 771 | static constexpr char error_msg[] = |
| 772 | "\nPlease ensure that the following kernel patch has been applied:\n" |
| 773 | "* https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=66dd34ad31e5963d72a700ec3f2449291d322921\n"; |
| 774 | static siginfo received; |
| 775 | |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 776 | struct sigaction handler = {}; |
Josh Gao | 61cf3f3 | 2016-03-08 15:27:15 -0800 | [diff] [blame] | 777 | handler.sa_sigaction = [](int, siginfo_t* siginfo, void*) { received = *siginfo; }; |
| 778 | handler.sa_flags = SA_SIGINFO; |
| 779 | |
| 780 | ASSERT_EQ(0, sigaction(SIGUSR1, &handler, nullptr)); |
| 781 | |
Josh Gao | d787852 | 2016-03-14 18:15:15 -0700 | [diff] [blame] | 782 | siginfo sent; |
| 783 | memset(&sent, 0, sizeof(sent)); |
Josh Gao | 61cf3f3 | 2016-03-08 15:27:15 -0800 | [diff] [blame] | 784 | |
| 785 | sent.si_code = SI_TKILL; |
| 786 | ASSERT_EQ(0, syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), SIGUSR1, &sent)) |
| 787 | << "rt_tgsigqueueinfo failed: " << strerror(errno) << error_msg; |
| 788 | ASSERT_EQ(sent.si_code, received.si_code) << "rt_tgsigqueueinfo modified si_code, expected " |
| 789 | << sent.si_code << ", received " << received.si_code |
| 790 | << error_msg; |
| 791 | |
| 792 | sent.si_code = SI_USER; |
| 793 | ASSERT_EQ(0, syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), SIGUSR1, &sent)) |
| 794 | << "rt_tgsigqueueinfo failed: " << strerror(errno) << error_msg; |
| 795 | ASSERT_EQ(sent.si_code, received.si_code) << "rt_tgsigqueueinfo modified si_code, expected " |
| 796 | << sent.si_code << ", received " << received.si_code |
| 797 | << error_msg; |
| 798 | } |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 799 | #endif |
Josh Gao | c244fcb | 2016-03-29 14:34:03 -0700 | [diff] [blame] | 800 | |
Josh Gao | c244fcb | 2016-03-29 14:34:03 -0700 | [diff] [blame] | 801 | TEST(signal, sigset_size) { |
| 802 | // The setjmp implementations for ARM, AArch64, x86, and x86_64 assume that sigset_t can fit in a |
| 803 | // long. This is true because ARM and x86 have broken rt signal support, and AArch64 and x86_64 |
| 804 | // both have a SIGRTMAX defined as 64. |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 805 | #if defined(__arm__) || defined(__aarch64__) || defined(__i386__) || defined(__x86_64__) |
| 806 | #if defined(__BIONIC__) |
Josh Gao | c244fcb | 2016-03-29 14:34:03 -0700 | [diff] [blame] | 807 | static_assert(sizeof(sigset_t) <= sizeof(long), "sigset_t doesn't fit in a long"); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 808 | #endif |
| 809 | static_assert(sizeof(sigset64_t)*8 >= 64, "sigset64_t too small for real-time signals"); |
| 810 | #endif |
Josh Gao | c244fcb | 2016-03-29 14:34:03 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 813 | TEST(signal, sigignore_EINVAL) { |
| 814 | errno = 0; |
| 815 | ASSERT_EQ(-1, sigignore(99999)); |
| 816 | ASSERT_EQ(EINVAL, errno); |
| 817 | } |
| 818 | |
| 819 | TEST(signal, sigignore) { |
| 820 | errno = 0; |
| 821 | EXPECT_EQ(-1, sigignore(SIGKILL)); |
| 822 | EXPECT_EQ(errno, EINVAL); |
| 823 | |
| 824 | errno = 0; |
| 825 | EXPECT_EQ(-1, sigignore(SIGSTOP)); |
| 826 | EXPECT_EQ(errno, EINVAL); |
| 827 | |
| 828 | ScopedSignalHandler sigalrm{SIGALRM}; |
| 829 | ASSERT_EQ(0, sigignore(SIGALRM)); |
| 830 | |
| 831 | struct sigaction sa; |
| 832 | ASSERT_EQ(0, sigaction(SIGALRM, nullptr, &sa)); |
| 833 | EXPECT_EQ(SIG_IGN, sa.sa_handler); |
| 834 | } |
| 835 | |
| 836 | TEST(signal, sighold_EINVAL) { |
| 837 | errno = 0; |
| 838 | ASSERT_EQ(-1, sighold(99999)); |
| 839 | ASSERT_EQ(EINVAL, errno); |
| 840 | } |
| 841 | |
| 842 | TEST(signal, sigpause_EINVAL) { |
| 843 | errno = 0; |
| 844 | ASSERT_EQ(-1, sigpause(99999)); |
| 845 | ASSERT_EQ(EINVAL, errno); |
| 846 | } |
| 847 | |
| 848 | TEST(signal, sigrelse_EINVAL) { |
| 849 | errno = 0; |
| 850 | ASSERT_EQ(-1, sigpause(99999)); |
| 851 | ASSERT_EQ(EINVAL, errno); |
| 852 | } |
| 853 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 854 | static void TestSigholdSigpauseSigrelse(int sig) { |
| 855 | static int signal_handler_call_count = 0; |
| 856 | ScopedSignalHandler ssh{sig, [](int) { signal_handler_call_count++; }}; |
| 857 | SignalMaskRestorer mask_restorer; |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 858 | sigset_t set; |
| 859 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 860 | // sighold(SIGALRM/SIGRTMIN) should add SIGALRM/SIGRTMIN to the signal mask ... |
| 861 | ASSERT_EQ(0, sighold(sig)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 862 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set)); |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 863 | EXPECT_TRUE(sigismember(&set, sig)); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 864 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 865 | // ... preventing our SIGALRM/SIGRTMIN handler from running ... |
| 866 | raise(sig); |
| 867 | ASSERT_EQ(0, signal_handler_call_count); |
| 868 | // ... until sigpause(SIGALRM/SIGRTMIN) temporarily unblocks it. |
| 869 | ASSERT_EQ(-1, sigpause(sig)); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 870 | ASSERT_EQ(EINTR, errno); |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 871 | ASSERT_EQ(1, signal_handler_call_count); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 872 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 873 | if (sig >= SIGRTMIN && sizeof(void*) == 8) { |
| 874 | // But sigpause(SIGALRM/SIGRTMIN) shouldn't permanently unblock SIGALRM/SIGRTMIN. |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 875 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set)); |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 876 | EXPECT_TRUE(sigismember(&set, sig)); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 877 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 878 | // Whereas sigrelse(SIGALRM/SIGRTMIN) should. |
| 879 | ASSERT_EQ(0, sigrelse(sig)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 880 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set)); |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 881 | EXPECT_FALSE(sigismember(&set, sig)); |
| 882 | } else { |
| 883 | // sigismember won't work for SIGRTMIN on LP32. |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | TEST(signal, sighold_sigpause_sigrelse) { |
| 888 | TestSigholdSigpauseSigrelse(SIGALRM); |
| 889 | } |
| 890 | |
| 891 | TEST(signal, sighold_sigpause_sigrelse_RT) { |
| 892 | TestSigholdSigpauseSigrelse(SIGRTMIN); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | TEST(signal, sigset_EINVAL) { |
| 896 | errno = 0; |
| 897 | ASSERT_EQ(SIG_ERR, sigset(99999, SIG_DFL)); |
| 898 | ASSERT_EQ(EINVAL, errno); |
| 899 | } |
| 900 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 901 | TEST(signal, sigset_RT) { |
| 902 | static int signal_handler_call_count = 0; |
| 903 | auto signal_handler = [](int) { signal_handler_call_count++; }; |
| 904 | ScopedSignalHandler ssh{SIGRTMIN, signal_handler}; |
| 905 | SignalMaskRestorer mask_restorer; |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 906 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 907 | ASSERT_EQ(signal_handler, sigset(SIGRTMIN, SIG_HOLD)); |
| 908 | #if defined(__LP64__) |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 909 | sigset_t set; |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 910 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); |
| 911 | ASSERT_TRUE(sigismember(&set, SIGRTMIN)); |
| 912 | #endif |
| 913 | |
| 914 | ASSERT_EQ(SIG_HOLD, sigset(SIGRTMIN, signal_handler)); |
| 915 | ASSERT_EQ(signal_handler, sigset(SIGRTMIN, signal_handler)); |
| 916 | ASSERT_EQ(0, signal_handler_call_count); |
| 917 | raise(SIGRTMIN); |
| 918 | ASSERT_EQ(1, signal_handler_call_count); |
| 919 | } |
| 920 | |
| 921 | TEST(signal, sigset) { |
| 922 | static int signal_handler_call_count = 0; |
| 923 | auto signal_handler = [](int) { signal_handler_call_count++; }; |
| 924 | ScopedSignalHandler ssh{SIGALRM, signal_handler}; |
| 925 | SignalMaskRestorer mask_restorer; |
| 926 | |
| 927 | ASSERT_EQ(0, signal_handler_call_count); |
| 928 | raise(SIGALRM); |
| 929 | ASSERT_EQ(1, signal_handler_call_count); |
| 930 | |
| 931 | // Block SIGALRM so the next sigset(SIGARLM) call will return SIG_HOLD. |
| 932 | sigset_t set; |
| 933 | sigemptyset(&set); |
| 934 | sigaddset(&set, SIGALRM); |
| 935 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &set, nullptr)); |
| 936 | |
| 937 | sigemptyset(&set); |
| 938 | ASSERT_EQ(SIG_HOLD, sigset(SIGALRM, signal_handler)); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 939 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); |
| 940 | EXPECT_FALSE(sigismember(&set, SIGALRM)); |
| 941 | |
Elliott Hughes | 4b1c6e7 | 2018-01-24 18:54:38 -0800 | [diff] [blame] | 942 | ASSERT_EQ(signal_handler, sigset(SIGALRM, SIG_IGN)); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 943 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); |
| 944 | EXPECT_FALSE(sigismember(&set, SIGALRM)); |
| 945 | |
| 946 | ASSERT_EQ(SIG_IGN, sigset(SIGALRM, SIG_DFL)); |
| 947 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); |
| 948 | EXPECT_FALSE(sigismember(&set, SIGALRM)); |
| 949 | |
| 950 | ASSERT_EQ(SIG_DFL, sigset(SIGALRM, SIG_HOLD)); |
| 951 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); |
| 952 | EXPECT_TRUE(sigismember(&set, SIGALRM)); |
| 953 | } |
Elliott Hughes | 7532b32 | 2017-07-11 15:00:17 -0700 | [diff] [blame] | 954 | |
| 955 | TEST(signal, killpg_EINVAL) { |
| 956 | // POSIX leaves pgrp <= 1 undefined, but glibc fails with EINVAL for < 0 |
| 957 | // and passes 0 through to kill(2). |
| 958 | errno = 0; |
| 959 | ASSERT_EQ(-1, killpg(-1, SIGKILL)); |
| 960 | ASSERT_EQ(EINVAL, errno); |
| 961 | } |