-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[sanitizer_common] AND signals in BlockSignals instead of deleting #113443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
0672505
d510d43
e8f090e
d46231d
9ad1184
fa0a6f7
a0b2a1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//===-- sanitizer_block_signals.cpp ---------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of sanitizer_common unit tests. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include <signal.h> | ||
#include <stdio.h> | ||
|
||
#include "gtest/gtest.h" | ||
#include "sanitizer_common/sanitizer_linux.h" | ||
|
||
namespace __sanitizer { | ||
|
||
#if SANITIZER_LINUX | ||
volatile int received_sig = -1; | ||
|
||
void signal_handler(int signum) { received_sig = signum; } | ||
|
||
TEST(SanitizerCommon, BlockSignals) { | ||
// No signals blocked | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of large test with 3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
{ | ||
signal(SIGUSR1, signal_handler); | ||
raise(SIGUSR1); | ||
while (received_sig == -1) sleep(1); | ||
EXPECT_EQ(received_sig, SIGUSR1); | ||
|
||
received_sig = -1; | ||
signal(SIGPIPE, signal_handler); | ||
raise(SIGPIPE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to sleep? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
while (received_sig == -1) sleep(1); | ||
EXPECT_EQ(received_sig, SIGPIPE); | ||
} | ||
|
||
// ScopedBlockSignals; SIGUSR1 should be blocked but not SIGPIPE | ||
{ | ||
__sanitizer_sigset_t sigset = {}; | ||
ScopedBlockSignals block(&sigset); | ||
|
||
received_sig = -1; | ||
signal(SIGUSR1, signal_handler); | ||
raise(SIGUSR1); | ||
sleep(1); | ||
EXPECT_EQ(received_sig, -1); | ||
|
||
received_sig = -1; | ||
signal(SIGPIPE, signal_handler); | ||
raise(SIGPIPE); | ||
while (received_sig == -1) sleep(1); | ||
EXPECT_EQ(received_sig, SIGPIPE); | ||
} | ||
while (received_sig == -1) sleep(1); | ||
EXPECT_EQ(received_sig, SIGUSR1); | ||
|
||
// Manually block SIGPIPE; ScopedBlockSignals should not unblock this | ||
sigset_t block_sigset; | ||
sigemptyset(&block_sigset); | ||
sigaddset(&block_sigset, SIGPIPE); | ||
sigprocmask(SIG_BLOCK, &block_sigset, NULL); | ||
{ | ||
__sanitizer_sigset_t sigset = {}; | ||
ScopedBlockSignals block(&sigset); | ||
|
||
received_sig = -1; | ||
signal(SIGPIPE, signal_handler); | ||
raise(SIGPIPE); | ||
sleep(1); | ||
EXPECT_EQ(received_sig, -1); | ||
} | ||
sigprocmask(SIG_UNBLOCK, &block_sigset, NULL); | ||
while (received_sig == -1) sleep(1); | ||
EXPECT_EQ(received_sig, SIGPIPE); | ||
} | ||
#endif // SANITIZER_LINUX | ||
|
||
} // namespace __sanitizer |
Uh oh!
There was an error while loading. Please reload this page.