Todd C. Miller wrote: > Here's a rewrite of my connect_sync() changes to use connect_wait() > instead. Unlike the version in the connect(2) manual, this one > returns EINTR when interrupted by a signal which is probably better.
> Index: usr.bin/ftp/fetch.c > =================================================================== > RCS file: /cvs/src/usr.bin/ftp/fetch.c,v > retrieving revision 1.148 > diff -u -p -u -r1.148 fetch.c > --- usr.bin/ftp/fetch.c 18 Aug 2016 16:23:06 -0000 1.148 > +++ usr.bin/ftp/fetch.c 19 Aug 2016 22:00:26 -0000 > @@ -557,8 +557,12 @@ noslash: > } > #endif /* !SMALL */ > > -again: > - if (connect_sync(s, res->ai_addr, res->ai_addrlen) < 0) { > + error = connect(s, res->ai_addr, res->ai_addrlen); > + while (error != 0) { > + if (errno == EINTR) { > + error = connect_wait(s); > + continue; > + } > save_errno = errno; > close(s); > errno = save_errno; continue; hmm. so I was trying to avoid the need for two different functions. I think there's a mental overhead to "do this, then maybe that". this loop reads very strangely to me. it's hard to mentally trace the code. it's not really a loop, just goto spelled with break and continue. there's a bug, too, since the existing continue wasn't replaced. now you need some break/continue the other loop dance.