util: password: Reverse the nonblocking stdin

It's not clear if this is absolutely necessary or not, but it probably
doesn't hurt. It's not clear if there is a way to read the previous
state before running this. Of course this isn't really thread-safe, so
use at your own risk.
This commit is contained in:
James Shubin
2023-09-29 22:13:14 -04:00
parent 738485a655
commit ab7eb0a293

View File

@@ -69,7 +69,8 @@ func ReadPasswordCtxFdPrompt(ctx context.Context, fd int, prompt string) ([]byte
if err := syscall.SetNonblock(fd, true); err != nil { if err := syscall.SetNonblock(fd, true); err != nil {
return nil, err return nil, err
} }
file := os.NewFile(uintptr(fd), "") // XXX: name? defer syscall.SetNonblock(fd, false) // TODO: is this necessary?
file := os.NewFile(uintptr(fd), "") // XXX: name?
// We do some term magic to not print the password. This is taken from: // We do some term magic to not print the password. This is taken from:
// golang.org/x/term/term_unix.go:readPassword // golang.org/x/term/term_unix.go:readPassword