You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Note: I am not an old hand with signals, and may be missing something obvious
here. Please be gentle.)
As I understand it, if I say
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
then I have forever disabled the default SIGINT handler, even if I close the
channel and never touch it. It would be nice if there were a way to declare to
the signal package that I no longer am interested in a signal, similar to
calling signal(3) with SIG_DFL.
I came across this issue when using this package for reading passwords without
echoing:
http://code.google.com/p/gopass/source/browse/gopass.go
(Admittedly this package's implementation is hacky. I couldn't find a better
way to do this though. Calling getpass(3) using cgo screwed up signal handling
even worse, as far as I can tell.)
The package installs a temporary SIGINT handler that turns terminal echoing
back on before exiting when a signal is received. It returns from this handler
when it's done reading a password though, and the net effect is that after
calling GetPass once, SIGINT never again works except while calling GetPass
another time.
If I control all of the code in my program then I can keep my signal handler
running and emulating the default handler. But this is a bit annoying, and I
can't think of any way for a library developer to do it correctly. (If the
library developer chooses to do this, she may interfere with some other
library developer who is intentionally trying to suppress SIGINT, for
example.)
The text was updated successfully, but these errors were encountered:
In case my rambling above wasn't clear, here's an example:
package main
import (
"os"
"os/signal"
)
func main() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
select {}
}
Run `go build signal.go && ./signal`, then observe you can't stop it using
Ctrl-C. This is a stupid case, but the "suppress SIGINT temporarily but not
forever from a library" thing maybe isn't.
I'd suggest to add another function to the package that removes the handler from the
list and returns the channel that was previously used for this signal, so a library may
restore a user-defined handler. This shouldn't be too hard to implement; I'll try it
later.
by jacobsa@google.com:
The text was updated successfully, but these errors were encountered: