-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Support] Re-raise external signals #125854
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
Conversation
@llvm/pr-subscribers-llvm-support Author: Guy David (guy-david) ChangesOtherwise, the handler "swallows" the signal and the process continues to execute. While this use case is peculiar, ignoring these signals entirely seems more odd. Full diff: https://github.com/llvm/llvm-project/pull/125854.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 2e7b467a14bbe2..388fff7d5c9dcf 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -80,7 +80,8 @@
using namespace llvm;
-static void SignalHandler(int Sig); // defined below.
+static void SignalHandler(int Sig, siginfo_t *Info,
+ void *Context); // defined below.
static void InfoSignalHandler(int Sig); // defined below.
using SignalHandlerFunctionType = void (*)();
@@ -313,8 +314,8 @@ static void RegisterHandlers() { // Not signal-safe.
switch (Kind) {
case SignalKind::IsKill:
- NewHandler.sa_handler = SignalHandler;
- NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
+ NewHandler.sa_sigaction = SignalHandler;
+ NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK | SA_SIGINFO;
break;
case SignalKind::IsInfo:
NewHandler.sa_handler = InfoSignalHandler;
@@ -370,7 +371,7 @@ void sys::CleanupOnSignal(uintptr_t Context) {
}
// The signal handler that runs.
-static void SignalHandler(int Sig) {
+static void SignalHandler(int Sig, siginfo_t *Info, void *Context) {
// Restore the signal behavior to default, so that the program actually
// crashes when we return and the signal reissues. This also ensures that if
// we crash in our signal handler that the program will terminate immediately
@@ -401,6 +402,11 @@ static void SignalHandler(int Sig) {
}
}
+ // Signal sent from another process, do not assume that continuing the
+ // execution would re-raise it.
+ if (Info->si_pid != getpid())
+ raise(Sig);
+
// Otherwise if it is a fault (like SEGV) run any handler.
llvm::sys::RunSignalHandlers();
@@ -468,8 +474,7 @@ void llvm::sys::AddSignalHandler(sys::SignalHandlerCallback FnPtr,
#if ENABLE_BACKTRACES && defined(HAVE_BACKTRACE) && \
(defined(__linux__) || defined(__FreeBSD__) || \
- defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \
- defined(__OpenBSD__) || defined(__DragonFly__))
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__))
struct DlIteratePhdrData {
void **StackTrace;
int depth;
|
I am maybe not the best one to review this. Perhaps @dwblaikie or @MaskRay can help finding another reviewer? |
f84d18a
to
83f5235
Compare
83f5235
to
a737a57
Compare
Yeah, not sure, sorry - bit outside my wheelhouse. I wonder if @d0k knows about this or knows someone who does... |
Could you state your motivation behind this change? Makes sense. I don't know why SIGQUIT in on the Kill list instead of Int list. Nevertheless, Kill/Int are handled similarly. If an external process raises SIGSEGV/SIGQUIT, the default action is termination. With the handler installed, the process should also terminate (by reraising the signal) after removing temporary files and invoking some handlers (for example, LLVM may dump It's strange that this
pattern isn't that common. (@cracauer for https://www.cons.org/cracauer/sigint.html :) This post probably could mention signals other than SIGINT/SIGQUIT ) (@emaste) |
Otherwise, the handler "swallows" the signal and the process continues to execute. While this use case is peculiar, ignoring these signals entirely seems more odd.
3162a7f
to
c70f573
Compare
Thanks! |
Otherwise, the handler "swallows" the signal and the process continues to execute. While this use case is peculiar, ignoring these signals entirely seems more odd.
Otherwise, the handler "swallows" the signal and the process continues to execute. While this use case is peculiar, ignoring these signals entirely seems more odd.
[cherry-pick] [Support] Re-raise external signals (llvm#125854)
Otherwise, the handler "swallows" the signal and the process continues to execute. While this use case is peculiar, ignoring these signals entirely seems more odd.