From: wessels <> Date: Tue, 26 Aug 1997 04:35:50 +0000 (+0000) Subject: Misc fixes to eliminate problems at exit (and other things) X-Git-Tag: SQUID_3_0_PRE1~4811 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e102ebd;p=thirdparty%2Fsquid.git Misc fixes to eliminate problems at exit (and other things) - changed storeDirCloseSwapLogs() to take a 'reopen' arg. if not set, we don't reopen the logs for writing again. - added FD_CLOSING flag to avoid recursive calls to comm_close(). - added 'non_peers' structure to keep stats on offendors, instead of logging every bad reply. --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index aeb53a2e69..d77eb77532 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,5 +1,5 @@ /* - * $Id: cache_cf.cc,v 1.222 1997/08/25 15:55:22 wessels Exp $ + * $Id: cache_cf.cc,v 1.223 1997/08/25 22:35:50 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -1129,4 +1129,3 @@ configFreeMemory(void) { free_all(); } - diff --git a/src/cachemgr.cc b/src/cachemgr.cc index ef1fb92e66..6c2094add6 100644 --- a/src/cachemgr.cc +++ b/src/cachemgr.cc @@ -1,7 +1,6 @@ - /* - * $Id: cachemgr.cc,v 1.58 1997/08/25 15:55:22 wessels Exp $ + * $Id: cachemgr.cc,v 1.59 1997/08/25 22:35:51 wessels Exp $ * * DEBUG: section 0 CGI Cache Manager * AUTHOR: Harvest Derived diff --git a/src/client.cc b/src/client.cc index 7a827a8906..e614e7f4df 100644 --- a/src/client.cc +++ b/src/client.cc @@ -1,7 +1,6 @@ - /* - * $Id: client.cc,v 1.27 1997/08/25 03:52:18 wessels Exp $ + * $Id: client.cc,v 1.28 1997/08/25 22:35:51 wessels Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived diff --git a/src/comm.cc b/src/comm.cc index 25880e924e..9a78fa5b01 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,5 +1,5 @@ /* - * $Id: comm.cc,v 1.185 1997/08/10 06:34:27 wessels Exp $ + * $Id: comm.cc,v 1.186 1997/08/25 22:35:52 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -117,15 +117,6 @@ #define min(x,y) ((x)<(y)? (x) : (y)) #define max(a,b) ((a)>(b)? (a) : (b)) -struct _cwstate { - char *buf; - long size; - long offset; - CWCB *handler; - void *handler_data; - void (*free) (void *); -}; - typedef struct { char *host; u_short port; @@ -166,16 +157,6 @@ static void commConnectCallback _PARAMS((ConnectStateData * cs, int status)); static struct timeval zero_tv; -void -commCancelWriteHandler(int fd) -{ - CommWriteStateData *CommWriteState = fd_table[fd].rwstate; - if (CommWriteState) { - CommWriteState->handler = NULL; - CommWriteState->handler_data = NULL; - } -} - static void CommWriteStateCallbackAndFree(int fd, int code) { @@ -579,8 +560,11 @@ comm_close(int fd) assert(fd >= 0); assert(fd < Squid_MaxFD); F = &fd_table[fd]; + if (BIT_TEST(F->flags, FD_CLOSING)) + return; assert(F->open); assert(F->type != FD_FILE); + BIT_SET(F->flags, FD_CLOSING); CommWriteStateCallbackAndFree(fd, COMM_ERROR); commCallCloseHandlers(fd); if (F->uses) /* assume persistent connect count */ @@ -591,7 +575,6 @@ comm_close(int fd) #else close(fd); #endif - memset(F, '\0', sizeof(fde)); } diff --git a/src/defines.h b/src/defines.h index d3bcb8b1c8..6cf05db3f1 100644 --- a/src/defines.h +++ b/src/defines.h @@ -65,6 +65,7 @@ #define FD_CLOSE_REQUEST 0x02 #define FD_WRITE_DAEMON 0x04 #define FD_WRITE_PENDING 0x08 +#define FD_CLOSING 0x10 #define FD_DESC_SZ 64 diff --git a/src/enums.h b/src/enums.h index 10b4296d41..94ee29a75d 100644 --- a/src/enums.h +++ b/src/enums.h @@ -139,6 +139,7 @@ typedef enum { MGR_REMOVE, MGR_REPLY_HDRS, MGR_SERVER_LIST, + MGR_NON_PEERS, MGR_SHUTDOWN, MGR_UTILIZATION, MGR_VM_OBJECTS, diff --git a/src/errorpage.cc b/src/errorpage.cc index 9e6f45a869..72ca7dbb23 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.68 1997/08/25 02:38:52 wessels Exp $ + * $Id: errorpage.cc,v 1.69 1997/08/25 22:35:54 wessels Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -151,7 +151,7 @@ errorConvert(char token, ErrorState * err) } if (p == NULL) p = ""; - debug(4, 1) ("errorConvert: %%%c --> '%s'\n", token, p); + debug(4, 3) ("errorConvert: %%%c --> '%s'\n", token, p); return p; } diff --git a/src/http.cc b/src/http.cc index d0f251c6fe..3babaa6b6a 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.184 1997/08/24 00:37:03 wessels Exp $ + * $Id: http.cc,v 1.185 1997/08/25 22:35:55 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -1002,6 +1002,7 @@ httpBuildState(int fd, StoreEntry * entry, request_t * orig_request, peer * e) } /* register the handler to free HTTP state data when the FD closes */ comm_add_close_handler(httpState->fd, httpStateFree, httpState); + storeRegisterAbort(entry, httpAbort, httpState); return httpState; } @@ -1044,7 +1045,6 @@ httpStart(request_t * request, StoreEntry * entry, peer * e) if ((fd = httpSocketOpen(entry, NULL)) < 0) return; httpState = httpBuildState(fd, entry, request, e); - storeRegisterAbort(entry, httpAbort, httpState); commSetTimeout(httpState->fd, Config.Timeout.connect, httpTimeout, diff --git a/src/main.cc b/src/main.cc index 35afb63d0a..2d5176ac1a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.172 1997/08/10 04:42:41 wessels Exp $ + * $Id: main.cc,v 1.173 1997/08/25 22:35:57 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -613,7 +613,7 @@ main(int argc, char **argv) if (rotate_pending) { icmpClose(); _db_rotate_log(); /* cache.log */ - storeWriteCleanLogs(); + storeWriteCleanLogs(1); storeRotateLog(); /* store.log */ accessLogRotate(); /* access.log */ useragentRotateLog(); /* useragent.log */ diff --git a/src/neighbors.cc b/src/neighbors.cc index c785caec68..952e26de76 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,5 +1,5 @@ /* - * $Id: neighbors.cc,v 1.158 1997/08/25 02:19:32 wessels Exp $ + * $Id: neighbors.cc,v 1.159 1997/08/25 22:35:58 wessels Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -124,6 +124,7 @@ static void peerCountMcastPeersDone _PARAMS((void *data)); static void peerCountMcastPeersStart _PARAMS((void *data)); static void peerCountMcastPeersSchedule _PARAMS((peer * p, time_t when)); static IRCB peerCountHandleIcpReply; +static void neighborIgnoreNonPeer _PARAMS((const struct sockaddr_in *, icp_opcode)); static icp_common_t echo_hdr; static u_short echo_port; @@ -134,6 +135,8 @@ static peer *first_ping = NULL; char * neighborTypeStr(const peer * p) { + if (p->type == PEER_NONE) + return "Non-Peer"; if (p->type == PEER_SIBLING) return "Sibling"; if (p->type == PEER_MULTICAST) @@ -577,6 +580,45 @@ neighborCountIgnored(peer * p, icp_opcode op_unused) NLateReplies++; } +static peer *non_peers = NULL; + +static void +neighborIgnoreNonPeer(const struct sockaddr_in *from, icp_opcode opcode) +{ + peer *np; + double x; + for (np = non_peers; np; np = np->next) { + if (np->in_addr.sin_addr.s_addr != from->sin_addr.s_addr) + continue; + if (np->in_addr.sin_port != from->sin_port) + continue; + break; + } + if (np == NULL) { + np = xcalloc(1, sizeof(peer)); + np->in_addr.sin_addr = from->sin_addr; + np->in_addr.sin_port = from->sin_port; + np->icp_port = ntohl(from->sin_port); + np->type = PEER_NONE; + np->host = xstrdup(inet_ntoa(from->sin_addr)); + np->next = non_peers; + non_peers = np; + } + np->stats.ignored_replies++; + np->stats.counts[opcode]++; + x = log(np->stats.ignored_replies) / log(10.0); + if (0.0 != x - (double) (int) x) + return; + debug(15, 1) ("WARNING: Ignored %d replies from non-peer %s\n", + np->stats.ignored_replies, np->host); +} + +void +neighborDumpNonPeers(StoreEntry * sentry) +{ + dump_peers(sentry, non_peers); +} + /* ignoreMulticastReply * * We want to ignore replies from multicast peers if the @@ -656,8 +698,7 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc } } else if (opcode == ICP_OP_MISS) { if (p == NULL) { - debug(15, 1) ("Ignoring MISS from non-peer %s\n", - inet_ntoa(from->sin_addr)); + neighborIgnoreNonPeer(from, opcode); } else if (ntype != PEER_PARENT) { (void) 0; /* ignore MISS from non-parent */ } else { @@ -665,16 +706,14 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc } } else if (opcode == ICP_OP_HIT || opcode == ICP_OP_HIT_OBJ) { if (p == NULL) { - debug(15, 1) ("Ignoring HIT from non-peer %s\n", - inet_ntoa(from->sin_addr)); + neighborIgnoreNonPeer(from, opcode); } else { header->opcode = ICP_OP_HIT; mem->icp_reply_callback(p, ntype, header, mem->ircb_data); } } else if (opcode == ICP_OP_DECHO) { if (p == NULL) { - debug(15, 1) ("Ignoring DECHO from non-peer %s\n", - inet_ntoa(from->sin_addr)); + neighborIgnoreNonPeer(from, opcode); } else if (ntype == PEER_SIBLING) { debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n"); debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n"); @@ -692,8 +731,7 @@ neighborsUdpAck(int fd, const char *url, icp_common_t * header, const struct soc } } else if (opcode == ICP_OP_DENIED) { if (p == NULL) { - debug(15, 1) ("Ignoring DENIED from non-peer %s\n", - inet_ntoa(from->sin_addr)); + neighborIgnoreNonPeer(from, opcode); } else if (p->stats.pings_acked > 100) { if (100 * p->stats.counts[ICP_OP_DENIED] / p->stats.pings_acked > 95) { debug(15, 0) ("95%% of replies from '%s' are UDP_DENIED\n", p->host); diff --git a/src/protos.h b/src/protos.h index 16d6567897..96d473cf53 100644 --- a/src/protos.h +++ b/src/protos.h @@ -107,7 +107,6 @@ extern void comm_write _PARAMS((int fd, void *handler_data, FREE *)); extern void commCallCloseHandlers _PARAMS((int fd)); -extern void commCancelWriteHandler _PARAMS((int fd)); extern int commSetTimeout _PARAMS((int fd, int, PF *, void *)); extern void _db_init _PARAMS((const char *logfile, const char *options)); @@ -441,7 +440,7 @@ extern void storeClientCopy _PARAMS((StoreEntry * e, STCB * callback, void *data)); extern int storePendingNClients _PARAMS((const StoreEntry *)); -extern int storeWriteCleanLogs _PARAMS((void)); +extern int storeWriteCleanLogs _PARAMS((int reopen)); extern HASHCMP urlcmp; extern EVH storeMaintainSwapSpace; extern void storeExpireNow _PARAMS((StoreEntry *)); @@ -552,9 +551,11 @@ extern OBJH statFiledescriptors; extern OBJH log_enable; extern OBJH info_get; extern OBJH server_list; +extern OBJH neighborDumpNonPeers; extern OBJH dump_config; extern OBJH storeDirStats; extern OBJH pconnHistDump; +extern void dump_peers _PARAMS((StoreEntry * sentry, peer * peers)); extern void pconnPush _PARAMS((int, const char *host, u_short port)); extern int pconnPop _PARAMS((const char *host, u_short port)); diff --git a/src/stat.cc b/src/stat.cc index 621683fc81..8adad8beb9 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.155 1997/08/25 03:51:53 wessels Exp $ + * $Id: stat.cc,v 1.156 1997/08/25 22:36:00 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -374,18 +374,21 @@ stat_vmobjects_get(StoreEntry * e) void server_list(StoreEntry * sentry) +{ + dump_peers(sentry, Config.peers); +} + +void +dump_peers(StoreEntry * sentry, peer * peers) { peer *e = NULL; struct _domain_ping *d = NULL; icp_opcode op; - storeAppendPrintf(sentry, open_bracket); - - if (getFirstPeer() == NULL) + if (peers == NULL) storeAppendPrintf(sentry, "{There are no neighbors installed.}\n"); - for (e = getFirstPeer(); e; e = getNextPeer(e)) { - if (e->host == NULL) - fatal_dump("Found an peer without a hostname!"); + for (e = peers; e; e = e->next) { + assert(e->host != NULL); storeAppendPrintf(sentry, "\n{%-11.11s: %s/%d/%d}\n", neighborTypeStr(e), e->host, diff --git a/src/store.cc b/src/store.cc index 51b1bbc546..3617de5021 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.282 1997/08/25 05:29:58 wessels Exp $ + * $Id: store.cc,v 1.283 1997/08/25 22:36:01 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -1629,7 +1629,7 @@ storeCheckSwapable(StoreEntry * e) } else if (e->mem_obj->e_current_len > Config.Store.maxObjectSize) { debug(20, 2) ("storeCheckSwapable: NO: too big\n"); } else if (BIT_TEST(e->flag, KEY_PRIVATE)) { - debug(20, 1) ("storeCheckSwapable: NO: private key\n"); + debug(20, 3) ("storeCheckSwapable: NO: private key\n"); } else { return 1; } @@ -2391,7 +2391,7 @@ storeMaintainSwapSpace(void *unused) * Writes a "clean" swap log file from in-memory metadata. */ int -storeWriteCleanLogs(void) +storeWriteCleanLogs(int reopen) { StoreEntry *e = NULL; int *fd; @@ -2482,7 +2482,8 @@ storeWriteCleanLogs(void) } } storeDirCloseSwapLogs(); - storeDirOpenSwapLogs(); + if (reopen) + storeDirOpenSwapLogs(); stop = squid_curtime; r = stop - start; debug(20, 1) (" Finished. Wrote %d lines.\n", n); diff --git a/src/structs.h b/src/structs.h index 1575826cbf..fa4ba0a970 100644 --- a/src/structs.h +++ b/src/structs.h @@ -291,7 +291,6 @@ struct _dwrite_q { void (*free) (void *); }; - struct _fde { unsigned int type; unsigned int open; diff --git a/src/tools.cc b/src/tools.cc index a087e22ea7..e13b902669 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.119 1997/08/25 15:55:25 wessels Exp $ + * $Id: tools.cc,v 1.120 1997/08/25 22:36:03 wessels Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -286,7 +286,7 @@ death(int sig) signal(sig, SIG_DFL); #endif releaseServerSockets(); - storeWriteCleanLogs(); + storeWriteCleanLogs(0); PrintRusage(); dumpMallocStats(); if (squid_curtime - SQUID_RELEASE_TIME < 864000) { @@ -355,7 +355,7 @@ normal_shutdown(void) } releaseServerSockets(); unlinkdClose(); - storeWriteCleanLogs(); + storeWriteCleanLogs(0); PrintRusage(); dumpMallocStats(); storeCloseLog(); @@ -408,7 +408,7 @@ fatal(const char *message) * used in early initialization phases, long before we ever * get to the store log. */ if (!store_rebuilding) - storeWriteCleanLogs(); + storeWriteCleanLogs(0); fatal_common(message); exit(1); } @@ -421,7 +421,7 @@ fatal_dump(const char *message) if (message) fatal_common(message); if (opt_catch_signals) - storeWriteCleanLogs(); + storeWriteCleanLogs(0); abort(); }