]> Cypherpunks repositories - gostls13.git/commitdiff
gc: graceful exit on seg fault
authorRuss Cox <rsc@golang.org>
Mon, 26 Jul 2010 23:52:51 +0000 (16:52 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 26 Jul 2010 23:52:51 +0000 (16:52 -0700)
R=ken2
CC=golang-dev
https://golang.org/cl/1882043

src/cmd/gc/lex.c

index 7c9fb07dd647c707bb6885358d4fa41f5ccb0da3..726cab7533b370398150f3fdbaf6cfd1c8c3dbce 100644 (file)
@@ -90,12 +90,27 @@ usage(void)
        exit(0);
 }
 
+void
+fault(int s)
+{
+       // If we've already complained about things
+       // in the program, don't bother complaining
+       // about the seg fault too; let the user clean up
+       // the code and try again.
+       if(nerrors > 0)
+               errorexit();
+       fatal("fault");
+}
+
 int
 main(int argc, char *argv[])
 {
        int i, c;
        NodeList *l;
        char *p;
+       
+       signal(SIGBUS, fault);
+       signal(SIGSEGV, fault);
 
        localpkg = mkpkg(strlit(""));
        localpkg->prefix = "\"\"";