-/* $Id: cache_cf.cc,v 1.29 1996/04/10 03:54:42 wessels Exp $ */
+/* $Id: cache_cf.cc,v 1.30 1996/04/10 20:45:24 wessels Exp $ */
/* DEBUG: Section 3 cache_cf: Configuration file parsing */
#include "squid.h"
-
static struct {
struct {
int maxSize;
char *file;
int rate;
} Announce;
+ wordlist *cache_dirs;
+ wordlist *http_stoplist;
+ wordlist *gopher_stoplist;
+ wordlist *ftp_stoplist;
+ wordlist *bind_addr_list;
+ wordlist *local_domain_list;
+ wordlist *inside_firewall_list;
} Config;
#define DefaultMemMaxSize (16 << 20) /* 16 MB */
extern char *config_file;
-stoplist *http_stoplist = NULL;
-stoplist *gopher_stoplist = NULL;
-stoplist *ftp_stoplist = NULL;
-stoplist *bind_addr_list = NULL;
-stoplist *local_domain_list = NULL;
-stoplist *inside_firewall_list = NULL;
-
/* default CONNECT ports */
intlist snews =
{
char w_space[] = " \t\n";
-static void configSetFactoryDefaults();
-static void configDoConfigure();
+static void configSetFactoryDefaults _PARAMS((void));
+static void configFreeMemory _PARAMS((void));
+static void configDoConfigure _PARAMS((void));
static char fatal_str[BUFSIZ];
void self_destruct(in_string)
#endif /* ndef IPACL_INTS */
-void addToStopList(list, key)
- stoplist **list;
+static void wordlistDestroy(list)
+ wordlist **list;
+{
+ wordlist *w = NULL;
+ wordlist *n = NULL;
+
+ for (w = *list; w; w=n) {
+ n = w->next;
+ safe_free(w->key);
+ safe_free(w);
+ }
+ *list = NULL;
+}
+
+void wordlistAdd(list, key)
+ wordlist **list;
char *key;
{
- stoplist *p, *q;
+ wordlist *p = NULL;
+ wordlist *q = NULL;
if (!(*list)) {
/* empty list */
- *list = (stoplist *) xcalloc(1, sizeof(stoplist));
+ *list = (wordlist *) xcalloc(1, sizeof(wordlist));
(*list)->key = xstrdup(key);
(*list)->next = NULL;
} else {
p = *list;
while (p->next)
p = p->next;
- q = (stoplist *) xcalloc(1, sizeof(stoplist));
+ q = (wordlist *) xcalloc(1, sizeof(wordlist));
q->key = xstrdup(key);
q->next = NULL;
p->next = q;
token = strtok(NULL, w_space);
if (token == (char *) NULL)
self_destruct(line_in);
- storeAddSwapDisk(xstrdup(token));
-
+ wordlistAdd(&Config.cache_dirs, token);
}
static void parseHttpdAccelLine(line_in)
token = strtok(NULL, w_space);
if (token == (char *) NULL)
return;
- addToStopList(&http_stoplist, token);
+ wordlistAdd(&Config.http_stoplist, token);
}
static void parseGopherStopLine(line_in)
token = strtok(NULL, w_space);
if (token == (char *) NULL)
return;
- addToStopList(&gopher_stoplist, token);
+ wordlistAdd(&Config.gopher_stoplist, token);
}
static void parseFtpStopLine(line_in)
char *line_in;
token = strtok(NULL, w_space);
if (token == (char *) NULL)
return;
- addToStopList(&ftp_stoplist, token);
+ wordlistAdd(&Config.ftp_stoplist, token);
}
static void parseAppendDomainLine(line_in)
if (token == (char *) NULL)
self_destruct(line_in);
debug(3, 1, "parseBindAddressLine: adding %s\n", token);
- addToStopList(&bind_addr_list, token);
+ wordlistAdd(&Config.bind_addr_list, token);
}
static void parseBlockListLine(line_in)
{
char *token;
while ((token = strtok(NULL, w_space))) {
- addToStopList(&local_domain_list, token);
+ wordlistAdd(&Config.local_domain_list, token);
}
}
{
char *token;
while ((token = strtok(NULL, w_space))) {
- addToStopList(&inside_firewall_list, token);
+ wordlistAdd(&Config.inside_firewall_list, token);
}
}
static char tmp_line[BUFSIZ];
static char line_in[BUFSIZ];
- /* Initialize a few global strings, in case they aren't user defined */
-
+ configFreeMemory();
configSetFactoryDefaults();
if ((fp = fopen(file_name, "r")) == NULL) {
}
/* Add INADDR_ANY to end of bind_addr_list as last chance */
- addToStopList(&bind_addr_list, "0.0.0.0");
+ wordlistAdd(&Config.bind_addr_list, "0.0.0.0");
/* Sanity checks */
if (getClientLifetime() < getReadTimeout()) {
{
return Config.Announce.rate;
}
+wordlist * getHttpStoplist()
+{
+ return Config.http_stoplist;
+}
+wordlist * getFtpStoplist()
+{
+ return Config.ftp_stoplist;
+}
+wordlist * getGopherStoplist()
+{
+ return Config.gopher_stoplist;
+}
+wordlist * getLocalDomainList()
+{
+ return Config.local_domain_list;
+}
+wordlist * getCacheDirs()
+{
+ return Config.cache_dirs;
+}
+wordlist * getInsideFirewallList()
+{
+ return Config.inside_firewall_list;
+}
+wordlist * getBindAddrList()
+{
+ return Config.bind_addr_list;
+}
int setAsciiPortNum(p)
int p;
return p ? strlen(p) : -1;
}
+static void configFreeMemory()
+{
+ safe_free(Config.Wais.relayHost);
+ safe_free(Config.Log.log);
+ safe_free(Config.Log.access);
+ safe_free(Config.Log.hierarchy);
+ safe_free(Config.adminEmail);
+ safe_free(Config.effectiveUser);
+ safe_free(Config.effectiveGroup);
+ safe_free(Config.Program.ftpget);
+ safe_free(Config.Program.ftpget_opts);
+ safe_free(Config.Program.dnsserver);
+ safe_free(Config.Accel.host);
+ safe_free(Config.Accel.prefix);
+ safe_free(Config.appendDomain);
+ safe_free(Config.debugOptions);
+ safe_free(Config.pidFilename);
+ safe_free(Config.visibleHostname);
+ safe_free(Config.ftpUser);
+ safe_free(Config.Announce.host);
+ safe_free(Config.Announce.file);
+ wordlistDestroy(&Config.cache_dirs);
+ wordlistDestroy(&Config.http_stoplist);
+ wordlistDestroy(&Config.gopher_stoplist);
+ wordlistDestroy(&Config.ftp_stoplist);
+ wordlistDestroy(&Config.bind_addr_list);
+ wordlistDestroy(&Config.local_domain_list);
+ wordlistDestroy(&Config.inside_firewall_list);
+}
+
static void configSetFactoryDefaults()
{
-/* $Id: comm.cc,v 1.19 1996/04/09 18:18:48 wessels Exp $ */
+/* $Id: comm.cc,v 1.20 1996/04/10 20:45:26 wessels Exp $ */
/* DEBUG: Section 5 comm: socket level functions */
int new_socket;
FD_ENTRY *conn = NULL;
int sock_type = io_type & COMM_DGRAM ? SOCK_DGRAM : SOCK_STREAM;
- stoplist *p = NULL;
+ wordlist *p = NULL;
/* Create socket for accepting new connections. */
if ((new_socket = socket(AF_INET, sock_type, 0)) < 0) {
}
}
if (port) {
- for (p = bind_addr_list; p; p = p->next) {
+ for (p = getBindAddrList(); p; p = p->next) {
if (do_bind(new_socket, p->key, port) == COMM_OK)
break;
- if (p->next == (stoplist *) NULL)
+ if (p->next == (wordlist *) NULL)
return COMM_ERROR;
}
}
-/* $Id: ftp.cc,v 1.31 1996/04/10 05:06:57 wessels Exp $ */
+/* $Id: ftp.cc,v 1.32 1996/04/10 20:45:26 wessels Exp $ */
/*
* DEBUG: Section 9 ftp: FTP
int ftpCachable(url)
char *url;
{
- stoplist *p = NULL;
+ wordlist *p = NULL;
/* scan stop list */
- p = ftp_stoplist;
- while (p) {
+ for (p = getFtpStoplist(); p; p=p->next) {
if (strstr(url, p->key))
return 0;
- p = p->next;
}
/* else cachable */
-/* $Id: gopher.cc,v 1.22 1996/04/10 03:53:59 wessels Exp $ */
+/* $Id: gopher.cc,v 1.23 1996/04/10 20:45:27 wessels Exp $ */
/*
* DEBUG: Section 10 gopher: GOPHER
int gopherCachable(url)
char *url;
{
- stoplist *p = NULL;
+ wordlist *p = NULL;
GopherData *data = NULL;
int cachable = 1;
/* scan stop list */
- for (p = gopher_stoplist; p; p = p->next)
+ for (p = getGopherStoplist(); p; p = p->next)
if (strstr(url, p->key))
return 0;
-/* $Id: http.cc,v 1.35 1996/04/10 00:18:49 wessels Exp $ */
+/* $Id: http.cc,v 1.36 1996/04/10 20:45:27 wessels Exp $ */
/*
* DEBUG: Section 11 http: HTTP
int method;
char *req_hdr;
{
- stoplist *p = NULL;
+ wordlist *p = NULL;
/* GET and HEAD are cachable. Others are not. */
if (method != METHOD_GET && method != METHOD_HEAD)
return 0;
/* scan stop list */
- for (p = http_stoplist; p; p = p->next) {
+ for (p = getHttpStoplist(); p; p = p->next) {
if (strstr(url, p->key))
return 0;
}
-/* $Id: ipcache.cc,v 1.18 1996/04/10 17:58:05 wessels Exp $ */
+/* $Id: ipcache.cc,v 1.19 1996/04/10 20:45:28 wessels Exp $ */
/*
* DEBUG: Section 14 ipcache: IP Cache
void update_dns_child_alive()
{
int i;
+ int N = getDnsChildren();
dns_child_alive = 0;
- for (i = 0; i < getDnsChildren(); ++i) {
+ for (i = 0; i < N; ++i) {
if (dns_child_table[i]->alive) {
dns_child_alive = 1;
break;
}
-/* initialize the ipcache */
-void ipcache_init()
+void ipcacheOpenServers()
{
- int i, dnssocket;
- char fd_note_buf[FD_ASCII_NOTE_SZ];
-
- debug(14, 3, "ipcache_init: Called. ipcache_initialized=%d getDnsChildren()=%d\n", ipcache_initialized, getDnsChildren());
-
- if (ipcache_initialized)
- return;
+ int N = getDnsChildren();
+ char *prg = getDnsProgram();
+ int i;
+ int dnssocket;
+ static char fd_note_buf[FD_ASCII_NOTE_SZ];
- if (mkdir("dns", 0755) < 0 && errno != EEXIST) {
- debug(14, 0, "ipcache_init: mkdir %s\n", xstrerror());
- }
- last_dns_dispatched = getDnsChildren() - 1;
- dns_error_message = xcalloc(1, 256);
+ if (mkdir("dns", 0755) < 0 && errno != EEXIST)
+ debug(14, 0, "ipcacheOpenServers: mkdir %s\n", xstrerror());
- /* test naming lookup */
- if (!do_dns_test) {
- debug(14, 4, "ipcache_init: Skipping DNS name lookup tests, -D flag given.\n");
- } else if (ipcache_testname() < 0) {
- fatal("ipcache_init: DNS name lookup appears to be broken on this machine.");
- } else {
- debug(14, 1, "Successful DNS name lookup tests...\n");
- }
-
- ip_table = hash_create(urlcmp, 229); /* small hash table */
- /* init static area */
- static_result = (struct hostent *) xcalloc(1, sizeof(struct hostent));
- static_result->h_length = 4;
- /* Need a terminating NULL address (h_addr_list[1]) */
- static_result->h_addr_list = (char **) xcalloc(2, sizeof(char *));
- static_result->h_addr_list[0] = (char *) xcalloc(1, 4);
- static_result->h_name = (char *) xcalloc(1, MAX_HOST_NAME + 1);
/* start up companion process */
- dns_child_table = (dnsserver_entry **) xcalloc(getDnsChildren(), sizeof(dnsserver_entry));
+ safe_free(dns_child_table);
+ dns_child_table = (dnsserver_entry **) xcalloc(N, sizeof(dnsserver_entry));
dns_child_alive = 0;
- debug(14, 1, "ipcache_init: Starting %d 'dns_server' processes\n",
- getDnsChildren());
- for (i = 0; i < getDnsChildren(); i++) {
+ debug(14, 1, "ipcache_init: Starting %d 'dns_server' processes\n", N);
+ for (i = 0; i < N; i++) {
dns_child_table[i] = (dnsserver_entry *) xcalloc(1, sizeof(dnsserver_entry));
- if ((dnssocket = ipcache_create_dnsserver(getDnsProgram())) < 0) {
+ if ((dnssocket = ipcache_create_dnsserver(prg)) < 0) {
debug(14, 1, "ipcache_init: WARNING: Cannot run 'dnsserver' process.\n");
debug(14, 1, " Fallling back to the blocking version.\n");
dns_child_table[i]->alive = 0;
/* update fd_stat */
sprintf(fd_note_buf, "%s #%d",
- getDnsProgram(),
+ prg,
dns_child_table[i]->id);
file_update_open(dns_child_table[i]->inpipe, fd_note_buf);
debug(14, 3, "ipcache_init: 'dns_server' %d started\n", i);
}
}
+}
+
+/* initialize the ipcache */
+void ipcache_init()
+{
+
+ debug(14, 3, "ipcache_init: Called. ipcache_initialized=%d getDnsChildren()=%d\n", ipcache_initialized, getDnsChildren());
+
+ if (ipcache_initialized)
+ return;
+
+ last_dns_dispatched = getDnsChildren() - 1;
+ if (!dns_error_message)
+ dns_error_message = xcalloc(1, 256);
+
+ /* test naming lookup */
+ if (!do_dns_test) {
+ debug(14, 4, "ipcache_init: Skipping DNS name lookup tests, -D flag given.\n");
+ } else if (ipcache_testname() < 0) {
+ fatal("ipcache_init: DNS name lookup appears to be broken on this machine.");
+ } else {
+ debug(14, 1, "Successful DNS name lookup tests...\n");
+ }
+
+ ip_table = hash_create(urlcmp, 229); /* small hash table */
+ /* init static area */
+ static_result = (struct hostent *) xcalloc(1, sizeof(struct hostent));
+ static_result->h_length = 4;
+ /* Need a terminating NULL address (h_addr_list[1]) */
+ static_result->h_addr_list = (char **) xcalloc(2, sizeof(char *));
+ static_result->h_addr_list[0] = (char *) xcalloc(1, 4);
+ static_result->h_name = (char *) xcalloc(1, MAX_HOST_NAME + 1);
+
+ ipcacheOpenServers();
+
ipcache_high = (long) (((float) MAX_IP *
(float) IP_HIGH_WATER) / (float) 100);
ipcache_low = (long) (((float) MAX_IP *
(float) IP_LOW_WATER) / (float) 100);
-
ipcache_initialized = 1;
}
for (i = 0; i < getDnsChildren(); i++) {
dns = *(dns_child_table + i);
- debug(14, 1, "ipcacheShutdownServers: sending '$shutdown' to dnsserver #%d\n", i);
- debug(14, 1, "ipcacheShutdownServers: --> FD %d\n", dns->outpipe);
+ debug(14, 3, "ipcacheShutdownServers: sending '$shutdown' to dnsserver #%d\n", i);
+ debug(14, 3, "ipcacheShutdownServers: --> FD %d\n", dns->outpipe);
file_write(dns->outpipe,
xstrdup(shutdown),
strlen(shutdown),
-/* $Id: main.cc,v 1.28 1996/04/10 17:58:26 wessels Exp $ */
+/* $Id: main.cc,v 1.29 1996/04/10 20:45:30 wessels Exp $ */
/* DEBUG: Section 1 main: startup and main loop */
}
}
-static void mainUninitialize()
+static void mainReinitialize()
{
+ debug(1, 0, "Retarting Harvest Cache (version %s)...\n", SQUID_VERSION);
+ /* Already called serverConnectionsClose and ipcacheShutdownServers() */
neighborsDestroy();
- serverConnectionsClose();
- /* ipcache_uninit() */
- /* neighbors_uninit(); */
+
+ parseConfigFile(config_file);
+ neighbors_init();
+ ipcacheOpenServers();
+ serverConnectionsOpen();
+ if (theUdpConnection >= 0 && (!httpd_accel_mode || getAccelWithProxy()))
+ neighbors_open(theUdpConnection);
+ debug(1, 0, "Ready to serve requests.\n");
}
static void mainInitialize()
}
signal(SIGPIPE, SIG_IGN);
signal(SIGCHLD, sig_child);
- signal(SIGHUP, rotate_logs);
+ signal(SIGUSR1, rotate_logs);
signal(SIGTERM, shut_down);
signal(SIGINT, shut_down);
+ signal(SIGHUP, reconfigure);
mainInitialize();
normal_shutdown();
exit(0);
} else if (reread_pending) {
- mainUninitialize();
- mainInitialize();
+ mainReinitialize();
reread_pending = 0; /* reset */
} else {
fatal_dump("MAIN: SHUTDOWN from comm_select, but nothing pending.");
}
+ break;
default:
fatal_dump("MAIN: Internal error -- this should never happen.");
break;
-/* $Id: neighbors.cc,v 1.13 1996/04/10 17:57:44 wessels Exp $ */
+/* $Id: neighbors.cc,v 1.14 1996/04/10 20:45:31 wessels Exp $ */
/* TODO:
* - change 'neighbor' to 'sibling'
edge *e = NULL;
edge *next = NULL;
- debug(15, 1, "neighborEdgesFree()\n");
+ debug(15, 3, "neighborsDestroy: called\n");
for (e = friends->edges_head; e; e = next) {
next = e->next;
safe_free(e->host);
safe_free(e);
}
- friends->edges_head = NULL;
+ safe_free(friends);
+ friends = NULL;
}
static void neighborsOpenLog(fname)
/* e->header.reqnum++; */
e->header.reqnum = atoi(entry->key);
- debug(15, 1, "neighborsUdpPing: key = '%s'\n", entry->key);
- debug(15, 1, "neighborsUdpPing: reqnum = %d\n", e->header.reqnum);
+ debug(15, 3, "neighborsUdpPing: key = '%s'\n", entry->key);
+ debug(15, 3, "neighborsUdpPing: reqnum = %d\n", e->header.reqnum);
if (e->udp_port == echo_port) {
debug(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping\n");
friends->edges_tail = e;
friends->n++;
- xfree(t);
+ safe_free(t);
}
+ Neighbor_cf = NULL;
}
void neighbors_rotate_log()
-/* $Id: stat.cc,v 1.18 1996/04/10 03:52:56 wessels Exp $ */
+/* $Id: stat.cc,v 1.19 1996/04/10 20:45:32 wessels Exp $ */
/*
* DEBUG: Section 18 stat
{
char *tod = NULL;
static char line[MAX_LINELEN];
+ wordlist *p = NULL;
#if defined(HAVE_GETRUSAGE) && defined(RUSAGE_SELF)
struct rusage rusage;
sprintf(line, "{Stop List:}\n");
storeAppend(sentry, line, strlen(line));
- if (http_stoplist) {
- stoplist *p;
- p = http_stoplist;
+ if ((p = getHttpStoplist())) {
sprintf(line, "{\tHTTP:}\n");
storeAppend(sentry, line, strlen(line));
while (p) {
p = p->next;
}
}
- if (gopher_stoplist) {
- stoplist *p;
- p = gopher_stoplist;
+ if ((p = getGopherStoplist())) {
sprintf(line, "{\tGOPHER:}\n");
storeAppend(sentry, line, strlen(line));
while (p) {
p = p->next;
}
}
- if (ftp_stoplist) {
- stoplist *p;
- p = ftp_stoplist;
+ if ((p = getFtpStoplist())) {
sprintf(line, "{\tFTP:}\n");
storeAppend(sentry, line, strlen(line));
while (p) {
-/* $Id: store.cc,v 1.39 1996/04/10 05:07:27 wessels Exp $ */
-#ident "$Id: store.cc,v 1.39 1996/04/10 05:07:27 wessels Exp $"
+/* $Id: store.cc,v 1.40 1996/04/10 20:45:33 wessels Exp $ */
+#ident "$Id: store.cc,v 1.40 1996/04/10 20:45:33 wessels Exp $"
/*
* DEBUG: Section 20 store
{
if (cache_dirs == NULL)
cache_dirs = create_dynamic_array(5, 5);
- insert_dynamic_array(cache_dirs, path);
+ /* XXX note xstrdup here prob means we
+ can't use destroy_dynamic_array() */
+ insert_dynamic_array(cache_dirs, xstrdup(path));
return ++ncache_dirs;
}
e->mem_obj = new_MemObject();
path = storeSwapFullPath(e->swap_file_number, NULL);
- fd = e->mem_obj->swap_fd = file_open(path, NULL, O_RDONLY);
- if (fd < 0) {
+ if ((fd = file_open(path, NULL, O_RDONLY)) < 0) {
debug(20, 0, "storeSwapInStart: Unable to open swapfile: %s\n",
path);
debug(20, 0, "storeSwapInStart: --> for <URL:%s>\n",
/* Invoke a store abort that should free the memory object */
return -1;
}
+ e->mem_obj->swap_fd = (short) fd;
debug(20, 5, "storeSwapInStart: initialized swap file '%s' for <URL:%s>\n",
path, e->url);
e->swap_file_number = -1;
return -1;
}
- e->mem_obj->swap_fd = fd;
+ e->mem_obj->swap_fd = (short) fd;
debug(20, 5, "storeSwapOutStart: Begin SwapOut <URL:%s> to FD %d FILE %s.\n",
e->url, fd, swapfilename);
int storeInit()
{
int dir_created;
+ wordlist *w = NULL;
storelog_fd = file_open("store.log", NULL, O_WRONLY | O_APPEND | O_CREAT);
+ for (w = getCacheDirs(); w; w=w->next)
+ storeAddSwapDisk(w->key);
storeSanityCheck();
file_map_create(MAX_SWAP_FILE);
dir_created = storeVerifySwapDirs(zap_disk_store);
-/* $Id: tools.cc,v 1.27 1996/04/10 05:10:28 wessels Exp $ */
+/* $Id: tools.cc,v 1.28 1996/04/10 20:45:34 wessels Exp $ */
/*
* DEBUG: Section 21 tools
void rotate_logs(sig)
int sig;
{
- debug(21, 1, "rotate_logs: SIGHUP received.\n");
+ debug(21, 1, "rotate_logs: SIGUSR1 received.\n");
storeWriteCleanLog();
neighbors_rotate_log();
}
-void usr1_handle(sig)
+void reconfigure(sig)
int sig;
{
- debug(21, 1, "usr1_handle: SIGUSR1 received.\n");
+ debug(21, 1, "reconfigure: SIGHUP received.\n");
+ serverConnectionsClose();
+ ipcacheShutdownServers();
reread_pending = 1;
#if defined(_SQUID_SYSV_SIGNALS_)
- signal(sig, rotate_logs);
+ signal(sig, reconfigure);
#endif
}