svn commit: r236108 - stable/9/lib/libfetch
Dag-Erling Smorgrav
des at FreeBSD.org
Sat May 26 17:08:01 UTC 2012
Author: des
Date: Sat May 26 17:08:01 2012
New Revision: 236108
URL: http://svn.freebsd.org/changeset/base/236108
Log:
MFH r234837: avoid busy-loop on slow connections when no timeout is set.
MFH r234838: don't reuse credentials when redirected to a different host.
Modified:
stable/9/lib/libfetch/common.c
stable/9/lib/libfetch/http.c
Directory Properties:
stable/9/lib/libfetch/ (props changed)
Modified: stable/9/lib/libfetch/common.c
==============================================================================
--- stable/9/lib/libfetch/common.c Sat May 26 17:07:34 2012 (r236107)
+++ stable/9/lib/libfetch/common.c Sat May 26 17:08:01 2012 (r236108)
@@ -455,11 +455,9 @@ fetch_read(conn_t *conn, char *buf, size
struct timeval now, timeout, delta;
fd_set readfds;
ssize_t rlen, total;
- int r;
char *start;
- if (fetchTimeout) {
- FD_ZERO(&readfds);
+ if (fetchTimeout > 0) {
gettimeofday(&timeout, NULL);
timeout.tv_sec += fetchTimeout;
}
@@ -523,23 +521,21 @@ fetch_read(conn_t *conn, char *buf, size
return (-1);
}
// assert(rlen == FETCH_READ_WAIT);
- while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) {
+ FD_ZERO(&readfds);
+ while (!FD_ISSET(conn->sd, &readfds)) {
FD_SET(conn->sd, &readfds);
- gettimeofday(&now, NULL);
- delta.tv_sec = timeout.tv_sec - now.tv_sec;
- delta.tv_usec = timeout.tv_usec - now.tv_usec;
- if (delta.tv_usec < 0) {
- delta.tv_usec += 1000000;
- delta.tv_sec--;
- }
- if (delta.tv_sec < 0) {
- errno = ETIMEDOUT;
- fetch_syserr();
- return (-1);
+ if (fetchTimeout > 0) {
+ gettimeofday(&now, NULL);
+ if (!timercmp(&timeout, &now, >)) {
+ errno = ETIMEDOUT;
+ fetch_syserr();
+ return (-1);
+ }
+ timersub(&timeout, &now, &delta);
}
errno = 0;
- r = select(conn->sd + 1, &readfds, NULL, NULL, &delta);
- if (r == -1) {
+ if (select(conn->sd + 1, &readfds, NULL, NULL,
+ fetchTimeout > 0 ? &delta : NULL) < 0) {
if (errno == EINTR) {
if (fetchRestartCalls)
continue;
Modified: stable/9/lib/libfetch/http.c
==============================================================================
--- stable/9/lib/libfetch/http.c Sat May 26 17:07:34 2012 (r236107)
+++ stable/9/lib/libfetch/http.c Sat May 26 17:08:01 2012 (r236108)
@@ -1779,7 +1779,9 @@ http_request(struct url *URL, const char
DEBUG(fprintf(stderr, "failed to parse new URL\n"));
goto ouch;
}
- if (!*new->user && !*new->pwd) {
+
+ /* Only copy credentials if the host matches */
+ if (!strcmp(new->host, url->host) && !*new->user && !*new->pwd) {
strcpy(new->user, url->user);
strcpy(new->pwd, url->pwd);
}
More information about the svn-src-stable-9
mailing list