=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.154 retrieving revision 1.155 diff -u -r1.154 -r1.155 --- src/usr.bin/ftp/fetch.c 2016/12/28 17:48:04 1.154 +++ src/usr.bin/ftp/fetch.c 2017/01/03 17:00:04 1.155 @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.154 2016/12/28 17:48:04 deraadt Exp $ */ +/* $OpenBSD: fetch.c,v 1.155 2017/01/03 17:00:04 deraadt Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -167,6 +167,14 @@ return (epath); } +/* ARGSUSED */ +static void +tooslow(int signo) +{ + dprintf(STDERR_FILENO, "%s: connect taking too long\n", __progname); + _exit(2); +} + /* * Retrieve URL, via the proxy in $proxyvar if necessary. * Modifies the string argument given. @@ -560,6 +568,11 @@ } #endif /* !SMALL */ + if (connect_timeout) { + (void)signal(SIGALRM, tooslow); + alarmtimer(connect_timeout); + } + for (error = connect(s, res->ai_addr, res->ai_addrlen); error != 0 && errno == EINTR; error = connect_wait(s)) continue; @@ -626,6 +639,11 @@ #else /* !NOSSL */ fin = fdopen(s, "r+"); #endif /* !NOSSL */ + + if (connect_timeout) { + signal(SIGALRM, SIG_DFL); + alarmtimer(0); + } /* * Construct and send the request. Proxy requests don't want leading /.