-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: when dying from a signal use the previous signal handler
Before this CL, whenever the Go runtime wanted to kill its own process with a signal dieFromSignal would reset the signal handler to _SIG_DFL. Unfortunately, if any signal handler were installed before the Go runtime initialized, it wouldn't be invoked either. Instead, use whatever signal handler was installed before initialization. The motivating use case is Crashlytics on Android. Before this CL, Crashlytics would not consider a crash from a panic() since the corresponding SIGABRT never reached its signal handler. Updates #11382 Updates #20392 (perhaps even fixes it) Fixes #19389 Change-Id: I0c8633329433b45cbb3b16571bea227e38e8be2e Reviewed-on: https://go-review.googlesource.com/49590 Run-TryBot: Elias Naur <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
- Loading branch information
Elias Naur
committed
Aug 10, 2017
1 parent
7d80a2e
commit 5500c9c
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build !plan9,!windows | ||
|
||
package main | ||
|
||
/* | ||
#include <signal.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
static void abrthandler(int signum) { | ||
if (signum == SIGABRT) { | ||
exit(0); // success | ||
} | ||
} | ||
static void __attribute__ ((constructor)) sigsetup(void) { | ||
struct sigaction act; | ||
if (getenv("CGOCATCHPANIC_INSTALL_HANDLER") == NULL) | ||
return; | ||
memset(&act, 0, sizeof act); | ||
act.sa_handler = abrthandler; | ||
sigaction(SIGABRT, &act, NULL); | ||
} | ||
*/ | ||
import "C" | ||
|
||
func init() { | ||
register("CgoCatchPanic", CgoCatchPanic) | ||
} | ||
|
||
// Test that the SIGABRT raised by panic can be caught by an early signal handler. | ||
func CgoCatchPanic() { | ||
panic("catch me") | ||
} |