From: wessels <> Date: Tue, 3 Jun 1997 01:55:58 +0000 (+0000) Subject: purifying X-Git-Tag: SQUID_3_0_PRE1~4957 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f88211e8cc111f07ed717c4e8404c6020b4eb9d0;p=thirdparty%2Fsquid.git purifying --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index ebe897f16e..2214e0e2a7 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,5 +1,5 @@ /* - * $Id: cache_cf.cc,v 1.194 1997/06/01 04:23:09 wessels Exp $ + * $Id: cache_cf.cc,v 1.195 1997/06/02 19:55:58 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -1399,7 +1399,7 @@ configSetFactoryDefaults(void) Config.Ftp.icon_suffix = safe_xstrdup(DefaultFtpIconSuffix); Config.Ftp.list_width = DefaultFtpListWidth; Config.Ftp.list_wrap = DefaultFtpListWrap; - Config.Ftp.anon_user = DefaultFtpAnonUser; + Config.Ftp.anon_user = safe_xstrdup(DefaultFtpAnonUser); } static void diff --git a/src/comm.cc b/src/comm.cc index becef70fca..e9ffa856bf 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.157 1997/06/02 01:06:10 wessels Exp $ + * $Id: comm.cc,v 1.158 1997/06/02 19:55:59 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -129,12 +129,23 @@ struct _cwstate { void (*free) (void *); }; +typedef struct { + char *host; + u_short port; + struct sockaddr_in S; + CNCB *callback; + void *data; + int tries; + struct in_addr in_addr; + int locks; +} ConnectStateData; + /* GLOBAL */ FD_ENTRY *fd_table = NULL; /* also used in disk.c */ /* STATIC */ static int commBind _PARAMS((int s, struct in_addr, u_short port)); -#ifndef HAVE_POLL +#if !HAVE_POLL static int examine_select _PARAMS((fd_set *, fd_set *)); #endif static void checkTimeouts _PARAMS((void)); @@ -150,11 +161,12 @@ static void CommWriteStateCallbackAndFree _PARAMS((int fd, int code)); static void commSetTcpNoDelay _PARAMS((int)); #endif static void commSetTcpRcvbuf _PARAMS((int, int)); -static void commConnectFree _PARAMS((int fd, void *data)); +static PF commConnectFree; static void commConnectHandle _PARAMS((int fd, void *data)); static void commHandleWrite _PARAMS((int fd, void *data)); static int fdIsHttpOrIcp _PARAMS((int fd)); static IPH commConnectDnsHandle; +static void commConnectCallback _PARAMS((int fd, ConnectStateData *cs, int status)); static struct timeval zero_tv; @@ -321,6 +333,7 @@ commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void * cs->callback = callback; cs->data = data; comm_add_close_handler(fd, commConnectFree, cs); + cs->locks++; ipcache_nbgethostbyname(host, fd, commConnectDnsHandle, cs); } @@ -328,28 +341,42 @@ static void commConnectDnsHandle(int fd, const ipcache_addrs * ia, void *data) { ConnectStateData *cs = data; + assert(cs->locks == 1); + cs->locks--; if (ia == NULL) { debug(5, 3, "commConnectDnsHandle: Unknown host: %s\n", cs->host); - cs->callback(fd, COMM_ERR_DNS, cs->data); + commConnectCallback(fd, cs, COMM_ERR_DNS); return; } cs->in_addr = ia->in_addrs[ia->cur]; commConnectHandle(fd, cs); } +static void +commConnectCallback(int fd, ConnectStateData *cs, int status) +{ + CNCB *callback = cs->callback; + void *data = cs->data; + comm_remove_close_handler(fd, commConnectFree, cs); + commConnectFree(fd, cs); + callback(fd, status, data); +} + static void commConnectFree(int fd, void *data) { ConnectStateData *cs = data; + if (cs->locks) + ipcacheUnregister(cs->host, cs); xfree(cs->host); xfree(cs); } static int -commRetryConnect(int fd, ConnectStateData * connectState) +commRetryConnect(int fd, ConnectStateData * cs) { int fd2; - if (++connectState->tries == 4) + if (++cs->tries == 4) return 0; fd2 = socket(AF_INET, SOCK_STREAM, 0); if (fd2 < 0) { @@ -369,41 +396,35 @@ commRetryConnect(int fd, ConnectStateData * connectState) static void commConnectHandle(int fd, void *data) { - ConnectStateData *connectState = data; - if (connectState->S.sin_addr.s_addr == 0) { - connectState->S.sin_family = AF_INET; - connectState->S.sin_addr = connectState->in_addr; - connectState->S.sin_port = htons(connectState->port); + ConnectStateData *cs = data; + if (cs->S.sin_addr.s_addr == 0) { + cs->S.sin_family = AF_INET; + cs->S.sin_addr = cs->in_addr; + cs->S.sin_port = htons(cs->port); if (Config.Log.log_fqdn) - fqdncache_gethostbyaddr(connectState->S.sin_addr, FQDN_LOOKUP_IF_MISS); + fqdncache_gethostbyaddr(cs->S.sin_addr, FQDN_LOOKUP_IF_MISS); } - switch (comm_connect_addr(fd, &connectState->S)) { + switch (comm_connect_addr(fd, &cs->S)) { case COMM_INPROGRESS: - commSetSelect(fd, - COMM_SELECT_WRITE, - commConnectHandle, - (void *) connectState, - 0); + commSetSelect(fd, COMM_SELECT_WRITE, commConnectHandle, cs, 0); break; case COMM_OK: if (vizSock > -1) - vizHackSendPkt(&connectState->S, 2); - ipcacheCycleAddr(connectState->host); - connectState->callback(fd, COMM_OK, connectState->data); + vizHackSendPkt(&cs->S, 2); + ipcacheCycleAddr(cs->host); + commConnectCallback(fd, cs, COMM_OK); break; default: - if (commRetryConnect(fd, connectState)) { - debug(5, 3, "Retrying connection to %s: %s\n", - connectState->host, xstrerror()); - connectState->S.sin_addr.s_addr = 0; - ipcacheCycleAddr(connectState->host); - ipcache_nbgethostbyname(connectState->host, - fd, - commConnectDnsHandle, - connectState); + if (commRetryConnect(fd, cs)) { + debug(5, 1, "Retrying connection to %s: %s\n", + cs->host, xstrerror()); + cs->S.sin_addr.s_addr = 0; + ipcacheCycleAddr(cs->host); + cs->locks++; + ipcache_nbgethostbyname(cs->host, fd, commConnectDnsHandle, cs); } else { - ipcacheRemoveBadAddr(connectState->host, connectState->S.sin_addr); - connectState->callback(fd, COMM_ERR_CONNECT, connectState->data); + ipcacheRemoveBadAddr(cs->host, cs->S.sin_addr); + commConnectCallback(fd, cs, COMM_ERR_CONNECT); } break; } @@ -632,7 +653,7 @@ comm_set_stall(int fd, int delta) } -#ifdef HAVE_POLL +#if HAVE_POLL /* poll() version by: * Stewart Forster , and @@ -779,7 +800,7 @@ fdIsHttpOrIcp(int fd) return 0; } -#ifdef HAVE_POLL +#if HAVE_POLL /* poll all sockets; call handlers for those that are ready. */ int comm_poll(time_t sec) @@ -1096,15 +1117,13 @@ comm_add_close_handler(int fd, PF * handler, void *data) void comm_remove_close_handler(int fd, PF * handler, void *data) { - struct close_handler *p, *last = NULL; - + struct close_handler *p; + struct close_handler *last = NULL; /* Find handler in list */ for (p = fd_table[fd].close_handler; p != NULL; last = p, p = p->next) if (p->handler == handler && p->data == data) break; /* This is our handler */ - if (!p) - fatal_dump("comm_remove_close_handler: Handler not found!\n"); - + assert(p != NULL); /* Remove list entry */ if (last) last->next = p->next; @@ -1239,7 +1258,7 @@ comm_init(void) } -#ifndef HAVE_POLL +#if !HAVE_POLL /* * examine_select - debug routine. * diff --git a/src/disk.cc b/src/disk.cc index 74fe3875b7..6c7b2b9d32 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -1,5 +1,5 @@ /* - * $Id: disk.cc,v 1.70 1997/05/22 15:51:51 wessels Exp $ + * $Id: disk.cc,v 1.71 1997/06/02 19:56:01 wessels Exp $ * * DEBUG: section 6 Disk I/O Routines * AUTHOR: Harvest Derived @@ -205,12 +205,9 @@ file_open_complete(void *data, int fd, int errcode) void file_close(int fd) { - FD_ENTRY *fde = NULL; - if (fd < 0) - fatal_dump("file_close: bad file number"); - fde = &fd_table[fd]; - if (!fde->open) - fatal_dump("file_close: already closed"); + FD_ENTRY *fde = &fd_table[fd]; + assert(fd >= 0); + assert(fde->open); if (BIT_TEST(fde->flags, FD_WRITE_DAEMON)) { BIT_SET(fde->flags, FD_CLOSE_REQUEST); return; diff --git a/src/ftp.cc b/src/ftp.cc index bb13b9cbd1..0ed1b0684d 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.117 1997/06/02 17:19:25 wessels Exp $ + * $Id: ftp.cc,v 1.118 1997/06/02 19:56:01 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -182,8 +182,8 @@ ftpStateFree(int fd, void *data) FtpStateData *ftpState = data; if (ftpState == NULL) return; - storeUnlockObject(ftpState->entry); storeUnregisterAbort(ftpState->entry); + storeUnlockObject(ftpState->entry); if (ftpState->reply_hdr) { put_free_8k_page(ftpState->reply_hdr); ftpState->reply_hdr = NULL; diff --git a/src/gopher.cc b/src/gopher.cc index f24d35b971..93d472b789 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,5 +1,5 @@ /* - * $Id: gopher.cc,v 1.82 1997/06/02 05:39:44 wessels Exp $ + * $Id: gopher.cc,v 1.83 1997/06/02 19:56:02 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -191,8 +191,8 @@ gopherStateFree(int fd, void *data) if (gopherState == NULL) return; if (gopherState->entry) { - storeUnlockObject(gopherState->entry); storeUnregisterAbort(gopherState->entry); + storeUnlockObject(gopherState->entry); } put_free_4k_page(gopherState->buf); xfree(gopherState); diff --git a/src/http.cc b/src/http.cc index 26092efc62..726a8a41a7 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.167 1997/06/02 05:39:45 wessels Exp $ + * $Id: http.cc,v 1.168 1997/06/02 19:56:03 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -216,8 +216,8 @@ httpStateFree(int fd, void *data) HttpStateData *httpState = data; if (httpState == NULL) return; - storeUnlockObject(httpState->entry); storeUnregisterAbort(httpState->entry); + storeUnlockObject(httpState->entry); if (httpState->reply_hdr) { put_free_8k_page(httpState->reply_hdr); httpState->reply_hdr = NULL; diff --git a/src/store_dir.cc b/src/store_dir.cc index 457a7274ba..10ae731e38 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -343,6 +343,7 @@ storeDirOpenTmpSwapLog(int dirn, int *clean_flag) debug(50, 0, "%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); } + memset(&clean_sb, '\0', sizeof(struct stat)); if (stat(clean_path, &clean_sb) < 0) *clean_flag = 0; else if (clean_sb.st_mtime < log_sb.st_mtime) diff --git a/src/wais.cc b/src/wais.cc index 5c6b839d98..5a5743df3b 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,6 +1,6 @@ /* - * $Id: wais.cc,v 1.74 1997/06/02 05:39:51 wessels Exp $ + * $Id: wais.cc,v 1.75 1997/06/02 19:56:04 wessels Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -132,8 +132,8 @@ waisStateFree(int fd, void *data) WaisStateData *waisState = data; if (waisState == NULL) return; - storeUnlockObject(waisState->entry); storeUnregisterAbort(waisState->entry); + storeUnlockObject(waisState->entry); xfree(waisState); }