]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
1.0.7 -> 1.0.8 merge
authorwessels <>
Tue, 20 Aug 1996 04:44:48 +0000 (04:44 +0000)
committerwessels <>
Tue, 20 Aug 1996 04:44:48 +0000 (04:44 +0000)
src/Makefile.in
src/acl.cc
src/cache_cf.cc
src/debug.cc
src/dnsserver.cc
src/errorpage.cc
src/ipcache.cc
src/main.cc
src/squid.h
src/store.cc
src/tools.cc

index 6e9a847b3847ff1af2d45b0c90a06e691fd7158f..db08b87bf73bab0b4714a3d4e28f4d372857a9a3 100644 (file)
@@ -1,7 +1,7 @@
 #
 #  Makefile for the Squid Object Cache server
 #
-#  $Id: Makefile.in,v 1.34 1996/08/15 02:57:15 wessels Exp $
+#  $Id: Makefile.in,v 1.35 1996/08/19 22:44:48 wessels Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -76,7 +76,7 @@ all:    squid.conf $(PROGS) $(UTILS) $(CGIPROGS)
 squid: $(OBJS)
        $(CC) -o $@ $(LDFLAGS) $(OBJS) $(CRYPT_LIB) $(LIBS) $(AIO_LIBS)
 
-cache_cf.o: cache_cf.c
+cache_cf.o: cache_cf.c Makefile
        $(CC) -c $< $(CFLAGS) $(DEFAULTS)
 
 client:        client.o
@@ -91,7 +91,7 @@ cachemgr.cgi: cachemgr.o
 ftpget: ftpget.o
        $(CC) -o $@ $(LDFLAGS) ftpget.o $(LIBS)
 
-squid.conf: squid.conf.pre
+squid.conf: squid.conf.pre Makefile
        sed "\
        s%@DEFAULT_CONFIG_FILE@%$(DEFAULT_CONFIG_FILE)%g;\
        s%@DEFAULT_FTPGET@%$(DEFAULT_FTPGET)%g;\
@@ -99,7 +99,7 @@ squid.conf: squid.conf.pre
        s%@DEFAULT_CACHE_LOG@%$(DEFAULT_CACHE_LOG)%g;\
        s%@DEFAULT_ACCESS_LOG@%$(DEFAULT_ACCESS_LOG)%g;\
        s%@DEFAULT_STORE_LOG@%$(DEFAULT_STORE_LOG)%g;\
-       s%@DEFAULT_SWAP_DIR@%$(DEFAULT_SWAP_DIR)%g" <$? >$@
+       s%@DEFAULT_SWAP_DIR@%$(DEFAULT_SWAP_DIR)%g" < squid.conf.pre >$@
 
 install-mkdirs:
        -@if test ! -d $(prefix); then \
index 75ed1270273b0d46dd4e97ff450193eed34e6c96..1adb718a3c348635105e425c0496cf8c162f1d7b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: acl.cc,v 1.26 1996/07/23 04:59:33 wessels Exp $
+ * $Id: acl.cc,v 1.27 1996/08/19 22:44:48 wessels Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Duane Wessels
@@ -75,6 +75,10 @@ static squid_acl aclType(s)
     if (!strcmp(s, "time"))
        return ACL_TIME;
     if (!strcmp(s, "pattern"))
+       return ACL_URLPATH_REGEX;
+    if (!strcmp(s, "urlpath_regex"))
+       return ACL_URLPATH_REGEX;
+    if (!strcmp(s, "url_regex"))
        return ACL_URL_REGEX;
     if (!strcmp(s, "port"))
        return ACL_URL_PORT;
@@ -435,6 +439,7 @@ void aclParseAclLine()
        A->data = (void *) aclParseTimeSpec();
        break;
     case ACL_URL_REGEX:
+    case ACL_URLPATH_REGEX:
        A->data = (void *) aclParseRegexList();
        break;
     case ACL_URL_PORT:
@@ -717,9 +722,12 @@ int aclMatchAcl(acl, checklist)
     case ACL_TIME:
        return aclMatchTime(acl->data, squid_curtime);
        /* NOTREACHED */
-    case ACL_URL_REGEX:
+    case ACL_URLPATH_REGEX:
        return aclMatchRegex(acl->data, r->urlpath);
        /* NOTREACHED */
+    case ACL_URL_REGEX:
+       return aclMatchRegex(acl->data, urlCanonical(r, NULL));
+       /* NOTREACHED */
     case ACL_URL_PORT:
        return aclMatchInteger(acl->data, r->port);
        /* NOTREACHED */
@@ -830,6 +838,7 @@ void aclDestroyAcls()
            aclDestroyTimeList(a->data);
            break;
        case ACL_URL_REGEX:
+       case ACL_URLPATH_REGEX:
            aclDestroyRegexList(a->data);
            break;
        case ACL_URL_PORT:
index 6bf1c88a0c3c0f107ad8a91b2d29467e72c6194b..15fb22ceabc9032ed79505566dbe782deef95734 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cache_cf.cc,v 1.67 1996/07/27 07:07:41 wessels Exp $
+ * $Id: cache_cf.cc,v 1.68 1996/08/19 22:44:50 wessels Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -154,6 +154,7 @@ struct SquidConfig Config;
 #define DefaultEffectiveUser   (char *)NULL    /* default NONE */
 #define DefaultEffectiveGroup  (char *)NULL    /* default NONE */
 #define DefaultAppendDomain    (char *)NULL    /* default NONE */
+#define DefaultErrHtmlText     (char *)NULL    /* default NONE */
 
 #define DefaultDebugOptions    "ALL,1"         /* All sections at level 1 */
 #define DefaultAccelHost       (char *)NULL    /* default NONE */
