]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Misc fixes to eliminate problems at exit (and other things)
authorwessels <>
Tue, 26 Aug 1997 04:35:50 +0000 (04:35 +0000)
committerwessels <>
Tue, 26 Aug 1997 04:35:50 +0000 (04:35 +0000)
- 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.

15 files changed:
src/cache_cf.cc
src/cachemgr.cc
src/client.cc
src/comm.cc
src/defines.h
src/enums.h
src/errorpage.cc
src/http.cc
src/main.cc
src/neighbors.cc
src/protos.h
src/stat.cc
src/store.cc
src/structs.h
src/tools.cc

index aeb53a2e6917e14a82411af9572b0a63e8f81580..d77eb77532dc2242c56e988f1008c612603a8da2 100644 (file)
@@ -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();
 }
-
index ef1fb92e66ad4a19b828b7a9aa85bcdb1816b377..6c2094add6e260e4892c6a4ad221cbf978bd1240 100644 (file)
@@ -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
index 7a827a890656e5ae71b28ee92c6932ced49e6a7b..e614e7f4df0f2bd87c4f8710c8a8797abf508c35 100644 (file)
@@ -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
index 25880e924ef8029a9fec4b14c0391626ec0cf84b..9a78fa5b010ea058a0c6e39001c83437f6e33203 100644 (file)
@@ -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
 #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));
 }
 
 
index d3bcb8b1c8ed5ff2797a59e5fd79a547455302f5..6cf05db3f11f60c91741ceabaefb55bbc1106123 100644 (file)
@@ -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
 
index 10b4296d41c8f051ecd5fb7cd0d8cea2e24b2d2c..94ee29a75d9fad22e431faeb53b3e1e31445d742 100644 (file)
@@ -139,6 +139,7 @@ typedef enum {
     MGR_REMOVE,
     MGR_REPLY_HDRS,
     MGR_SERVER_LIST,
+    MGR_NON_PEERS,
     MGR_SHUTDOWN,
     MGR_UTILIZATION,
     MGR_VM_OBJECTS,
index 9e6f45a8696f947ce8165816593c716d32f7f66b..72ca7dbb2343d445d0b144b4af95ed0bce864fa7 100644 (file)
@@ -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 = "<NULL>";
-    debug(4, 1) ("errorConvert: %%%c --> '%s'\n", token, p);
+    debug(4, 3) ("errorConvert: %%%c --> '%s'\n", token, p);
     return p;
 }
 
index d0f251c6fe5307459a21405717cf544d13957bc0..3babaa6b6a07f248587907fd9292e736225837a8 100644 (file)
@@ -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,
index 35afb63d0ac27ee55c3210702a703aa32ea22f28..2d5176ac1a8edb8c620a58748eddd5f03b82269a 100644 (file)
@@ -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 */
index c785caec6856fff0a1344b1fb1d61febca1b7b82..952e26de7641c738148cb78217daec53505145c0 100644 (file)
@@ -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);
index 16d656789727f1ae1cac92be9967c6ea9f77c2a5..96d473cf5372878b0e3d8f52e317fc1acc30cb11 100644 (file)
@@ -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));
index 621683fc817bf75e5e8c949ee4a74cb29aac73d8..8adad8beb9cd21f65a0f34e73e8438a269fdb999 100644 (file)
@@ -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,
index 51b1bbc546b4296c0c25b19b07ec5f87f240749d..3617de5021d9b17e5c3fec41dbd3c314d3b89059 100644 (file)
@@ -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);
index 1575826cbf023cf93259cb48301ba88315d8687b..fa4ba0a970fa3868250a94f7bda1f23425a69ab3 100644 (file)
@@ -291,7 +291,6 @@ struct _dwrite_q {
     void (*free) (void *);
 };
 
-
 struct _fde {
     unsigned int type;
     unsigned int open;
index a087e22ea75e917e555a50fb4188d7da618c9784..e13b90266945cbf05c727208f2d5966c47c50ddc 100644 (file)
@@ -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();
 }