[compiler-rt] [sanitizer_common] AND signals in BlockSignals instead of deleting (PR #113443)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 14:25:43 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 2c5208a2dc4aaa5615e6c19e3f417f4727f4b65b d46231d6936ccfcd8a5fd61affdd414c60941361 --extensions cpp -- compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp
index 391b122ba4..e5b98fc3d7 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp
@@ -9,79 +9,73 @@
// This file is a part of sanitizer_common unit tests.
//
//===----------------------------------------------------------------------===//
-#include "gtest/gtest.h"
-#include "sanitizer_common/sanitizer_linux.h"
#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;
-}
+void signal_handler(int signum) { received_sig = signum; }
TEST(SanitizerCommon, BlockSignals) {
- // No signals blocked
- {
- signal (SIGUSR1, signal_handler);
- raise (SIGUSR1);
- while (received_sig == -1)
- sleep(1);
- EXPECT_EQ(received_sig, SIGUSR1);
+ // No signals blocked
+ {
+ 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);
- while (received_sig == -1)
- sleep(1);
- EXPECT_EQ(received_sig, SIGPIPE);
- }
+ received_sig = -1;
+ signal(SIGPIPE, signal_handler);
+ raise(SIGPIPE);
+ 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);
+ // 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(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);
+ 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);
+ // 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);
+ 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
+#endif // SANITIZER_LINUX
} // namespace __sanitizer
``````````
</details>
https://github.com/llvm/llvm-project/pull/113443
More information about the llvm-commits
mailing list