@@ -845,7 +846,6 @@ static void parseLocalDomainLine()
     }
 }
 
-
 static void parseInsideFirewallLine()
 {
     char *token;
@@ -978,6 +978,12 @@ static void parseIntegerValue(iptr)
     *iptr = i;
 }
 
+static void parseErrHtmlLine()
+{
+    char *token;
+    if ((token = strtok(NULL, "")))
+       Config.errHtmlText = xstrdup(token);
+}
 
 int parseConfigFile(file_name)
      char *file_name;
@@ -1235,6 +1241,9 @@ int parseConfigFile(file_name)
        else if (!strcmp(token, "ssl_proxy"))
            parseSslProxyLine();
 
+       else if (!strcmp(token, "err_html_text"))
+           parseErrHtmlLine();
+
        else {
            debug(3, 0, "parseConfigFile: line %d unrecognized: '%s'\n",
                config_lineno,
@@ -1311,7 +1320,6 @@ u_short setIcpPortNum(port)
     return (Config.Port.icp = port);
 }
 
-
 static char *safe_xstrdup(p)
      char *p;
 {
@@ -1340,6 +1348,7 @@ static void configFreeMemory()
     safe_free(Config.ftpUser);
     safe_free(Config.Announce.host);
     safe_free(Config.Announce.file);
+    safe_free(Config.errHtmlText);
     wordlistDestroy(&Config.cache_dirs);
     wordlistDestroy(&Config.hierarchy_stoplist);
     wordlistDestroy(&Config.local_domain_list);
@@ -1393,6 +1402,7 @@ static void configSetFactoryDefaults()
     Config.effectiveUser = safe_xstrdup(DefaultEffectiveUser);
     Config.effectiveGroup = safe_xstrdup(DefaultEffectiveGroup);
     Config.appendDomain = safe_xstrdup(DefaultAppendDomain);
+    Config.errHtmlText = safe_xstrdup(DefaultErrHtmlText);
 
     Config.Port.http = DefaultHttpPortNum;
     Config.Port.icp = DefaultIcpPortNum;
index dd5b7cee4c1a6619d758231f3cb21c482b8525f1..5a073bf52bcedaeb351d1dbc5c16fc1061cd79c6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: debug.cc,v 1.20 1996/07/25 07:10:30 wessels Exp $
+ * $Id: debug.cc,v 1.21 1996/08/19 22:44:51 wessels Exp $
  *
  * DEBUG: section 0     Debug Routines
  * AUTHOR: Harvest Derived
 char *_db_file = __FILE__;
 int _db_line = 0;
 
-int syslog_enable = 0;
 FILE *debug_log = NULL;
 static char *debug_log_file = NULL;
 static time_t last_squid_curtime = 0;
@@ -165,7 +164,7 @@ void _db_print(va_alist)
 
 #if HAVE_SYSLOG
     /* level 0 go to syslog */
-    if ((level == 0) && syslog_enable) {
+    if ((level == 0) && opt_syslog_enable) {
        tmpbuf[0] = '\0';
        vsprintf(tmpbuf, f, args);
        syslog(LOG_ERR, tmpbuf);
@@ -246,7 +245,7 @@ void _db_init(logfile, options)
     debugOpenLog(logfile);
 
 #if HAVE_SYSLOG && defined(LOG_LOCAL4)
-    if (syslog_enable)
+    if (opt_syslog_enable)
        openlog(appname, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
 #endif /* HAVE_SYSLOG */
 
index 50345bc49fdeb5ce909cb4fcca9d14826f5aa808..026b2020491aa0eb78001f394b88fb9b551836fa 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: dnsserver.cc,v 1.11 1996/07/25 07:10:32 wessels Exp $
+ * $Id: dnsserver.cc,v 1.12 1996/08/19 22:44:51 wessels Exp $
  *
  * DEBUG: section 0     DNS Resolver
  * AUTHOR: Harvest Derived
@@ -228,7 +228,8 @@ int main(argc, argv)
        /* point stdout to fd */
        dup2(fd, 1);
        dup2(fd, 0);
-       close(fd);
+       if (fd > 1)
+           close(fd);
     }
     while (1) {
        int retry_count = 0;
index c16f7f0a427af5b0ed761b4224e597ab37ccb3ba..6695174ecadb47451c5de5ab62c77b2b0223e5ee 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: errorpage.cc,v 1.28 1996/07/25 07:10:32 wessels Exp $
+ * $Id: errorpage.cc,v 1.29 1996/08/19 22:44:52 wessels Exp $
  *
  * DEBUG: section 4     Error Generation
  * AUTHOR: Duane Wessels
@@ -55,7 +55,9 @@ The following error was encountered:\n\
 <PRE>\n\
     %s\n\
 </PRE>\n\
-<P> <HR>\n\
+<P>\n\
+%s\n\
+<HR>\n\
 <ADDRESS>\n\
 Generated by %s/%s@%s\n\
 </ADDRESS>\n\
@@ -152,13 +154,16 @@ void squid_error_entry(entry, type, msg)
     }
     sprintf(tbuf, SQUID_ERROR_MSG_P3,
        ErrorData[index].lng,
+       Config.errHtmlText,
        appname,
        version_string,
        getMyHostname());
     strcat(tmp_error_buf, tbuf);
-    entry->mem_obj->abort_code = type;
-    if (entry->mem_obj->reply->code == 0)
-       entry->mem_obj->reply->code = 400;
+    if (entry->mem_obj) {
+       entry->mem_obj->abort_code = type;
+       if (entry->mem_obj->reply->code == 0)
+           entry->mem_obj->reply->code = 400;
+    }
     storeAbort(entry, tmp_error_buf);
 }
 
@@ -190,6 +195,7 @@ char *squid_error_url(url, method, type, address, code, msg)
     }
     sprintf(tbuf, SQUID_ERROR_MSG_P3,
        ErrorData[index].lng,
+       Config.errHtmlText,
        appname,
        version_string,
        getMyHostname());
@@ -205,6 +211,8 @@ char *squid_error_url(url, method, type, address, code, msg)
 <PRE>\n\
 %s\n\
 </PRE>\n\
+<P>\n\
+%s\n\
 <HR>\n\
 <ADDRESS>\n\
 Generated by %s/%s@%s\n\
@@ -224,6 +232,7 @@ char *squid_error_request(request, type, address, code)
     sprintf(tmp_error_buf, "HTTP/1.0 %d Cache Detected Error\r\nContent-type: text/html\r\n\r\n", code);
     sprintf(tbuf, SQUID_REQUEST_ERROR_MSG,
        request,
+       Config.errHtmlText,
        appname,
        version_string,
        getMyHostname());
@@ -249,6 +258,8 @@ Sorry, you are not currently allowed to request\n\
 From this cache.  Please check with the\n\
 <A HREF=\"mailto:%s\">cache administrator</A>\n\
 if you believe this is incorrect.\n\
+<P>\n\
+%s\n\
 <HR>\n\
 <ADDRESS>\n\
 Generated by %s/%s@%s\n\
@@ -257,6 +268,7 @@ Generated by %s/%s@%s\n\
        code,
        url,
        Config.adminEmail,
+       Config.errHtmlText,
        appname,
        version_string,
        getMyHostname());
@@ -273,6 +285,8 @@ Sorry, you have to authorize yourself to request\n\
 from this cache.  Please check with the\n\
 <A HREF=\"mailto:%s\">cache administrator</A>\n\
 if you believe this is incorrect.\n\
+<P>\n\
+%s\n\
 <HR>\n\
 <ADDRESS>\n\
 Generated by %s/%s@%s\n\
@@ -282,6 +296,7 @@ Generated by %s/%s@%s\n\
        request->host,
        request->urlpath,
        Config.adminEmail,
+       Config.errHtmlText,
        appname,
        version_string,
        getMyHostname());
