Deadlock (busy loop) on panic/SIGSEGV case in Go API user code

Kagami Hiiragi <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
Hello.

With the recent SA_ONSTACK fix I get deadlock in this minimal Go example code:

```
package main
/*
#cgo pkg-config: GraphicsMagick
#include <magick/api.h>
*/
import "C"
import "fmt"
type A struct { b *B }
type B struct { c int }
func main() {
	C.InitializeMagick(nil)
	a := A{nil}
	fmt.Println(a.b.c)
}
```

Without SA_ONSTACK fix I get this output which is not normal Go panic too:
https://gist.github.com/f0f4a1b0e65021050f020b3d88b06aaa

Normal panic should look like this (comment "C.InitializeMagick(nil)" line):

```
$ go run gm.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x483937]

goroutine 1 [running]:
main.main()
	/home/kagami/gm.go:13 +0x27
exit status 2
```

Probably it's caused by violating some rules described at:
https://golang.org/pkg/os/signal/#hdr-Go_programs_that_use_cgo_or_SWIG

E.g. SA_RESTART and signal mask bits. Maybe it would be better to not redefine
"oldact"? I.e. make first sigaction call with act=NULL and don't re-set it in
case if it's non-empty.

It would be even better to not set any handlers for API users at all, unless
requested, but as you said before it might cause ABI change...

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.