From: wessels <> Date: Wed, 13 Nov 1996 13:52:20 +0000 (+0000) Subject: - Fixed 'void *buf' bug icpCreateMessage() (Jean-Hugues ROYER). X-Git-Tag: SQUID_3_0_PRE1~5479 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=28070024e672ecc3af7d0f148b3fd99fb7386656;p=thirdparty%2Fsquid.git - Fixed 'void *buf' bug icpCreateMessage() (Jean-Hugues ROYER). - Fixed more NULL 'friends' bugs. - Added debug_trap for NULL mem->clients in InvokeHandlers() (Mark Treacy). --- diff --git a/src/comm.cc b/src/comm.cc index eaec199217..662103e13c 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.101 1996/11/11 22:00:45 wessels Exp $ + * $Id: comm.cc,v 1.102 1996/11/13 06:52:20 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -115,8 +115,6 @@ * 64 file descriptors free for disk-i/o and connections to remote servers */ int RESERVED_FD = 64; -struct in_addr any_addr; -struct in_addr no_addr; #define min(x,y) ((x)<(y)? (x) : (y)) #define max(a,b) ((a)>(b)? (a) : (b)) @@ -1025,8 +1023,6 @@ comm_init(void) meta_data.misc += FD_SETSIZE * sizeof(int); zero_tv.tv_sec = 0; zero_tv.tv_usec = 0; - any_addr.s_addr = INADDR_ANY; - no_addr.s_addr = INADDR_NONE; return 0; } diff --git a/src/main.cc b/src/main.cc index bae1c1f3e1..d602319308 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,5 @@ /* - * $Id: main.cc,v 1.110 1996/11/12 22:37:10 wessels Exp $ + * $Id: main.cc,v 1.111 1996/11/13 06:52:24 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -130,6 +130,8 @@ const char *const version_string = SQUID_VERSION; const char *const appname = "squid"; const char *const localhost = "127.0.0.1"; struct in_addr local_addr; +struct in_addr no_addr; +struct in_addr any_addr; struct in_addr theOutICPAddr; const char *const dash_str = "-"; const char *const null_string = ""; @@ -541,7 +543,8 @@ mainInitialize(void) eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate); eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1); eventAdd("storeDirClean", storeDirClean, NULL, 15); - eventAdd("send_announce", send_announce, NULL, 3600); + if (Config.Announce.on) + eventAdd("send_announce", send_announce, NULL, 3600); eventAdd("ipcache_purgelru", (EVH) ipcache_purgelru, NULL, 10); } first_time = 0; @@ -572,6 +575,10 @@ main(int argc, char **argv) memset(&local_addr, '\0', sizeof(struct in_addr)); local_addr.s_addr = inet_addr(localhost); + memset(&any_addr, '\0', sizeof(struct in_addr)); + any_addr.s_addr = inet_addr("0.0.0.0"); + memset(&no_addr, '\0', sizeof(struct in_addr)); + no_addr.s_addr = inet_addr("255.255.255.255"); errorInitialize(); diff --git a/src/neighbors.cc b/src/neighbors.cc index cc8841325a..eaf42702a9 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,5 +1,5 @@ /* - * $Id: neighbors.cc,v 1.85 1996/11/12 22:37:11 wessels Exp $ + * $Id: neighbors.cc,v 1.86 1996/11/13 06:52:25 wessels Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -111,12 +111,22 @@ static edge *whichEdge _PARAMS((const struct sockaddr_in * from)); static void neighborAlive _PARAMS((edge *, const MemObject *, const icp_common_t *)); static void neighborCountIgnored _PARAMS((edge * e, icp_opcode op_unused)); static neighbor_t parseNeighborType _PARAMS((const char *s)); -static void neighbors_init _PARAMS((void)); -static neighbors *friends = NULL; static icp_common_t echo_hdr; static u_short echo_port; +static struct { + int n; + int n_parent; + int n_sibling; + edge *edges_head; + edge *edges_tail; + edge *first_ping; +} friends = { + + 0, 0, 0, NULL, NULL, NULL +}; + const char *hier_strings[] = { "NONE", @@ -145,7 +155,7 @@ whichEdge(const struct sockaddr_in *from) struct in_addr ip = from->sin_addr; edge *e = NULL; debug(15, 3, "whichEdge: from %s port %d\n", inet_ntoa(ip), port); - for (e = friends->edges_head; e; e = e->next) { + for (e = friends.edges_head; e; e = e->next) { for (j = 0; j < e->n_addresses; j++) { if (ip.s_addr == e->addresses[j].s_addr && port == e->icp_port) { return e; @@ -213,9 +223,9 @@ getSingleParent(request_t * request, int *n) edge *e = NULL; int count = 0; - if (n == NULL && friends->n_parent < 1) + if (n == NULL && friends.n_parent < 1) return NULL; - for (e = friends->edges_head; e; e = e->next) { + for (e = friends.edges_head; e; e = e->next) { if (!edgeWouldBePinged(e, request)) continue; count++; @@ -248,9 +258,9 @@ edge * getFirstUpParent(request_t * request) { edge *e = NULL; - if (friends->n_parent < 1) + if (friends.n_parent < 1) return NULL; - for (e = friends->edges_head; e; e = e->next) { + for (e = friends.edges_head; e; e = e->next) { if (!e->neighbor_up) continue; if (neighborType(e, request) != EDGE_PARENT) @@ -270,7 +280,7 @@ getNextEdge(edge * e) edge * getFirstEdge(void) { - return friends->edges_head; + return friends.edges_head; } static void @@ -278,8 +288,8 @@ neighborRemove(edge * target) { edge *e = NULL; edge **E = NULL; - e = friends->edges_head; - E = &friends->edges_head; + e = friends.edges_head; + E = &friends.edges_head; while (e) { if (target == e) break; @@ -290,7 +300,7 @@ neighborRemove(edge * target) *E = e->next; safe_free(e->host); safe_free(e); - friends->n--; + friends.n--; } } @@ -302,14 +312,13 @@ neighborsDestroy(void) debug(15, 3, "neighborsDestroy: called\n"); - for (e = friends->edges_head; e; e = next) { + for (e = friends.edges_head; e; e = next) { next = e->next; safe_free(e->host); safe_free(e); - friends->n--; + friends.n--; } - safe_free(friends); - friends = NULL; + memset(&friends, '\0', sizeof(friends)); } void @@ -325,15 +334,13 @@ neighbors_open(int fd) edge **E = NULL; struct servent *sep = NULL; - if (friends == NULL) - neighbors_init(); memset(&name, '\0', sizeof(struct sockaddr_in)); if (getsockname(fd, (struct sockaddr *) &name, &len) < 0) debug(15, 1, "getsockname(%d,%p,%p) failed.\n", fd, &name, &len); /* Prepare neighbor connections, one at a time */ - E = &friends->edges_head; - next = friends->edges_head; + E = &friends.edges_head; + next = friends.edges_head; while ((e = next)) { getCurrentTime(); next = e->next; @@ -409,7 +416,7 @@ neighborsUdpPing(protodispatch_data * proto) mem->w_rtt = 0; mem->start_ping = current_time; - if (friends->edges_head == NULL) + if (friends.edges_head == NULL) return 0; if (theOutIcpConnection < 0) { debug(15, 0, "neighborsUdpPing: There is no ICP socket!\n"); @@ -417,11 +424,11 @@ neighborsUdpPing(protodispatch_data * proto) debug(15, 0, "Check 'icp_port' in your config file\n"); fatal_dump(NULL); } - for (i = 0, e = friends->first_ping; i++ < friends->n; e = e->next) { + for (i = 0, e = friends.first_ping; i++ < friends.n; e = e->next) { if (entry->swap_status != NO_SWAP) fatal_dump("neighborsUdpPing: bad swap_status"); if (e == (edge *) NULL) - e = friends->edges_head; + e = friends.edges_head; debug(15, 5, "neighborsUdpPing: Edge %s\n", e->host); /* skip any cache where we failed to connect() w/in the last 60s */ @@ -492,11 +499,11 @@ neighborsUdpPing(protodispatch_data * proto) e->host, e->http_port, e->icp_port); } } - friends->first_ping = e->next; + friends.first_ping = e->next; } /* only do source_ping if we have neighbors */ - if (friends->n) { + if (friends.n) { if (!proto->source_ping) { debug(15, 6, "neighborsUdpPing: Source Ping is disabled.\n"); } else if ((ia = ipcache_gethostbyname(host, IP_BLOCKING_LOOKUP))) { @@ -727,10 +734,8 @@ neighborAdd(const char *host, { edge *e = NULL; const char *me = getMyHostname(); - if (friends == NULL) - neighbors_init(); if (!strcmp(host, me) && http_port == Config.Port.http) { - debug(15, 0, "neighbors_init: skipping cache_host %s %s/%d/%d\n", + debug(15, 0, "neighborAdd: skipping cache_host %s %s/%d/%d\n", type, host, http_port, icp_port); return; } @@ -748,17 +753,17 @@ neighborAdd(const char *host, e->icp_version = ICP_VERSION_CURRENT; e->type = parseNeighborType(type); if (e->type == EDGE_PARENT) - friends->n_parent++; + friends.n_parent++; else if (e->type == EDGE_SIBLING) - friends->n_sibling++; + friends.n_sibling++; /* Append edge */ - if (!friends->edges_head) - friends->edges_head = e; - if (friends->edges_tail) - friends->edges_tail->next = e; - friends->edges_tail = e; - friends->n++; + if (!friends.edges_head) + friends.edges_head = e; + if (friends.edges_tail) + friends.edges_tail->next = e; + friends.edges_tail = e; + friends.n++; } void @@ -843,20 +848,11 @@ neighborAddAcl(const char *host, const char *aclname) *Tail = L; } -static void -neighbors_init(void) -{ - debug(15, 1, "neighbors_init: Initializing Neighbors...\n"); - if (friends == NULL) - friends = xcalloc(1, sizeof(neighbors)); - any_addr.s_addr = inet_addr("0.0.0.0"); -} - edge * neighborFindByName(const char *name) { edge *e = NULL; - for (e = friends->edges_head; e; e = e->next) { + for (e = friends.edges_head; e; e = e->next) { if (!strcasecmp(name, e->host)) break; } diff --git a/src/send-announce.cc b/src/send-announce.cc index 1c458e768c..b121f7a8d2 100644 --- a/src/send-announce.cc +++ b/src/send-announce.cc @@ -1,6 +1,6 @@ /* - * $Id: send-announce.cc,v 1.24 1996/11/12 22:37:16 wessels Exp $ + * $Id: send-announce.cc,v 1.25 1996/11/13 06:52:27 wessels Exp $ * * DEBUG: section 27 Cache Announcer * AUTHOR: Duane Wessels @@ -45,6 +45,8 @@ send_announce(void *unused) int l; int n; + if (!Config.Announce.on) + return; eventAdd("send_announce", send_announce, NULL, Config.Announce.rate); if ((ia = ipcache_gethostbyname(host, IP_BLOCKING_LOOKUP)) == NULL) { debug(27, 1, "send_announce: Unknown host '%s'\n", host); diff --git a/src/store.cc b/src/store.cc index 4cd5f076cb..b3bb0a1216 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.160 1996/11/12 22:37:17 wessels Exp $ + * $Id: store.cc,v 1.161 1996/11/13 06:52:29 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -919,6 +919,10 @@ InvokeHandlers(StoreEntry * e) PIF handler = NULL; void *data = NULL; struct _store_client *sc; + if (mem->clients == NULL) { + debug_trap("InvokeHandlers: NULL mem->clients"); + return; + } /* walk the entire list looking for valid handlers */ for (i = 0; i < mem->nclients; i++) { sc = &mem->clients[i];