index a79455413c31a633cb36210b11cd4f93c4fe3953..037b7627eb2ad21c1d6d0514f63195a8ea5b4a10 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ipcache.cc,v 1.38 1996/07/25 07:10:37 wessels Exp $
+ * $Id: ipcache.cc,v 1.39 1996/08/19 22:44:53 wessels Exp $
  *
  * DEBUG: section 14    IP Cache
  * AUTHOR: Harvest Derived
@@ -362,8 +362,8 @@ static int ipcache_purgelru()
     /* sort LRU candidate list */
     qsort((char *) LRU_list,
        LRU_list_count,
-       sizeof(i),
-       (int (*)(const void *, const void *)) ipcache_compareLastRef);
+       sizeof(ipcache_entry *),
+       (QS) ipcache_compareLastRef);
     for (k = 0; LRU_list[k] && (meta_data.ipcache_count > ipcache_low)
        && k < LRU_list_count;
        ++k) {
index fb7f662effa944d1d97ea20620c6dec532f4fc05..643d55f6c30c6df279feb34586025d9eaf14ecc9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.cc,v 1.59 1996/08/14 22:57:11 wessels Exp $
+ * $Id: main.cc,v 1.60 1996/08/19 22:44:54 wessels Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -117,6 +117,7 @@ int catch_signals = 1;
 int opt_dns_tests = 1;
 int opt_foreground_rebuild = 0;
 int opt_zap_disk_store = 0;
+int opt_syslog_enable = 0;     /* disabled by default */
 int vhost_mode = 0;
 int unbuffered_logs = 1;       /* debug and hierarhcy unbuffered by default */
 int shutdown_pending = 0;      /* set by SIGTERM handler (shut_down()) */
@@ -147,7 +148,7 @@ Usage: %s [-hsvzCDFRUVY] [-f config-file] [-[au] port]\n\
                  %s\n\
        -h        Print help message.\n\
        -s        Enable logging to syslog.\n\
-       -u port   Specify UDP port number (default: %d), disable with 0.\n\
+       -u port   Specify ICP port number (default: %d), disable with 0.\n\
        -v        Print version.\n\
        -z        Zap disk storage -- deletes all objects in disk cache.\n\
        -C        Do not catch fatal signals.\n\
@@ -213,7 +214,7 @@ static void mainParseOptions(argc, argv)
            fatal("Need to add -DMALLOC_DBG when compiling to use -m option");
 #endif
        case 's':
-           syslog_enable = 0;
+           opt_syslog_enable = 1;
            break;
        case 'u':
            icpPortNumOverride = atoi(optarg);
@@ -265,6 +266,10 @@ void shut_down(sig)
     debug(21, 1, "Waiting %d seconds for active connections to finish\n",
        Config.lifetimeShutdown);
     shutdown_pending = 1;
+#if SA_RESETHAND == 0
+    signal(SIGTERM, SIG_DFL);
+    signal(SIGINT, SIG_DFL);
+#endif
 }
 
 void serverConnectionsOpen()
@@ -524,9 +529,6 @@ int main(argc, argv)
     fd_note(1, "STDOUT");
     fd_note(2, "STDERR");
 
-    /* enable syslog by default */
-    syslog_enable = 0;
-
     /* preinit for debug module */
     debug_log = stderr;
     hash_init(0);
