]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Miscellaneous useful changes from 3p1-rock (r9630) unrelated to Rock Store.
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 27 Jan 2011 21:16:49 +0000 (14:16 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 27 Jan 2011 21:16:49 +0000 (14:16 -0700)
14 files changed:
src/Server.cc
src/adaptation/ServiceConfig.cc
src/adaptation/icap/Elements.cc
src/adaptation/icap/Elements.h
src/adaptation/icap/ServiceRep.h
src/adaptation/icap/Xaction.cc
src/client_side.cc
src/ipcache.cc
src/log/FormatSquidCustom.cc
src/log/FormatSquidIcap.cc
src/log/Tokens.h
src/main.cc
src/mem.cc
src/store.cc

index 8256a1f77a2f9c6a45a8e154102d37a7d6a18d7d..59d27d14af7646ebf21785be94e8b899f6cea657 100644 (file)
@@ -379,10 +379,10 @@ ServerStateData::sentRequestBody(const CommIoCbParams &io)
     }
 
     if (io.flag) {
-        debugs(11, 1, "sentRequestBody error: FD " << io.fd << ": " << xstrerr(errno));
+        debugs(11, 1, "sentRequestBody error: FD " << io.fd << ": " << xstrerr(io.xerrno));
         ErrorState *err;
         err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request);
-        err->xerrno = errno;
+        err->xerrno = io.xerrno;
         fwd->fail(err);
         abortTransaction("I/O error while sending request body");
         return;
index 176ce2110ae20cfd5ae2c71b5f75418ebca04f31..612432365f822299ee221d3d703d5e90f6932cf1 100644 (file)
@@ -69,6 +69,7 @@ Adaptation::ServiceConfig::parse()
 
     // handle optional service name=value parameters
     const char *lastOption = NULL;
