diff options
| author | Elias Naur <elias.naur@gmail.com> | 2017-08-19 16:59:19 +0200 |
|---|---|---|
| committer | Elias Naur <elias.naur@gmail.com> | 2017-08-29 07:40:19 +0000 |
| commit | c3189cee717a47dd7936d9f82904db72b28293f6 (patch) | |
| tree | e3fc16aff861b031fec26f74f79ed10ce085ff5a /src/runtime/testdata | |
| parent | 176cd48e574817bbb912c139396324c187b31279 (diff) | |
| download | go-c3189cee717a47dd7936d9f82904db72b28293f6.tar.xz | |
runtime: forward crashing signals to late handlers
CL 49590 made it possible for external signal handlers to catch
signals from a crashing Go process. This CL extends that support
to handlers registered after the Go runtime has initialized.
Updates #20392 (and possibly fix it).
Change-Id: I18eccd5e958a505f4d1782a7fc51c16bd3a4ff9c
Reviewed-on: https://go-review.googlesource.com/57291
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/testdata')
| -rw-r--r-- | src/runtime/testdata/testprogcgo/catchpanic.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/runtime/testdata/testprogcgo/catchpanic.go b/src/runtime/testdata/testprogcgo/catchpanic.go index f03b6d3ea3..55a606d1bc 100644 --- a/src/runtime/testdata/testprogcgo/catchpanic.go +++ b/src/runtime/testdata/testprogcgo/catchpanic.go @@ -17,17 +17,21 @@ static void abrthandler(int signum) { } } -static void __attribute__ ((constructor)) sigsetup(void) { +void registerAbortHandler() { struct sigaction act; - - if (getenv("CGOCATCHPANIC_INSTALL_HANDLER") == NULL) - return; memset(&act, 0, sizeof act); act.sa_handler = abrthandler; sigaction(SIGABRT, &act, NULL); } + +static void __attribute__ ((constructor)) sigsetup(void) { + if (getenv("CGOCATCHPANIC_EARLY_HANDLER") == NULL) + return; + registerAbortHandler(); +} */ import "C" +import "os" func init() { register("CgoCatchPanic", CgoCatchPanic) @@ -35,5 +39,8 @@ func init() { // Test that the SIGABRT raised by panic can be caught by an early signal handler. func CgoCatchPanic() { + if _, ok := os.LookupEnv("CGOCATCHPANIC_EARLY_HANDLER"); !ok { + C.registerAbortHandler() + } panic("catch me") } |
