On Mon, Jun 6, 2016 at 8:00 PM, James Chacon <
chacon...@gmail.com> wrote:
> [...]
>>> I agree but you're suggesting conflicting arguments here. Evidently
>>>
golang.org/x/crypto/ssh/terminal is allowed to change global state (terminal
>>> echo) but isn't allowed to then setup a mechanism to replace that state upon
>>> abnormal exit?
>>>
>>> It's either one or the other here. Either it should be enabling a signal
>>> handler (with chaining) to do proper cleanup
>>
>>
>> > [...]
>>
>> The problem is that the library function does know what signals it should
>> be handle. Moreover some goroutine may cause program termination, and the
>> cleanup code will not be called.
>>
>
> "The program may terminate" is a nice strawman but irrelevant. Under normal
> circumstances (i.e. not crashing) the library should be returning the state
> of the system to how it started. This means handling normal termination
> (i.e. ^C/INTR situations) cleanly too. Only the library knows what it did
> here so main can't reasonably be expected to deal with half state scenarios.
>
By normal termination I mean when the program terminates by returning from main.
In this case each each function executed in the program returns, and
deferred are called.
By abnormal termination I mean when some goroutine calls os.Exit.
In this case functions running concurrently at the time os.Exit is
called will not have deferred functions called.
Now, when you handle a signal, you usually call os.Exit in a goroutine
(unless you want to ignore the signal).
But the same may happen when some goroutine (defined in the main
package, I hope) calls, as an example, log.Fatal.
The ReadPassword function simply does not have this information.
Registering a SIGINT handler does not solve the problem in the general
case, unless the program have only one goroutine.
Manlio