+    bool grokkedUri = false;
     while (char *option = strtok(NULL, w_space)) {
         if (strcmp(option, "0") == 0) { // backward compatibility
             bypass = false;
@@ -94,6 +95,8 @@ Adaptation::ServiceConfig::parse()
             grokked = grokBool(bypass, name, value);
         else if (strcmp(name, "routing") == 0)
             grokked = grokBool(routing, name, value);
+        else if (strcmp(name, "uri") == 0)
+            grokked = grokkedUri = grokUri(value);
         else if (strcmp(name, "ipv6") == 0) {
             grokked = grokBool(ipv6, name, value);
             if (grokked && ipv6 && !Ip::EnableIpv6)
@@ -107,7 +110,7 @@ Adaptation::ServiceConfig::parse()
     }
 
     // what is left must be the service URI
-    if (!grokUri(lastOption))
+    if (!grokkedUri && !grokUri(lastOption))
         return false;
 
     // there should be nothing else left
index 17a26130d7400a538ded426bc896147805f769b8..ac82c70ad419137f5150c7bf2a9ac88a505656af 100644 (file)
@@ -8,6 +8,7 @@ namespace Icap
 {
 
 const XactOutcome xoUnknown = "ICAP_ERR_UNKNOWN";
+const XactOutcome xoGone = "ICAP_ERR_GONE";
 const XactOutcome xoRace = "ICAP_ERR_RACE";
 const XactOutcome xoError = "ICAP_ERR_OTHER";
 const XactOutcome xoOpt = "ICAP_OPT";
index ec78a55f6c420175fd6b56961085200d9e24db5f..1e9ad8e18c0328d737ce1cb66e61c2e84ea5dcbf 100644 (file)
@@ -64,6 +64,7 @@ using Adaptation::vectPointStr;
 
 typedef const char *XactOutcome; ///< transaction result for logging
 extern const XactOutcome xoUnknown; ///< initial value: outcome was not set
+extern const XactOutcome xoGone; ///< initiator gone, will not continue
 extern const XactOutcome xoRace; ///< ICAP server closed pconn when we started
 extern const XactOutcome xoError; ///< all kinds of transaction errors
 extern const XactOutcome xoOpt; ///< OPTION transaction
index fa67bde23aec2b1c516f1858b1c1a3348b681509..54fb70c3cdcafe96babc2a7530f85ed1fe2cfbc5 100644 (file)
@@ -92,6 +92,8 @@ public:
 
     virtual void finalize();
 
+    void invalidate(); // call when the service is no longer needed or valid
+
     virtual bool probed() const; // see comments above
     virtual bool up() const; // see comments above
 
index 3e1f3b5d4156e3a158cacefb655d7dda97eb5911..b327fe006547b1b7f31e1dbd7fd0bc13c2f4a04a 100644 (file)
@@ -196,10 +196,14 @@ void Adaptation::Icap::Xaction::closeConnection()
                                 theService->cfg().port, NULL, client_addr);
             disableRetries();
         } else {
-            //status() adds leading spaces.
-            debugs(93,3, HERE << "closing pconn" << status());
+            const bool reset = al.icap.outcome == xoGone || al.icap.outcome == xoError;
+            debugs(93,3, HERE << (reset ? "RST" : "FIN") << "-closing" <<
+                   status());
             // comm_close will clear timeout
-            comm_close(connection);
+            if (reset)
+                comm_reset_close(connection);
+            else
+                comm_close(connection);
         }
 
         writer = NULL;
@@ -444,8 +448,10 @@ void Adaptation::Icap::Xaction::noteInitiatorAborted()
 {
 
     if (theInitiator.set()) {
+        debugs(93,4, HERE << "Initiator gone before ICAP transaction ended");
         clearInitiator();
         detailError(ERR_DETAIL_ICAP_INIT_GONE);
+        setOutcome(xoGone);
         mustStop("initiator aborted");
     }
 
index d961801a5f8e8eaf8253b2f8f2a62fe51dae3f62..8943d7b8b8b837753c8cc48128b7570648d5a1ad 100644 (file)
@@ -615,7 +615,10 @@ prepareLogWithRequestDetails(HttpRequest * request, AccessLogEntry * aLogEntry)
 void
 ClientHttpRequest::logRequest()
 {
-    if (out.size || logType) {
+    if (!out.size && !logType)
+        debugs(33,2, HERE << "logging half-baked transaction: " << log_uri);
+
+    if (true) {
         al.icp.opcode = ICP_INVALID;
         al.url = log_uri;
         debugs(33, 9, "clientLogRequest: al.url='" << al.url << "'");
@@ -2244,8 +2247,10 @@ parseHttpRequest(ConnStateData *conn, HttpParser *hp, HttpRequestMethod * method
 int
 ConnStateData::getAvailableBufferLength() const
 {
-    int result = in.allocatedSize - in.notYetUsed - 1;
-    assert (result >= 0);
+    assert (in.allocatedSize > in.notYetUsed); // allocated more than used
+    const size_t result = in.allocatedSize - in.notYetUsed - 1;
+    // huge request_header_max_size may lead to more than INT_MAX unused space
+    assert (static_cast<ssize_t>(result) <= INT_MAX);
     return result;
 }
 
index 926b906e5c20f18011432482ea6f73e1e2d76cec..b4a1f725a65cf7784d8989ad6aff686d21ad9d4c 100644 (file)
@@ -161,6 +161,9 @@ static long ipcache_high = 200;
 extern int _dns_ttl_;
 #endif
 
+/// \ingroup IPCacheInternal
+inline int ipcacheCount() { return ip_table ? ip_table->count : 0; }
+
 int
 ipcache_entry::age() const
 {
@@ -235,7 +238,7 @@ ipcache_purgelru(void *voidnotused)
     eventAdd("ipcache_purgelru", ipcache_purgelru, NULL, 10.0, 1);
 
     for (m = lru_list.tail; m; m = prev) {
-        if (memInUse(MEM_IPCACHE_ENTRY) < ipcache_low)
+        if (ipcacheCount() < ipcache_low)
             break;
 
         prev = m->prev;
@@ -855,8 +858,10 @@ stat_ipcache_get(StoreEntry * sentry)
     dlink_node *m;
     assert(ip_table != NULL);
     storeAppendPrintf(sentry, "IP Cache Statistics:\n");
-    storeAppendPrintf(sentry, "IPcache Entries:  %d\n",
+    storeAppendPrintf(sentry, "IPcache Entries In Use:  %d\n",
                       memInUse(MEM_IPCACHE_ENTRY));
+    storeAppendPrintf(sentry, "IPcache Entries Cached:  %d\n",
+                      ipcacheCount());
     storeAppendPrintf(sentry, "IPcache Requests: %d\n",
                       IpcacheStats.requests);
     storeAppendPrintf(sentry, "IPcache Hits:            %d\n",
@@ -1231,7 +1236,7 @@ snmp_netIpFn(variable_list * Var, snint * ErrP)
 
     case IP_ENT:
         Answer = snmp_var_new_integer(Var->name, Var->name_length,
-                                      memInUse(MEM_IPCACHE_ENTRY),
+                                      ipcacheCount(),
                                       SMI_GAUGE32);
         break;
 
index f1a031ceac584717455d0fd0af231791c28e1130..67d45a23b9a593739d02e542e6e5d7b58c0cea13 100644 (file)
@@ -794,11 +794,18 @@ Log::Format::SquidCustom(AccessLogEntry * al, customlog * log)
                 }
             }
 
-            if (fmt->width) {
+            // enforce width limits if configured
+            const bool haveMaxWidth = fmt->precision && !doint && !dooff;
+            if (haveMaxWidth || fmt->width) {
+                const int minWidth = fmt->width ?
+                                     static_cast<int>(fmt->width) : 0;
+                const int maxWidth = haveMaxWidth ?
+                                     static_cast<int>(fmt->precision) : strlen(out);
+
                 if (fmt->left)
-                    mb.Printf("%-*s", (int) fmt->width, out);
+                    mb.Printf("%-*.*s", minWidth, maxWidth, out);
                 else
-                    mb.Printf("%*s", (int) fmt->width, out);
+                    mb.Printf("%*.*s", minWidth, maxWidth, out);
             } else
                 mb.append(out, strlen(out));
         } else {
index 5fccc88f9eb5ee8661df4f5ff14402560af23104..929d8817136694ea96d9cc13ef1e65b59702db56 100644 (file)
@@ -75,11 +75,12 @@ Log::Format::SquidIcap(AccessLogEntry * al, Logfile * logfile)
     if (user && !*user)
         safe_free(user);
 
-    logfilePrintf(logfile, "%9ld.%03d %6d %s -/%03d %"PRId64" %s %s %s -/%s -\n",
+    logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %"PRId64" %s %s %s -/%s -\n",
                   (long int) current_time.tv_sec,
                   (int) current_time.tv_usec / 1000,
                   al->icap.trTime,
                   client,
+                  al->icap.outcome,
                   al->icap.resStatus,
                   al->icap.bytesRead,
                   Adaptation::Icap::ICAP::methodStr(al->icap.reqMethod),
index 36316d454e6c455c45ed3797d6339534a7a49a6b..0890c04d653a28dbe385bc745aca2f05a4215acf 100644 (file)
@@ -189,8 +189,8 @@ public:
         } header;
         char *timespec;
     } data;
-    unsigned char width;
-    unsigned char precision;
+    unsigned int width;
+    unsigned int precision;
     enum log_quote quote;
     unsigned int left:1;
     unsigned int space:1;
index 662c6ef629720efee60853ef60c2d47689e33e4f..597f03d57940417a4a6188f77673b4a4bb92fc56 100644 (file)
@@ -1208,10 +1208,10 @@ SquidMainSafe(int argc, char **argv)
     try {
         return SquidMain(argc, argv);
     } catch (const std::exception &e) {
-        std::cerr << "dying from an unhandled exception: " << e.what() << std::endl;
+        debugs(0,0, "dying from an unhandled exception: " << e.what());
         throw;
     } catch (...) {
-        std::cerr << "dying from an unhandled exception." << std::endl;
+        debugs(0,0, "dying from an unhandled exception.");
         throw;
     }
     return -1; // not reached
index 9970cd39b5466dd0ad5a052c33697bf0a7aa3139..14b5c94a9a614f92dfe8cb87dcf79569deb31b0e 100644 (file)
@@ -489,7 +489,8 @@ void
 memClean(void)
 {
     MemPoolGlobalStats stats;
-    MemPools::GetInstance().setIdleLimit(0);
+    if (Config.MemPools.limit > 0) // do not reset if disabled or same
+        MemPools::GetInstance().setIdleLimit(0);
     MemPools::GetInstance().clean(0);
     memPoolGetGlobalStats(&stats);
 
index 72f7d0829d14e3e45fa5efd5160aceefc6deb0f5..f9b692402ff6dc9ec4331ab5351a3e19acd0b925 100644 (file)
@@ -254,6 +254,16 @@ StoreEntry::delayAwareRead(int fd, char *buf, int len, AsyncCall::Pointer callba
 
     }
 
+    if (fd_table[fd].closing()) {
+        // Readers must have closing callbacks if they want to be notified. No
+        // readers appeared to care around 2009/12/14 as they skipped reading
+        // for other reasons. Closing may already be true at the delyaAwareRead
+        // call time or may happen while we wait after delayRead() above.
+        debugs(20, 3, HERE << "wont read from closing FD " << fd << " for " <<
+               callback);
+        return; // the read callback will never be called
+    }
+
     comm_read(fd, buf, amountToRead, callback);
 }