Currently, TestCgoSigfwd will pass incorrectly if the SIGSEGV that
originates in Go mistakenly goes to the C SIGSEGV handler. Fix this by
adding a signal-atomic variable that tracks what the expected behavior
is.
Change-Id: Id2a9fa3b209299dccf90bb60720b89ad96838a9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/443072
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
#include <stdio.h>
#include <string.h>
+sig_atomic_t expectCSigsegv;
int *sigfwdP;
+
static void sigsegv() {
+ expectCSigsegv = 1;
*sigfwdP = 1;
fprintf(stderr, "ERROR: C SIGSEGV not thrown on caught?.\n");
exit(2);
static void segvhandler(int signum) {
if (signum == SIGSEGV) {
+ if (expectCSigsegv == 0) {
+ fprintf(stderr, "SIGSEGV caught in C unexpectedly\n");
+ exit(1);
+ }
fprintf(stdout, "OK\n");
exit(0); // success
}