diff options
Diffstat (limited to 'libgo/misc/cgo/testcarchive/main3.c')
-rw-r--r-- | libgo/misc/cgo/testcarchive/main3.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libgo/misc/cgo/testcarchive/main3.c b/libgo/misc/cgo/testcarchive/main3.c index 0a6c0d3f74e..60a16cf5fc4 100644 --- a/libgo/misc/cgo/testcarchive/main3.c +++ b/libgo/misc/cgo/testcarchive/main3.c @@ -11,6 +11,7 @@ #include <string.h> #include <time.h> #include <sched.h> +#include <unistd.h> #include "libgo3.h" @@ -25,6 +26,31 @@ static void ioHandler(int signo, siginfo_t* info, void* ctxt) { sigioSeen = 1; } +// Set up the SIGPIPE signal handler in a high priority constructor, so +// that it is installed before the Go code starts. + +static void pipeHandler(int signo, siginfo_t* info, void* ctxt) { + const char *s = "unexpected SIGPIPE\n"; + write(2, s, strlen(s)); + exit(EXIT_FAILURE); +} + +static void init(void) __attribute__ ((constructor (200))); + +static void init() { + struct sigaction sa; + + memset(&sa, 0, sizeof sa); + sa.sa_sigaction = pipeHandler; + if (sigemptyset(&sa.sa_mask) < 0) { + die("sigemptyset"); + } + sa.sa_flags = SA_SIGINFO; + if (sigaction(SIGPIPE, &sa, NULL) < 0) { + die("sigaction"); + } +} + int main(int argc, char** argv) { int verbose; struct sigaction sa; @@ -35,6 +61,14 @@ int main(int argc, char** argv) { setvbuf(stdout, NULL, _IONBF, 0); if (verbose) { + printf("raising SIGPIPE\n"); + } + + // Test that the Go runtime handles SIGPIPE, even if we installed + // a non-default SIGPIPE handler before the runtime initializes. + ProvokeSIGPIPE(); + + if (verbose) { printf("calling sigaction\n"); } |