Fix bug #79411 Connect with invalid password exits

The problem was that write was called on closed sockets. That caused
SIGPIPE signals that weren't handled.

It is fixed by introducing write_ignore_pipe_signal() that sets up a
short-lived signal handler SIGPIPE that simply ignores the signal
while write() is called.

write_ignore_pipe_signal() is now called everywhere that write() used to
be called directly.