index 8970801f069137b1cb4e0b83206d2587329a1f4e..9532c34a33634bc19dba7749587f8f2b387bd354 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: squid.h,v 1.36 1996/08/14 22:57:13 wessels Exp $
+ * $Id: squid.h,v 1.37 1996/08/19 22:44:56 wessels Exp $
  *
  * AUTHOR: Duane Wessels
  *
 #ifndef SA_NODEFER
 #define SA_NODEFER 0
 #endif
-
 #ifndef SA_RESETHAND
-#ifdef SA_ONESHOT
-#define SA_RESETHAND SA_ONESHOT
-#else
 #define SA_RESETHAND 0
-#define HAVE_SIGACTION 0
-#endif /* SA_ONESHOT */
-#endif /* SA_RESETHAND */
+#endif
+#if SA_RESETHAND == 0 && defined(SA_ONESHOT)
+#define SA_RESETHAND SA_ONESHOT
+#endif
 
 typedef struct sentry StoreEntry;
 typedef struct mem_hdr *mem_ptr;
@@ -214,6 +211,7 @@ typedef unsigned long u_num32;
 #include "ansihelp.h"
 
 typedef void (*SIH) _PARAMS((int, void *));    /* swap in */
+typedef int (*QS) _PARAMS((const void *, const void *));
 
 #include "cache_cf.h"
 #include "comm.h"
@@ -269,6 +267,7 @@ extern int opt_reload_hit_only;     /* main.c */
 extern int opt_dns_tests;      /* main.c */
 extern int opt_foreground_rebuild;     /* main.c */
 extern int opt_zap_disk_store; /* main.c */
+extern int opt_syslog_enable;  /* main.c */
 extern int vhost_mode;         /* main.c */
 extern char version_string[];  /* main.c */
 extern char appname[];         /* main.c */
index 31f8541237d8b3fe5f17fd7a2a134268eaca0823..9181176a5d8f36d0210cb143fc803a9e5326e6f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: store.cc,v 1.82 1996/08/17 05:10:28 wessels Exp $
+ * $Id: store.cc,v 1.83 1996/08/19 22:45:31 wessels Exp $
  *
  * DEBUG: section 20    Storeage Manager
  * AUTHOR: Harvest Derived
@@ -212,7 +212,9 @@ static int storeCheckPurgeMem _PARAMS((StoreEntry * e));
 static void storeSwapLog _PARAMS((StoreEntry *));
 static int storeHashDelete _PARAMS((StoreEntry *));
 static char *storeDescribeStatus _PARAMS((StoreEntry *));
-
+static int compareLastRef _PARAMS((StoreEntry ** e1, StoreEntry ** e2));
+static int compareSize _PARAMS((StoreEntry ** e1, StoreEntry ** e2));
+static int storeClientListSearch _PARAMS((MemObject *, int fd));
 
 /* Now, this table is inaccessible to outsider. They have to use a method
  * to access a value in internal storage data structure. */
@@ -280,10 +282,8 @@ static void destroy_MemObject(mem)
     destroy_MemObjectData(mem);
     safe_free(mem->pending);
     if (mem->client_list) {
-       for (i = 0; i < mem->client_list_size; ++i) {
-           if (mem->client_list[i])
-               safe_free(mem->client_list[i]);
-       }
+       for (i = 0; i < mem->client_list_size; i++)
+           safe_free(mem->client_list[i]);
        safe_free(mem->client_list);
     }
     safe_free(mem->mime_hdr);
@@ -509,14 +509,14 @@ int storeLockObject(e, handler, data)
 
     if (e->mem_status != NOT_IN_MEMORY)
        /* ok, its either IN_MEMORY or SWAPPING_IN */
-       debug(20,5,"storeLockObject: OK: mem_status is %s\n", memStatusStr[e->mem_status]);
+       debug(20, 5, "storeLockObject: OK: mem_status is %s\n", memStatusStr[e->mem_status]);
     else if (e->swap_status == SWAP_OK)
        /* ok, its NOT_IN_MEMORY, but its swapped out */
-       debug(20,5,"storeLockObject: OK: swap_status is %s\n", swapStatusStr[e->swap_status]);
+       debug(20, 5, "storeLockObject: OK: swap_status is %s\n", swapStatusStr[e->swap_status]);
     else if (e->store_status == STORE_PENDING)
        /* ok, we're reading it in right now */
-       debug(20,5,"storeLockObject: OK: store_status is %s\n", storeStatusStr[e->store_status]);
-    else 
+       debug(20, 5, "storeLockObject: OK: store_status is %s\n", storeStatusStr[e->store_status]);
+    else
        fatal_dump(storeDescribeStatus(e));
     e->lastref = squid_curtime;
 
@@ -689,7 +689,7 @@ void storeSetPrivateKey(e)
        fatal_dump("Private key already exists.");
     }
     if (e->key)
-       storeHashDelete(e);
+       storeHashDelete((hash_link *) e);
     if (e->key && !BIT_TEST(e->flag, KEY_URL))
        safe_free(e->key);
     e->key = xstrdup(newkey);
@@ -721,7 +721,7 @@ void storeSetPublicKey(e)
        newkey = storeGeneratePublicKey(e->url, e->method);
     }
     if (e->key)
