On Friday, May 21, 2021 at 10:22:08 PM UTC+2 Ian Lance Taylor wrote:

> On Fri, May 21, 2021 at 7:49 AM Manlio Perillo <manlio....@gmail.com> 
> wrote: 
> > 
> > In a program I want to read a password from the terminal, using 
> golang.org/x/term. 
> > The problem is that there is a possibility that a signal is sent to the 
> program, resulting in the terminal state not being restored: 
> > https://play.golang.org/p/4IjLve9gDx0 
> > 
> > In case of term.ReadPassword, on Linux I noted that ECHO is restored, 
> but let's ignore it. 
> > 
> > What I tried to do was to ttemporarily block the signals, using 
> signal.Ignore and signal.Reset; the problem is that Reset doesn't reset 
> ignored signals. 
> > 
> > Looking at the runtime code, Go only use SIG_DFL in special cases. 
> > Is there a reason why Reset don't reset ignore signals? Portability? 
> > 
> > Is there a simple, portable way, to do what I want? 
>
> I thought that signal.Reset would reset a signal ignored by 
> signal.Ignore. What happens when you try it? 
>
>
In https://play.golang.org/p/c88iu09mOgO,  the SIGINT signal (via Ctrl-C) 
is ignored after the call to `signal.Ignore`.
However SIGINT is still ignored after the call to `signal.Reset`.
 

> In any case I don't see why your program wants to ignore signals. It 
> seems better to catch the signal, restore the terminal, and exit. 
>
>
In some C/C++ programs I have often see the use sigprocmask:
https://www.gnu.org/software/libc/manual/html_node/Why-Block.html

I think that it is more convenient to ignore all signals, since I don't 
need to specify each signal explicitly (requiring the use of build tags for 
portability).
However it is true that in this simple case (a command line program), the 
only signal to handle is SIGINT.

Thanks
Manlio 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/75a18ef2-573e-4f14-86aa-84347f8ea59bn%40googlegroups.com.

Reply via email to