jlmucb / cloudproxy

The CloudProxy Tao for Trustworthy Computing
Apache License 2.0
37 stars 11 forks source link

Signal handling and return status in Go #22

Closed cjpatton closed 9 years ago

cjpatton commented 9 years ago

See go/apps/mixnet/mixnet_router/mixnet_router.go:90 for related TODO. To handle signals in Go, one creates a chan os.Signal and run a go routine that waits on that channel. So we free up any resources that need to be freed and call os.Exit(), which accepts as input a byte conveying the exit status to the OS. We would like this status to reflect the type of signal that was captured, but the os.Signal interface provides no means for getting at the signal number. This is less a CloudProxy issue and more an issue of the os.Signal interface.

kevinawalsh commented 9 years ago

You can indeed access the signal number. os.Signal is the generic interface type used for the signal mechanism. We are always running on linux, where the concrete type will be syscall.Signal, which converts directly to int. So:

signum := int(sig.(syscall.Signal))

Or if you are paranoid:

signum := syscall.SIGINT; // some reasonable default? if s, ok := sig.(syscall.Signal); ok { signum = int(s) }

cjpatton commented 9 years ago

Thanks, John, that's immensely helpful.