-       storeHashDelete(e);
+       storeHashDelete((hash_link *) e);
     if (e->key && !BIT_TEST(e->flag, KEY_URL))
        safe_free(e->key);
     if (e->method == METHOD_GET) {
@@ -794,11 +794,10 @@ StoreEntry *storeCreateEntry(url, req_hdr, flags, method)
 
     /* allocate client list */
     mem->client_list_size = MIN_CLIENT;
-    mem->client_list = (ClientStatusEntry **)
+    mem->client_list =
        xcalloc(mem->client_list_size, sizeof(ClientStatusEntry *));
     /* storeLog(STORE_LOG_CREATE, e); */
     return e;
-
 }
 
 /* Add a new object to the cache with empty memory copy and pointer to disk
@@ -898,7 +897,6 @@ int storeRegister(e, fd, handler, data)
 
        debug(20, 9, "storeRegister: grew pending list to %d for slot %d.\n",
            mem->pending_list_size, i);
-
     }
     mem->pending[i] = pe;
     return 0;
@@ -913,29 +911,24 @@ int storeUnregister(e, fd)
 {
     int i;
     int freed = 0;
-
+    MemObject *mem = e->mem_obj;
     debug(20, 9, "storeUnregister: called for FD %d '%s'\n", fd, e->key);
-
     /* look for entry in client_list */
