From: hno <> Date: Mon, 3 Mar 2003 06:13:48 +0000 (+0000) Subject: Cleanup of errno management to rely on the errno to be sent by X-Git-Tag: SQUID_3_0_PRE1~290 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3400a9388ead45c99f81f600ba2dbad3c456ffc;p=thirdparty%2Fsquid.git Cleanup of errno management to rely on the errno to be sent by the comm code rather than assuming it is kept intact in errno. Due to the comm callback queue there may be a significant delay and relying on errno is quite likely to get it wrong --- diff --git a/src/client_side.cc b/src/client_side.cc index 47462d88b6..cdcff821f9 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.626 2003/02/23 00:08:03 robertc Exp $ + * $Id: client_side.cc,v 1.627 2003/03/02 23:13:48 hno Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -206,7 +206,7 @@ static int connGetAvailableBufferLength(ConnStateData const *conn); static void connMakeSpaceAvailable(ConnStateData * conn); static void connAddContextToQueue(ConnStateData * conn, ClientSocketContext * context); static int connGetConcurrentRequestCount(ConnStateData * conn); -static int connReadWasError(ConnStateData * conn, comm_err_t, int size); +static int connReadWasError(ConnStateData * conn, comm_err_t, int size, int xerrno); static int connFinishedWithConn(ConnStateData * conn, int size); static void connNoteUseOfBuffer(ConnStateData * conn, size_t byteCount); static int connKeepReadingIncompleteRequest(ConnStateData * conn); @@ -1932,7 +1932,7 @@ connGetConcurrentRequestCount(ConnStateData * conn) } int -connReadWasError(ConnStateData * conn, comm_err_t flag, int size) +connReadWasError(ConnStateData * conn, comm_err_t flag, int size, int xerrno) { if (flag != COMM_OK) { debug(50, 2) ("connReadWasError: FD %d: got flag %d\n", conn->fd, flag); @@ -1940,12 +1940,12 @@ connReadWasError(ConnStateData * conn, comm_err_t flag, int size) } if (size < 0) { - if (!ignoreErrno(errno)) { - debug(50, 2) ("connReadWasError: FD %d: %s\n", conn->fd, xstrerror()); + if (!ignoreErrno(xerrno)) { + debug(50, 2) ("connReadWasError: FD %d: %s\n", conn->fd, xstrerr(xerrno)); return 1; } else if (conn->in.notYetUsed == 0) { debug(50, 2) ("connReadWasError: FD %d: no data to process (%s)\n", - conn->fd, xstrerror()); + conn->fd, xstrerr(xerrno)); } } @@ -2220,7 +2220,7 @@ clientReadRequest(int fd, char *buf, size_t size, comm_err_t flag, int xerrno, * whole, not individual read() calls. Plus, it breaks our * lame half-close detection */ - if (connReadWasError(conn, flag, size)) { + if (connReadWasError(conn, flag, size, xerrno)) { comm_close(fd); return; } @@ -2614,9 +2614,8 @@ httpAccept(int sock, int newfd, ConnectionDetail *details, /* XXX we're not considering httpAcceptDefer yet! */ if (flag != COMM_OK) { - errno = xerrno; debug(50, 1) ("httpAccept: FD %d: accept failure: %s\n", - sock, xstrerror()); + sock, xstrerr(xerrno)); return; } @@ -2727,7 +2726,7 @@ httpsAccept(int sock, int newfd, ConnectionDetail *details, if (flag != COMM_OK) { errno = xerrno; debug(50, 1) ("httpsAccept: FD %d: accept failure: %s\n", - sock, xstrerror()); + sock, xstrerr(xerrno)); return; } diff --git a/src/comm.cc b/src/comm.cc index b0a111eecd..174b9bd7cd 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.366 2003/02/21 22:50:07 robertc Exp $ + * $Id: comm.cc,v 1.367 2003/03/02 23:13:49 hno Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -85,7 +85,7 @@ static PF commConnectFree; static PF commConnectHandle; static PF commHandleWrite; static IPH commConnectDnsHandle; -static void commConnectCallback(ConnectStateData * cs, comm_err_t status); +static void commConnectCallback(ConnectStateData * cs, comm_err_t status, int xerrno); static int commResetFD(ConnectStateData * cs); static int commRetryConnect(ConnectStateData * cs); CBDATA_TYPE(ConnectStateData); @@ -429,7 +429,7 @@ comm_calliocallback(void) * Queue a callback */ static void -comm_read_callback(int fd, int retval, comm_err_t errcode, int xerrno) +comm_read_callback(int fd, size_t retval, comm_err_t errcode, int xerrno) { fdc_t *Fc = &fdc_table[fd]; @@ -465,7 +465,7 @@ comm_read_try(int fd, void *data) if (retval < 0 && !ignoreErrno(errno)) { debug(5, 3) ("comm_read_try: scheduling COMM_ERROR\n"); - comm_read_callback(fd, -1, COMM_ERROR, errno); + comm_read_callback(fd, 0, COMM_ERROR, errno); return; }; @@ -1083,7 +1083,7 @@ commConnectDnsHandle(const ipcache_addrs * ia, void *data) } assert(dns_error_message != NULL); - commConnectCallback(cs, COMM_ERR_DNS); + commConnectCallback(cs, COMM_ERR_DNS, 0); return; } @@ -1096,7 +1096,7 @@ commConnectDnsHandle(const ipcache_addrs * ia, void *data) } static void -commConnectCallback(ConnectStateData * cs, comm_err_t status) +commConnectCallback(ConnectStateData * cs, comm_err_t status, int xerrno) { CNCB *callback = cs->callback; void *cbdata = cs->data; @@ -1109,7 +1109,7 @@ commConnectCallback(ConnectStateData * cs, comm_err_t status) commConnectFree(fd, cs); if (cbdataReferenceValid(cbdata)) - callback(fd, status, cbdata); + callback(fd, status, xerrno, cbdata); cbdataReferenceDone(cbdata); } @@ -1244,7 +1244,7 @@ commConnectHandle(int fd, void *data) case COMM_OK: ipcacheMarkGoodAddr(cs->host, cs->S.sin_addr); - commConnectCallback(cs, COMM_OK); + commConnectCallback(cs, COMM_OK, 0); break; default: @@ -1258,7 +1258,7 @@ commConnectHandle(int fd, void *data) cs->locks++; ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs); } else { - commConnectCallback(cs, COMM_ERR_CONNECT); + commConnectCallback(cs, COMM_ERR_CONNECT, errno); } break; diff --git a/src/forward.cc b/src/forward.cc index e5000b9147..29eb34f562 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -1,6 +1,6 @@ /* - * $Id: forward.cc,v 1.99 2003/02/25 12:24:35 robertc Exp $ + * $Id: forward.cc,v 1.100 2003/03/02 23:13:49 hno Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -339,7 +339,7 @@ fwdInitiateSSL(FwdState * fwdState) #endif static void -fwdConnectDone(int server_fd, comm_err_t status, void *data) +fwdConnectDone(int server_fd, comm_err_t status, int xerrno, void *data) { FwdState *fwdState = (FwdState *)data; FwdServer *fs = fwdState->servers; @@ -375,7 +375,7 @@ fwdConnectDone(int server_fd, comm_err_t status, void *data) } else if (status != COMM_OK) { assert(fs); err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE); - err->xerrno = errno; + err->xerrno = xerrno; if (fs->_peer) { err->host = xstrdup(fs->_peer->host); diff --git a/src/ftp.cc b/src/ftp.cc index 7010a4bdd0..397f998537 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.343 2003/02/23 00:08:04 robertc Exp $ + * $Id: ftp.cc,v 1.344 2003/03/02 23:13:49 hno Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -215,7 +215,7 @@ static IOWCB ftpDataWriteCallback; static PF ftpStateFree; static PF ftpTimeout; static IOCB ftpReadControlReply; -static CWCB ftpWriteCommandCallback; +static IOWCB ftpWriteCommandCallback; static void ftpLoginParser(const char *, FtpStateData *, int escaped); static wordlist *ftpParseControlReply(char *, size_t, int *, int *); static int ftpRestartable(FtpStateData * ftpState); @@ -226,8 +226,8 @@ static void ftpUnhack(FtpStateData * ftpState); static void ftpScheduleReadControlReply(FtpStateData *, int); static void ftpHandleControlReply(FtpStateData *); static char *ftpHtmlifyListEntry(const char *line, FtpStateData * ftpState); -static void ftpFailed(FtpStateData *, err_type); -static void ftpFailedErrorMessage(FtpStateData *, err_type); +static void ftpFailed(FtpStateData *, err_type, int xerrno); +static void ftpFailedErrorMessage(FtpStateData *, err_type, int xerrno); /* * State machine functions @@ -438,7 +438,7 @@ ftpTimeout(int fd, void *data) debug(9, 1) ("ftpTimeout: timeout in SENT_PASV state\n"); } - ftpFailed(ftpState, ERR_READ_TIMEOUT); + ftpFailed(ftpState, ERR_READ_TIMEOUT, 0); /* ftpFailed closes ctrl.fd and frees ftpState */ } @@ -1158,9 +1158,9 @@ ftpDataRead(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *da } if (flag != COMM_OK || len < 0) { - debug(50, ignoreErrno(errno) ? 3 : 1) ("ftpDataRead: read error: %s\n", xstrerror()); + debug(50, ignoreErrno(xerrno) ? 3 : 1) ("ftpDataRead: read error: %s\n", xstrerr(xerrno)); - if (ignoreErrno(errno)) { + if (ignoreErrno(xerrno)) { /* XXX what about Config.Timeout.read? */ read_sz = ftpState->data.size - ftpState->data.offset; #if DELAY_POOLS @@ -1170,7 +1170,7 @@ ftpDataRead(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *da comm_read(fd, ftpState->data.buf + ftpState->data.offset, read_sz, ftpDataRead, data); } else { - ftpFailed(ftpState, ERR_READ_ERROR); + ftpFailed(ftpState, ERR_READ_ERROR, 0); /* ftpFailed closes ctrl.fd and frees ftpState */ return; } @@ -1407,19 +1407,19 @@ ftpWriteCommand(const char *buf, FtpStateData * ftpState) safe_free(ftpState->ctrl.last_command); safe_free(ftpState->ctrl.last_reply); ftpState->ctrl.last_command = xstrdup(buf); - comm_old_write(ftpState->ctrl.fd, - xstrdup(buf), - strlen(buf), - ftpWriteCommandCallback, - ftpState, - xfree); + comm_write(ftpState->ctrl.fd, + xstrdup(buf), + strlen(buf), + ftpWriteCommandCallback, + ftpState); ftpScheduleReadControlReply(ftpState, 0); } static void -ftpWriteCommandCallback(int fd, char *bufnotused, size_t size, comm_err_t errflag, void *data) +ftpWriteCommandCallback(int fd, char *buf, size_t size, comm_err_t errflag, int xerrno, void *data) { FtpStateData *ftpState = (FtpStateData *)data; + xfree(buf); debug(9, 7) ("ftpWriteCommandCallback: wrote %d bytes\n", (int) size); if (size > 0) { @@ -1432,8 +1432,8 @@ ftpWriteCommandCallback(int fd, char *bufnotused, size_t size, comm_err_t errfla return; if (errflag) { - debug(9, 1) ("ftpWriteCommandCallback: FD %d: %s\n", fd, xstrerror()); - ftpFailed(ftpState, ERR_WRITE_ERROR); + debug(9, 1) ("ftpWriteCommandCallback: FD %d: %s\n", fd, xstrerr(xerrno)); + ftpFailed(ftpState, ERR_WRITE_ERROR, xerrno); /* ftpFailed closes ctrl.fd and frees ftpState */ return; } @@ -1581,12 +1581,12 @@ ftpReadControlReply(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, debug(9, 5) ("ftpReadControlReply: FD %d, Read %d bytes\n", fd, (int)len); if (flag != COMM_OK || len < 0) { - debug(50, ignoreErrno(errno) ? 3 : 1) ("ftpReadControlReply: read error: %s\n", xstrerror()); + debug(50, ignoreErrno(xerrno) ? 3 : 1) ("ftpReadControlReply: read error: %s\n", xstrerr(xerrno)); - if (ignoreErrno(errno)) { + if (ignoreErrno(xerrno)) { ftpScheduleReadControlReply(ftpState, 0); } else { - ftpFailed(ftpState, ERR_READ_ERROR); + ftpFailed(ftpState, ERR_READ_ERROR, xerrno); /* ftpFailed closes ctrl.fd and frees ftpState */ return; } @@ -1596,7 +1596,7 @@ ftpReadControlReply(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, if (len == 0) { if (entry->store_status == STORE_PENDING) { - ftpFailed(ftpState, ERR_FTP_FAILURE); + ftpFailed(ftpState, ERR_FTP_FAILURE, 0); /* ftpFailed closes ctrl.fd and frees ftpState */ return; } @@ -2204,7 +2204,7 @@ ftpReadPasv(FtpStateData * ftpState) } static void -ftpPasvCallback(int fd, comm_err_t status, void *data) +ftpPasvCallback(int fd, comm_err_t status, int xerrno, void *data) { FtpStateData *ftpState = (FtpStateData *)data; debug(9, 3) ("ftpPasvCallback\n"); @@ -2213,7 +2213,7 @@ ftpPasvCallback(int fd, comm_err_t status, void *data) debug(9, 2) ("ftpPasvCallback: failed to connect. Retrying without PASV.\n"); ftpState->fwd->flags.dont_retry = 0; /* this is a retryable error */ ftpState->fwd->flags.ftp_pasv_failed = 1; - ftpFailed(ftpState, ERR_NONE); + ftpFailed(ftpState, ERR_NONE, 0); /* ftpFailed closes ctrl.fd and frees ftpState */ return; } @@ -2359,8 +2359,7 @@ ftpAcceptDataConnection(int fd, int newfd, ConnectionDetail *details, } if (flag != COMM_OK) { - errno = xerrno; - debug(9, 1) ("ftpHandleDataAccept: comm_accept(%d): %s", newfd, xstrerror()); + debug(9, 1) ("ftpHandleDataAccept: comm_accept(%d): %s", newfd, xstrerr(xerrno)); /* XXX Need to set error message */ ftpFail(ftpState); return; @@ -2665,7 +2664,7 @@ ftpReadTransferDone(FtpStateData * ftpState) } else { /* != 226 */ debug(9, 1) ("ftpReadTransferDone: Got code %d after reading data\n", code); - ftpFailed(ftpState, ERR_FTP_FAILURE); + ftpFailed(ftpState, ERR_FTP_FAILURE, 0); /* ftpFailed closes ctrl.fd and frees ftpState */ return; } @@ -2685,7 +2684,7 @@ ftpRequestBody(char *buf, ssize_t size, void *data) } else if (size < 0) { /* Error */ debug(9, 1) ("ftpRequestBody: request aborted"); - ftpFailed(ftpState, ERR_READ_ERROR); + ftpFailed(ftpState, ERR_READ_ERROR, 0); } else if (size == 0) { /* End of transfer */ ftpDataComplete(ftpState); @@ -2702,8 +2701,8 @@ ftpDataWriteCallback(int fd, char *buf, size_t size, comm_err_t err, int xerrno, /* Shedule the rest of the request */ clientReadBody(ftpState->request, ftpState->data.buf, ftpState->data.size, ftpRequestBody, ftpState); } else { - debug(9, 1) ("ftpDataWriteCallback: write error: %s\n", xstrerror()); - ftpFailed(ftpState, ERR_WRITE_ERROR); + debug(9, 1) ("ftpDataWriteCallback: write error: %s\n", xstrerr(xerrno)); + ftpFailed(ftpState, ERR_WRITE_ERROR, xerrno); } } @@ -2725,7 +2724,7 @@ ftpWriteTransferDone(FtpStateData * ftpState) if (code != 226) { debug(9, 1) ("ftpReadTransferDone: Got code %d after sending data\n", code); - ftpFailed(ftpState, ERR_FTP_PUT_ERROR); + ftpFailed(ftpState, ERR_FTP_PUT_ERROR, 0); return; } @@ -2872,17 +2871,17 @@ ftpFail(FtpStateData * ftpState) } } - ftpFailed(ftpState, ERR_NONE); + ftpFailed(ftpState, ERR_NONE, 0); /* ftpFailed closes ctrl.fd and frees ftpState */ } static void -ftpFailed(FtpStateData * ftpState, err_type error) +ftpFailed(FtpStateData * ftpState, err_type error, int xerrno) { StoreEntry *entry = ftpState->entry; if (entry->isEmpty()) - ftpFailedErrorMessage(ftpState, error); + ftpFailedErrorMessage(ftpState, error, xerrno); if (ftpState->data.fd > -1) { comm_close(ftpState->data.fd); @@ -2893,7 +2892,7 @@ ftpFailed(FtpStateData * ftpState, err_type error) } static void -ftpFailedErrorMessage(FtpStateData * ftpState, err_type error) +ftpFailedErrorMessage(FtpStateData * ftpState, err_type error, int xerrno) { ErrorState *err; const char *command, *reply; @@ -2943,7 +2942,7 @@ ftpFailedErrorMessage(FtpStateData * ftpState, err_type error) if (err == NULL) err = errorCon(ERR_FTP_FAILURE, HTTP_BAD_GATEWAY); - err->xerrno = errno; + err->xerrno = xerrno; err->request = requestLink(ftpState->request); diff --git a/src/ident.cc b/src/ident.cc index 41790e94bb..7a6e7da50e 100644 --- a/src/ident.cc +++ b/src/ident.cc @@ -1,6 +1,6 @@ /* - * $Id: ident.cc,v 1.67 2003/02/23 00:08:04 robertc Exp $ + * $Id: ident.cc,v 1.68 2003/03/02 23:13:49 hno Exp $ * * DEBUG: section 30 Ident (RFC 931) * AUTHOR: Duane Wessels @@ -110,7 +110,7 @@ identTimeout(int fd, void *data) } static void -identConnectDone(int fd, comm_err_t status, void *data) +identConnectDone(int fd, comm_err_t status, int xerrno, void *data) { IdentStateData *state = (IdentStateData *)data; IdentClient *c; diff --git a/src/neighbors.cc b/src/neighbors.cc index 2058a03a3c..558cc7ff32 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,6 +1,6 @@ /* - * $Id: neighbors.cc,v 1.318 2003/02/23 00:08:04 robertc Exp $ + * $Id: neighbors.cc,v 1.319 2003/03/02 23:13:49 hno Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -1416,7 +1416,7 @@ peerProbeConnect2(const ipcache_addrs * ianotused, void *data) } static void -peerProbeConnectDone(int fd, comm_err_t status, void *data) +peerProbeConnectDone(int fd, comm_err_t status, int xerrno, void *data) { peer *p = (peer*)data; diff --git a/src/tunnel.cc b/src/tunnel.cc index 6181db8ab2..1308dc3103 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -1,6 +1,6 @@ /* - * $Id: tunnel.cc,v 1.139 2003/03/02 23:10:22 hno Exp $ + * $Id: tunnel.cc,v 1.140 2003/03/02 23:13:49 hno Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -403,7 +403,7 @@ sslErrorComplete(int fdnotused, void *data, size_t sizenotused) static void -sslConnectDone(int fdnotused, comm_err_t status, void *data) +sslConnectDone(int fdnotused, comm_err_t status, int xerrno, void *data) { SslStateData *sslState = (SslStateData *)data; request_t *request = sslState->request; @@ -431,7 +431,7 @@ sslConnectDone(int fdnotused, comm_err_t status, void *data) } else if (status != COMM_OK) { err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE); *sslState->status_ptr = HTTP_SERVICE_UNAVAILABLE; - err->xerrno = errno; + err->xerrno = xerrno; err->host = xstrdup(sslState->host); err->port = sslState->port; err->request = requestLink(request); diff --git a/src/typedefs.h b/src/typedefs.h index 0e845cac80..b80f4ee944 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.155 2003/02/25 15:07:54 hno Exp $ + * $Id: typedefs.h,v 1.156 2003/03/02 23:13:49 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -284,7 +284,8 @@ typedef struct _snmp_request_t snmp_request_t; #endif typedef void CWCB(int fd, char *, size_t size, comm_err_t flag, void *data); -typedef void CNCB(int fd, comm_err_t status, void *); +typedef void CNCB(int fd, comm_err_t status, int xerrno, void *data); + typedef void IOCB(int fd, char *, size_t size, comm_err_t flag, int xerrno, void *data); typedef void FREE(void *);