by jacobsa@google.com:
(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.)
by jacobsa@google.com:
(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.)