-    if (e->mem_obj->client_list) {
-       for (i = 0; i < e->mem_obj->client_list_size; ++i) {
-           if (e->mem_obj->client_list[i] && (e->mem_obj->client_list[i]->fd == fd)) {
-               /* reset fd to zero as a mark for empty slot */
-               safe_free(e->mem_obj->client_list[i]);
-               e->mem_obj->client_list[i] = NULL;
-           }
-       }
+    if ((i = storeClientListSearch(mem, fd)) > -1) {
+       safe_free(mem->client_list[i]);
+       mem->client_list[i] = NULL;
     }
     /* walk the entire list looking for matched fd */
-    for (i = 0; i < (int) e->mem_obj->pending_list_size; i++) {
-       if (e->mem_obj->pending[i] && (e->mem_obj->pending[i]->fd == fd)) {
-           /* found the match fd */
-           safe_free(e->mem_obj->pending[i]);
-           e->mem_obj->pending[i] = NULL;
-           freed++;
-       }
+    for (i = 0; i < (int) mem->pending_list_size; i++) {
+       if (mem->pending[i] == NULL)
+           continue;
+       if (mem->pending[i]->fd != fd)
+           continue;
+       /* found the match fd */
+       safe_free(mem->pending[i]);
+       mem->pending[i] = NULL;
+       freed++;
     }
-
     debug(20, 9, "storeUnregister: returning %d\n", freed);
     return freed;
 }
@@ -1130,6 +1123,9 @@ int storeSwapInHandle(fd_notused, buf, len, flag, e, offset_notused)
     MemObject *mem = e->mem_obj;
     debug(20, 2, "storeSwapInHandle: '%s'\n", e->key);
 
+    if (mem == NULL)           /* XXX remove later */
+       fatal_dump(NULL);
+
     if ((flag < 0) && (flag != DISK_EOF)) {
        debug(20, 0, "storeSwapInHandle: SwapIn failure (err code = %d).\n", flag);
        put_free_8k_page(mem->e_swap_buf);
@@ -1148,6 +1144,9 @@ int storeSwapInHandle(fd_notused, buf, len, flag, e, offset_notused)
     debug(20, 5, "storeSwapInHandle: e->e_current_len = %d\n", mem->e_current_len);
     debug(20, 5, "storeSwapInHandle: e->object_len    = %d\n", e->object_len);
 
+    if (len < 0)               /* XXX remove later */
+       fatal_dump(NULL);
+
     /* always call these, even if len == 0 */
     mem->swap_offset += len;
     storeAppend(e, buf, len);
@@ -1198,14 +1197,13 @@ static int storeSwapInStart(e, swapin_complete_handler, swapin_complete_data)
     MemObject *mem = NULL;
 
     /* sanity check! */
-    if ((e->swap_status != SWAP_OK) || (e->swap_file_number < 0)) {
-       debug(20, 0, "storeSwapInStart: <No filename:%d> ? <URL:%s>\n",
-           e->swap_file_number, e->url);
-       if (e->mem_obj)
-           e->mem_obj->swapin_fd = -1;
-       return -1;
-    }
-    /* create additional structure for object in memory */
+    if (e->swap_status != SWAP_OK)
+       fatal_dump("storeSwapInStart: bad swap_status");
+    if (e->swap_file_number < 0)
+       fatal_dump("storeSwapInStart: bad swap_file_number");
+    if (e->mem_obj)
+       fatal_dump("storeSwapInStart: mem_obj already present");
+
     e->mem_obj = mem = new_MemObject();
 
     path = storeSwapFullPath(e->swap_file_number, NULL);
@@ -1218,7 +1216,6 @@ static int storeSwapInStart(e, swapin_complete_handler, swapin_complete_data)
     mem->swapin_fd = (short) fd;
     debug(20, 5, "storeSwapInStart: initialized swap file '%s' for <URL:%s>\n",
        path, e->url);
-
     storeSetMemStatus(e, SWAPPING_IN);
     mem->data = new_MemObjectData();
     mem->swap_offset = 0;
@@ -1347,8 +1344,8 @@ static int storeSwapOutStart(e)
      StoreEntry *e;
 {
     int fd;
-    LOCAL_ARRAY(char, swapfilename, MAX_FILE_NAME_LEN);
     int x;
+    LOCAL_ARRAY(char, swapfilename, MAX_FILE_NAME_LEN);
     MemObject *mem = e->mem_obj;
     /* Suggest a new swap file number */
     swapfileno = (swapfileno + 1) % (MAX_SWAP_FILE);
@@ -1596,7 +1593,7 @@ void storeStartRebuildFromDisk()
     }
     data = xcalloc(1, sizeof(*data));
 
-    for (i = 0; i < ncache_dirs; ++i)
+    for (i = 0; i < ncache_dirs; i++)
        debug(20, 1, "Rebuilding storage from disk image in %s\n", swappath(i));
     data->start = getCurrentTime();
 
@@ -1694,7 +1691,6 @@ void storeComplete(e)
      StoreEntry *e;
 {
     debug(20, 3, "storeComplete: '%s'\n", e->key);
-
     e->object_len = e->mem_obj->e_current_len;
     InvokeHandlers(e);
     e->lastref = squid_curtime;
@@ -1721,6 +1717,9 @@ int storeAbort(e, msg)
     LOCAL_ARRAY(char, abort_msg, 2000);
     MemObject *mem = e->mem_obj;
 
+    if (mem == NULL)           /* XXX remove later */
+       fatal_dump("storeAbort: null mem");
+
     debug(20, 6, "storeAbort: '%s'\n", e->key);
     e->expires = squid_curtime + Config.negativeTtl;
     e->store_status = STORE_ABORTED;
@@ -1905,7 +1904,6 @@ int storeGetMemSpace(size, check_vm_number)
     int compareLastRef();
     int compareSize();
 
-
     if (!check_vm_number && ((store_mem_size + size) < store_mem_high))
        return 0;
 
@@ -1957,13 +1955,16 @@ int storeGetMemSpace(size, check_vm_number)
     debug(20, 5, "storeGetMemSpace: Can't purge size: %7d bytes\n", locked_bytes);
     debug(20, 5, "storeGetMemSpace: Sorting LRU_list: %7d items\n", LRU_list->index);
 #endif
-    qsort((char *) LRU_list->collection, LRU_list->index, sizeof(e), (int (*)(const void *, const void *)) compareLastRef);
+    qsort((char *) LRU_list->collection,
+       LRU_list->index,
+       sizeof(StoreEntry *),
+       (QS) compareLastRef);
 
     /* Kick LRU out until we have enough memory space */
 
     if (check_vm_number) {
        /* look for vm slot */
-       for (i = 0; (i < LRU_list->index) && (meta_data.hot_vm > store_hotobj_low); ++i) {
+       for (i = 0; (i < LRU_list->index) && (meta_data.hot_vm > store_hotobj_low); i++) {
            if ((LRU = (StoreEntry *) LRU_list->collection[i]))
                if ((LRU->store_status != STORE_PENDING) && (LRU->swap_status == NO_SWAP)) {
                    n_released++;
@@ -1975,7 +1976,7 @@ int storeGetMemSpace(size, check_vm_number)
        }
     } else {
        /* look for space */
-       for (i = 0; (i < LRU_list->index) && ((store_mem_size + size) > store_mem_low); ++i) {
+       for (i = 0; (i < LRU_list->index) && ((store_mem_size + size) > store_mem_low); i++) {
            if ((LRU = (StoreEntry *) LRU_list->collection[i]))
                if ((LRU->store_status != STORE_PENDING) && (LRU->swap_status == NO_SWAP)) {
                    n_released++;
@@ -2033,8 +2034,11 @@ int storeGetMemSpace(size, check_vm_number)
     }
 
     /* sort the stuff by size */
-    qsort((char *) pending_entry_list->collection, pending_entry_list->index, sizeof(e), (int (*)(const void *, const void *)) compareSize);
-    for (i = 0; (i < pending_entry_list->index) && (i < entry_to_delete_behind); ++i)
+    qsort((char *) pending_entry_list->collection,
+       pending_entry_list->index,
+       sizeof(StoreEntry *),
+       (QS) compareSize);
+    for (i = 0; (i < pending_entry_list->index) && (i < entry_to_delete_behind); i++)
        if (pending_entry_list->collection[i]) {
            n_deleted_behind++;
            storeStartDeleteBehind(pending_entry_list->collection[i]);
@@ -2048,34 +2052,27 @@ int storeGetMemSpace(size, check_vm_number)
     return 0;
 }
 
-int compareSize(e1, e2)
+static int compareSize(e1, e2)
      StoreEntry **e1, **e2;
 {
-    if (!e1 || !e2) {
-       debug(20, 1, "compareSize: Called with at least one null argument, shouldn't happen.\n");
-       return 0;
-    }
+    if (!e1 || !e2)
+       fatal_dump(NULL);
     if ((*e1)->mem_obj->e_current_len > (*e2)->mem_obj->e_current_len)
        return (1);
-
     if ((*e1)->mem_obj->e_current_len < (*e2)->mem_obj->e_current_len)
        return (-1);
-
     return (0);
 }
 
-int compareLastRef(e1, e2)
+static int compareLastRef(e1, e2)
      StoreEntry **e1, **e2;
 {
     if (!e1 || !e2)
        fatal_dump(NULL);
-
     if ((*e1)->lastref > (*e2)->lastref)
        return (1);
-
     if ((*e1)->lastref < (*e2)->lastref)
        return (-1);
-
     return (0);
 }
 
@@ -2085,7 +2082,6 @@ int compareLastRef(e1, e2)
 unsigned int storeGetBucketNum()
 {
     static unsigned int bucket = 0;
-
     if (bucket >= STORE_BUCKETS)
        bucket = 0;
     return (bucket++);
@@ -2134,7 +2130,7 @@ int storeGetSwapSpace(size)
 
     LRU_list = create_dynamic_array(LRU_cur_size, LRU_cur_size);
     /* remove expired objects until recover enough space or no expired objects */
-    for (i = 0; i < STORE_BUCKETS; ++i) {
+    for (i = 0; i < STORE_BUCKETS; i++) {
        int expired_in_one_bucket = 0;
 
        link_ptr = hash_get_bucket(store_table, storeGetBucketNum());
@@ -2179,7 +2175,10 @@ int storeGetSwapSpace(size)
                expired);
            return 0;
        }
-       qsort((char *) LRU_list->collection, LRU_list->index, sizeof(e), (int (*)(const void *, const void *)) compareLastRef);
+       qsort((char *) LRU_list->collection,
+           LRU_list->index,
+           sizeof(StoreEntry *),
+           (QS) compareLastRef);
        /* keep the first n LRU objects only */
        cut_dynamic_array(LRU_list, SWAP_LRU_REMOVE_COUNT);
 
@@ -2216,7 +2215,7 @@ int storeGetSwapSpace(size)
 
     /* Although all expired objects removed, still didn't recover enough */
     /* space.  Kick LRU out until we have enough swap space */
-    for (i = 0; i < LRU_list->index; ++i) {
+    for (i = 0; i < LRU_list->index; i++) {
        if (store_swap_size + kb_size <= store_swap_low) {
            fReduceSwap = 0;
            break;
@@ -2400,16 +2399,16 @@ int storeClientWaiting(e)
      StoreEntry *e;
 {
     int i;
-
-    if (e->mem_obj->client_list) {
-       for (i = 0; i < e->mem_obj->client_list_size; ++i) {
-           if (e->mem_obj->client_list[i])
+    MemObject *mem = e->mem_obj;
+    if (mem->client_list) {
+       for (i = 0; i < mem->client_list_size; i++) {
+           if (mem->client_list[i])
                return 1;
        }
     }
-    if (e->mem_obj->pending) {
-       for (i = 0; i < (int) e->mem_obj->pending_list_size; ++i) {
-           if (e->mem_obj->pending[i])
+    if (mem->pending) {
+       for (i = 0; i < (int) mem->pending_list_size; i++) {
+           if (mem->pending[i])
                return 1;
        }
     }
@@ -2417,18 +2416,19 @@ int storeClientWaiting(e)
 }
 
 /* return index to matched clientstatus in client_list, -1 on NOT_FOUND */
-int storeClientListSearch(e, fd)
-     StoreEntry *e;
+static int storeClientListSearch(mem, fd)
+     MemObject *mem;
      int fd;
 {
     int i;
-
-    if (!e->mem_obj->client_list)
-       return -1;
-    for (i = 0; i < e->mem_obj->client_list_size; ++i) {
-       if (e->mem_obj->client_list[i] &&
-           (fd == e->mem_obj->client_list[i]->fd))
+    if (mem->client_list) {
+       for (i = 0; i < mem->client_list_size; i++) {
+           if (mem->client_list[i] == NULL)
+               continue;
+           if (mem->client_list[i]->fd != fd)
+               continue;
            return i;
+       }
     }
     return -1;
 }
@@ -2440,26 +2440,34 @@ void storeClientListAdd(e, fd, last_offset)
      int last_offset;
 {
     int i;
+    MemObject *mem = e->mem_obj;
+    ClientStatusEntry **oldlist = NULL;
+    int oldsize;
     /* look for empty slot */
-
-    if (e->mem_obj->client_list) {
-       for (i = 0; (i < e->mem_obj->client_list_size)
-           && (e->mem_obj->client_list[i] != NULL); ++i);
-
-       if (i == e->mem_obj->client_list_size) {
-           /* have to expand client_list */
-           e->mem_obj->client_list_size += MIN_CLIENT;
-           e->mem_obj->client_list = xrealloc(e->mem_obj->client_list, e->mem_obj->client_list_size * sizeof(ClientStatusEntry *));
-       }
-    } else {
-       e->mem_obj->client_list_size += MIN_CLIENT;
-       e->mem_obj->client_list = xcalloc(e->mem_obj->client_list_size, sizeof(ClientStatusEntry *));
-       i = 0;
+    if (mem->client_list == NULL) {
+       mem->client_list_size = MIN_CLIENT;
+       mem->client_list =
+           xcalloc(mem->client_list_size, sizeof(ClientStatusEntry *));
     }
-
-    e->mem_obj->client_list[i] = xcalloc(1, sizeof(ClientStatusEntry));
-    e->mem_obj->client_list[i]->fd = fd;
-    e->mem_obj->client_list[i]->last_offset = last_offset;
+    for (i = 0; i < mem->client_list_size; i++) {
+       if (mem->client_list[i] == NULL)
+           break;
+    }
+    if (i == mem->client_list_size) {
+       debug(20, 3, "storeClientListAdd: FD %d Growing client_list for '%s'\n",
+           fd, e->url);
+       oldlist = mem->client_list;
+       oldsize = mem->client_list_size;
+       mem->client_list_size <<= 1;
+       mem->client_list =
+           xcalloc(mem->client_list_size, sizeof(ClientStatusEntry *));
+       for (i = 0; i < oldsize; i++)
+           mem->client_list[i] = oldlist[i];
+       safe_free(oldlist);
+    }
+    mem->client_list[i] = xcalloc(1, sizeof(ClientStatusEntry));
+    mem->client_list[i]->fd = fd;
+    mem->client_list[i]->last_offset = last_offset;
 }
 
 /* same to storeCopy but also register client fd and last requested offset
@@ -2475,32 +2483,32 @@ int storeClientCopy(e, stateoffset, maxSize, buf, size, fd)
     int next_offset;
     int client_list_index;
     int available_to_write = e->mem_obj->e_current_len - stateoffset;
+    MemObject *mem = e->mem_obj;
 
-    if (stateoffset < e->mem_obj->e_lowest_offset) {
+    if (stateoffset < mem->e_lowest_offset) {
        /* this should not happen. Logic race !!! */
        debug(20, 1, "storeClientCopy: Client Request a chunk of data in area lower than the lowest_offset\n");
        debug(20, 1, "                              fd : %d\n", fd);
-       debug(20, 1, "           Current Lowest offset : %d\n", e->mem_obj->e_lowest_offset);
+       debug(20, 1, "           Current Lowest offset : %d\n", mem->e_lowest_offset);
        debug(20, 1, "           Requested offset      : %d\n", stateoffset);
        /* can't really do anything here. Client may hang until lifetime runout. */
        return 0;
     }
-    *size = (available_to_write >= maxSize) ?
-       maxSize : available_to_write;
+    *size = (available_to_write >= maxSize) ? maxSize : available_to_write;
 
     debug(20, 6, "storeCopy: avail_to_write=%d, store_offset=%d\n",
        *size, stateoffset);
 
     /* update the lowest requested offset */
     next_offset = (stateoffset + *size);
-    if ((client_list_index = storeClientListSearch(e, fd)) >= 0) {
-       e->mem_obj->client_list[client_list_index]->last_offset = next_offset;
+    if ((client_list_index = storeClientListSearch(mem, fd)) >= 0) {
+       mem->client_list[client_list_index]->last_offset = next_offset;
     } else {
        storeClientListAdd(e, fd, next_offset);
     }
 
     if (*size > 0)
-       (void) e->mem_obj->data->mem_copy(e->mem_obj->data, stateoffset, buf, *size);
+       (void) mem->data->mem_copy(mem->data, stateoffset, buf, *size);
 
     /* see if we can get rid of some data if we are in "delete behind" mode . */
     if (e->flag & DELETE_BEHIND) {
@@ -2580,7 +2588,7 @@ static int storeVerifySwapDirs(clean)
     int directory_created = 0;
     char *cmdbuf = NULL;
 
-    for (inx = 0; inx < ncache_dirs; ++inx) {
+    for (inx = 0; inx < ncache_dirs; inx++) {
        path = swappath(inx);
        debug(20, 9, "storeVerifySwapDirs: Creating swap space in %s\n", path);
        if (stat(path, &sb) < 0) {
index 4773e811f1b5deeba226198edc425a1b82b720e4..239e5e8ec809146c88d671bbf339ef4c8d914685 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tools.cc,v 1.46 1996/07/25 07:10:44 wessels Exp $
+ * $Id: tools.cc,v 1.47 1996/08/19 22:44:57 wessels Exp $
  *
  * DEBUG: section 21    Misc Functions
  * AUTHOR: Harvest Derived
@@ -130,31 +130,21 @@ static char *dead_msg()
 void mail_warranty()
 {
     FILE *fp = NULL;
-    LOCAL_ARRAY(char, filename, 256);
-    LOCAL_ARRAY(char, command, 256);
-
-    sprintf(filename, "/tmp/mailin%d", (int) getpid());
-    fp = fopen(filename, "w");
-    if (fp != NULL) {
-       fprintf(fp, "From: %s\n", appname);
-       fprintf(fp, "To: %s\n", Config.adminEmail);
-       fprintf(fp, "Subject: %s\n", dead_msg());
-       fclose(fp);
-       sprintf(command, "mail %s < %s", Config.adminEmail, filename);
-       system(command);        /* XXX should avoid system(3) */
-       unlink(filename);
-    }
-}
-
-void print_warranty()
-{
-    if (Config.adminEmail)
-       mail_warranty();
-    else
-       puts(dead_msg());
+    char *filename;
+    static char command[256];
+    if ((filename = tempnam(NULL, appname)) == NULL)
+       return;
+    if ((fp = fopen(filename, "w")) == NULL)
+       return;
+    fprintf(fp, "From: %s\n", appname);
+    fprintf(fp, "To: %s\n", getAdminEmail());
+    fprintf(fp, "Subject: %s\n", dead_msg());
+    fclose(fp);
+    sprintf(command, "mail %s < %s", getAdminEmail(), filename);
+    system(command);           /* XXX should avoid system(3) */
+    unlink(filename);
 }
 
-
 static void dumpMallocStats(f)
      FILE *f;
 {
@@ -233,17 +223,23 @@ void death(sig)
     if (sig == SIGSEGV)
        fprintf(debug_log, "FATAL: Received Segment Violation...dying.\n");
     else if (sig == SIGBUS)
-       fprintf(debug_log, "FATAL: Received bus error...dying.\n");
+       fprintf(debug_log, "FATAL: Received Bus Error...dying.\n");
     else
        fprintf(debug_log, "FATAL: Received signal %d...dying.\n", sig);
-#if !HAVE_SIGACTION
+#if SA_RESETHAND == 0
     signal(SIGSEGV, SIG_DFL);
     signal(SIGBUS, SIG_DFL);
     signal(sig, SIG_DFL);
 #endif
     storeWriteCleanLog();
     PrintRusage(NULL, debug_log);
-    print_warranty();
+    if (squid_curtime - SQUID_RELEASE_TIME < 864000) {
+       /* skip if more than 10 days old */
+       if (getAdminEmail())
+           mail_warranty();
+       else
+           puts(dead_msg());
+    }
     abort();
 }
 
@@ -303,7 +299,7 @@ void fatal_common(message)
      char *message;
 {
 #if HAVE_SYSLOG
-    if (syslog_enable)
+    if (opt_syslog_enable)
        syslog(LOG_ALERT, message);
 #endif
     fprintf(debug_log, "FATAL: %s\n", message);