Misc fixes

From: Stephen R. van den Berg <srb@dont-contact.us>
Date: Mon, 24 Aug 1998 14:32:44 +0200

These were some miscellaneous fixes I have accumulated over time.
Some might even be redundant.
I'll comment them as we go along.

********************************************************
First, some checks for EAGAIN signal interruptions.
********************************************************

diff -u -b -r squid-1.2.beta24/src/aiops.c squid-BuGless/src/aiops.c
--- squid-1.2.beta24/src/aiops.c Tue Aug 18 21:13:57 1998
+++ squid-BuGless/src/aiops.c Mon Aug 24 12:54:31 1998
@@ -584,7 +584,9 @@
 aio_do_read(aio_request_t * requestp)
 {
     lseek(requestp->fd, requestp->offset, requestp->whence);
- requestp->ret = read(requestp->fd, requestp->tmpbufp, requestp->buflen);
+ while((requestp->ret =
+ read(requestp->fd, requestp->tmpbufp, requestp->buflen)) < 0 &&
+ errno == EAGAIN);
     requestp->err = errno;
 }
 
@@ -622,7 +624,9 @@
 static void
 aio_do_write(aio_request_t * requestp)
 {
- requestp->ret = write(requestp->fd, requestp->tmpbufp, requestp->buflen);
+ while((requestp->ret =
+ write(requestp->fd, requestp->tmpbufp, requestp->buflen)) < 0 &&
+ errno == EAGAIN);
     requestp->err = errno;
 }
 
@@ -651,7 +655,10 @@
 static void
 aio_do_close(aio_request_t * requestp)
 {
- requestp->ret = close(requestp->fd);
+ if((requestp->ret = close(requestp->fd))<0) {
+ debug(43, 0) ("aio_do_close: FD %d, errno %d\n", requestp->fd, errno);
+ close(requestp->fd);
+ }
     requestp->err = errno;
 }
 
diff -u -b -r squid-1.2.beta24/src/async_io.c squid-BuGless/src/async_io.c
--- squid-1.2.beta24/src/async_io.c Tue Aug 18 23:15:43 1998
+++ squid-BuGless/src/async_io.c Sat Aug 22 03:32:19 1998
@@ -127,8 +127,7 @@
         aioInit();
     aioCancel(fd, NULL);
     if (free_list == NULL) {
- close(fd);
- return;
+ goto force_close;
     }
     ctrlp = free_list;
     ctrlp->fd = fd;
@@ -137,7 +136,9 @@
     ctrlp->done_handler_data = NULL;
     ctrlp->operation = _AIO_CLOSE;
     if (aio_close(fd, &(ctrlp->result)) < 0) {
- close(fd); /* Can't create thread - do a normal close */
+force_close:
+ if(close(fd)) /* Can't create thread - do a normal close */
+ debug(0,0) ("aioClose: FD %d, errno %d\n", fd, errno), close(fd);
         return;
     }
     free_list = free_list->next;
diff -u -b -r squid-1.2.beta24/src/comm.c squid-BuGless/src/comm.c
--- squid-1.2.beta24/src/comm.c Wed Aug 19 00:42:17 1998
+++ squid-BuGless/src/comm.c Sun Aug 23 23:32:11 1998
@@ -573,7 +573,8 @@
      * michael@metal.iinet.net.au sez close() on
      * network sockets never blocks.
      */
- close(fd);
+ if(close(fd))
+ debug(50, 0) ("comm_close: FD %d, %s\n", fd, xstrerror()), close(fd);
 #elif USE_ASYNC_IO
     if (doaioclose)
         aioClose(fd);

********************************************************
Allow for small swaps; and fix a bug with the refresh
options
********************************************************

diff -u -b -r squid-1.2.beta24/src/cache_cf.c squid-BuGless/src/cache_cf.c
--- squid-1.2.beta24/src/cache_cf.c Fri Aug 21 18:58:11 1998
+++ squid-BuGless/src/cache_cf.c Mon Aug 24 04:02:19 1998
@@ -219,7 +219,7 @@
     /* calculate Config.Swap.maxSize */
     storeDirConfigure();
     if (Config.Swap.maxSize < (Config.Mem.maxSize >> 10))
- fatal("cache_swap is lower than cache_mem");
+ debug(3, 0) ("configDoConfigure: cache_swap is lower than cache_mem");
     if (Config.Announce.period > 0) {
         Config.onoff.announce = 1;
     } else if (Config.Announce.period < 1) {
@@ -1183,7 +1183,7 @@
 #if HTTP_VIOLATIONS
         if (!strcmp(token, "override-expire"))
             override_expire = 1;
- else if (!strcmp(token, "override-expire"))
+ else if (!strcmp(token, "override-lastmod"))
             override_lastmod = 1;
         else if (!strcmp(token, "reload-into-ims")) {
             reload_into_ims = 1;

********************************************************
I kind of liked the clickable statistics in 1.1,
here they are again.
********************************************************

diff -u -b -r squid-1.2.beta24/src/cachemgr.c squid-BuGless/src/cachemgr.c
--- squid-1.2.beta24/src/cachemgr.c Fri Aug 14 21:25:14 1998
+++ squid-BuGless/src/cachemgr.c Sat Aug 22 03:50:12 1998
@@ -345,7 +345,7 @@
 {
     static const char *ttags[] =
     {"td", "th"};
- static char html[4096];
+ static char html[4096*4];
     static int table_line_num = 0;
     static int next_is_header = 0;
     int is_header = 0;
@@ -359,7 +359,7 @@
         snprintf(html, sizeof(html), "%s%s",
             table_line_num ? "</table>\n<pre>" : "", buf);
         table_line_num = 0;
- return html;
+ goto ret;
     }
     /* start html table */
     if (!table_line_num) {
@@ -392,6 +392,37 @@
     l += snprintf(html + l, sizeof(html) - l, "</tr>\n");
     next_is_header = is_header && strstr(buf, "\t\t");
     table_line_num++;
+ret:
+ {
+#define STRLEN(x) (sizeof(x)-1)
+ char*pok, *found;
+ for(pok = html; pok = strstr(pok+4, "://"); )
+#define CHECKFOR(str) (!memcmp(found=pok-STRLEN(str),str,STRLEN(str)))
+ if(CHECKFOR("http")||CHECKFOR("ftp")||
+ CHECKFOR("gopher")||CHECKFOR("wais")) {
+ static const char prefix[]="<a href=\"", interfix[]="\">",
+ postfix[]="</a>";
+ size_t len,restlen;
+ for(;;) {
+ switch(*++pok) {
+ default:
+ continue;
+ case ' ':case '\t':case '\n':case '\0':
+ break;
+ }
+ break;
+ }
+ len=pok-found; restlen=strlen(pok)+1;
+ memmove(found+STRLEN(prefix)+len+STRLEN(interfix)+len+
+ STRLEN(postfix),found+len,restlen);
+ memmove(found+STRLEN(prefix),found,len);
+ memcpy(found,prefix,STRLEN(prefix));
+ memcpy(pok = found+STRLEN(prefix)+len,
+ interfix,STRLEN(interfix));
+ memcpy(pok += STRLEN(interfix),found+STRLEN(prefix),len);
+ memcpy(pok += len, postfix,STRLEN(postfix));
+ }
+ }
     return html;
 }
diff -u -b -r squid-1.2.beta24/src/defines.h squid-BuGless/src/defines.h
--- squid-1.2.beta24/src/defines.h Tue Aug 18 01:00:37 1998
+++ squid-BuGless/src/defines.h Mon Aug 24 13:00:15 1998
@@ -87,7 +87,7 @@
 
 #define DNS_INBUF_SZ 4096
 
-#define FD_DESC_SZ 64
+#define FD_DESC_SZ 128
 
 #define FQDN_LOOKUP_IF_MISS 0x01
 #define FQDN_MAX_NAMES 5
 

********************************************************
An extension to allow the redirector to act differently
depending on the port the request was made on
(for junk-buster and non-junk-buster decisions).
********************************************************

diff -u -b -r squid-1.2.beta24/src/cf.data.pre squid-BuGless/src/cf.data.pre
--- squid-1.2.beta24/src/cf.data.pre Fri Aug 21 06:03:45 1998
+++ squid-BuGless/src/cf.data.pre Mon Aug 24 04:04:09 1998
@@ -61,6 +61,17 @@
 http_port 3128
 DOC_END
 
+NAME: bhttp_port ascii_port
+TYPE: ushort
+DEFAULT: none
+LOC: Config.Port.bhttp
+DOC_START
+ The port number where Squid uses the cuciwhirl junkfilter.
+ Note that you need another http_port directive to actually
+ bind the port.
+
+bhttp_port 3129
+DOC_END
 
 NAME: icp_port udp_port
 TYPE: ushort
diff -u -b -r squid-1.2.beta24/src/structs.h squid-BuGless/src/structs.h
--- squid-1.2.beta24/src/structs.h Fri Aug 21 06:03:49 1998
+++ squid-BuGless/src/structs.h Sat Aug 22 03:32:32 1998
@@ -242,6 +243,7 @@
     size_t maxRequestSize;
     struct {
         ushortlist *http;
+ ushort bhttp;
         u_short icp;
 #if USE_HTCP
         u_short htcp;

********************************************************
At one point, I've seen entry == NULL in this place
(around 1.2.b20), maybe this was due to a different bug.
********************************************************

diff -u -b -r squid-1.2.beta24/src/client_side.c squid-BuGless/src/client_side.c
--- squid-1.2.beta24/src/client_side.c Fri Aug 21 08:52:32 1998
+++ squid-BuGless/src/client_side.c Sat Aug 22 04:19:57 1998
@@ -1463,10 +1463,10 @@
     debug(33, 3) ("clientKeepaliveNextRequest: FD %d\n", conn->fd);
     conn->defer.until = 0; /* Kick it to read a new request */
     httpRequestFree(http);
- if ((http = conn->chr) != NULL) {
+ entry = http->entry;
+ if ((http = conn->chr) != NULL && entry) {
         debug(33, 1) ("clientKeepaliveNextRequest: FD %d Sending next\n",
             conn->fd);
- entry = http->entry;
         if (0 == storeClientCopyPending(entry, http)) {
             if (entry->store_status == STORE_ABORTED)
                 debug(33, 0) ("clientKeepaliveNextRequest: entry->swap_status == STORE_ABORTED\n");

********************************************************
Fix bug when q == data
********************************************************

diff -u -b -r squid-1.2.beta24/src/disk.c squid-BuGless/src/disk.c
--- squid-1.2.beta24/src/disk.c Fri Aug 21 11:15:22 1998
+++ squid-BuGless/src/disk.c Mon Aug 24 02:38:25 1998
@@ -275,9 +275,9 @@
         errcode = EFAULT;
     }
 #endif
- safe_free(data);
+
     if (q == NULL) /* Someone aborted then write completed */
- return;
+ goto ret;
 
     if (len == -2 && errcode == -2) { /* Write cancelled - cleanup */
         do {
@@ -314,6 +314,8 @@
              * repeated write failures for the same FD because of
              * the queued data.
              */
+ if (data == q)
+ data = 0;
             do {
                 fdd->write_q = q->next;
                 if (q->free_func)
@@ -335,6 +337,8 @@
             fdd->write_q = q->next;
             if (q->free_func)
                 (q->free_func) (q->buf);
+ if (data == q)
+ data = 0;
             safe_free(q);
         }
     }
@@ -371,11 +375,13 @@
 #ifdef OPTIMISTIC_IO
             F->flags.calling_io_handler = 0;
 #endif
- return;
+ goto ret;
         }
     }
     if (do_close)
         file_close(fd);
+ret:
+ safe_free(data);
 }
 
 

********************************************************
Misc optimisation
********************************************************

diff -u -b -r squid-1.2.beta24/src/filemap.c squid-BuGless/src/filemap.c
--- squid-1.2.beta24/src/filemap.c Wed Jul 22 22:37:19 1998
+++ squid-BuGless/src/filemap.c Thu Jul 23 17:54:28 1998
@@ -115,7 +115,8 @@
     for (count = 0; count < fm->nwords; count++) {
         if (fm->file_map[word] != ALL_ONES)
             break;
- word = (word + 1) % fm->nwords;
+ if (++word == fm->nwords)
+ word = 0;
     }
     for (bit = 0; bit < BITS_IN_A_LONG; bit++) {
         suggestion = ((unsigned long) word << LONG_BIT_SHIFT) | bit;

********************************************************
Self explanatory?
********************************************************

diff -u -b -r squid-1.2.beta24/src/forward.c squid-BuGless/src/forward.c
--- squid-1.2.beta24/src/forward.c Wed Aug 19 08:05:52 1998
+++ squid-BuGless/src/forward.c Sat Aug 22 04:37:41 1998
@@ -59,7 +59,9 @@
     assert(e->mem_obj);
     if (e->store_status == STORE_PENDING) {
         if (e->mem_obj->inmem_hi == 0) {
+#if 0 /* SRB bogus assertion? */
             assert(fwdState->fail.err_code);
+#endif
             err = errorCon(fwdState->fail.err_code, fwdState->fail.http_code);
             err->request = requestLink(fwdState->request);
             err->xerrno = fwdState->fail.xerrno;

********************************************************
Better to reexec, than to die, the binary
might have been fixed (recompiled) in the mean time.
********************************************************

diff -u -b -r squid-1.2.beta24/src/main.c squid-BuGless/src/main.c
--- squid-1.2.beta24/src/main.c Tue Aug 18 00:04:59 1998
+++ squid-BuGless/src/main.c Sat Aug 22 03:32:31 1998
@@ -669,8 +671,11 @@
             failcount++;
         else
             failcount = 0;
- if (failcount == 5)
- exit(1);
+ if (failcount >= 5) {
+ extern char**environ;
+ sleep(1);
+ execve(argv[0],argv,environ);
+ }
         if (WIFEXITED(status))
             if (WEXITSTATUS(status) == 0)
                 exit(0);

********************************************************
This was needed, probably due to a check in storeComplete()
********************************************************

diff -u -b -r squid-1.2.beta24/src/mime.c squid-BuGless/src/mime.c
--- squid-1.2.beta24/src/mime.c Fri Aug 21 05:15:18 1998
+++ squid-BuGless/src/mime.c Sat Aug 22 03:32:31 1998
@@ -413,9 +413,9 @@
         storeAppend(e, buf, n);
     file_close(fd);
     storeSetPublicKey(e);
+ EBIT_SET(e->Sflag, ENTRY_SPECIAL);
     storeComplete(e);
     storeTimestampsSet(e);
- EBIT_SET(e->flag, ENTRY_SPECIAL);
     debug(25, 3) ("Loaded icon %s\n", url);
     storeUnlockObject(e);
     memFree(MEM_4K_BUF, buf);

********************************************************
Fix the redirector interface:
- EAGAIN handling
- When all redirectors die, keep on going
- Terminate all redirector requests with two newlines,
  this allows for a more efficient lex-engine to be
  used as a redirector.
- Support the bhttp port differentiation
********************************************************

diff -u -b -r squid-1.2.beta24/src/redirect.c squid-BuGless/src/redirect.c
--- squid-1.2.beta24/src/redirect.c Sat Jul 25 02:16:29 1998
+++ squid-BuGless/src/redirect.c Thu Jul 30 11:13:50 1998
@@ -100,6 +100,9 @@
     debug(29, 5) ("redirectHandleRead: %d bytes from Redirector #%d.\n",
         len, redirector->index + 1);
     if (len <= 0) {
+ if (len < 0 && errno == EAGAIN)
+ len = 0;
+ else {
         if (len < 0)
             debug(50, 1) ("redirectHandleRead: FD %d read: %s\n", fd, xstrerror());
         debug(29, EBIT_TEST(redirector->flags, HELPER_CLOSING) ? 5 : 1)
@@ -110,10 +113,11 @@
         redirector->inbuf = NULL;
         comm_close(fd);
         if (--NRedirectorsOpen == 0 && !shutting_down)
- fatal_dump("All redirectors have exited!");
+ debug(50, 0) ("All redirectors have exited!");
         return;
     }
- if (len != 1)
+ }
+ if (len > 1)
         RedirectStats.rewrites[redirector->index]++;
     redirector->offset += len;
     redirector->inbuf[redirector->offset] = '\0';
@@ -141,7 +145,7 @@
              * be NULL */
             if (r->handler) {
                 r->handler(r->data,
- t == redirector->inbuf ? NULL : redirector->inbuf);
+ *redirector->inbuf ? redirector->inbuf : NULL);
             }
             redirectStateFree(r);
             redirector->redirectState = NULL;
@@ -227,7 +231,7 @@
     if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL)
         fqdn = dash_str;
     buf = memAllocate(MEM_8K_BUF);
- snprintf(buf, 8192, "%s %s/%s %s %s\n",
+ snprintf(buf, 8192, "%s %s/%s %s %s\n\n",
         r->orig_url,
         inet_ntoa(r->client_addr),
         fqdn,
@@ -261,14 +265,17 @@
     if (!handler)
         fatal_dump("redirectStart: NULL handler");
     debug(29, 5) ("redirectStart: '%s'\n", http->uri);
- if (Config.Program.redirect == NULL) {
+ if (!NRedirectorsOpen) {
         handler(data, NULL);
         return;
     }
     r = xcalloc(1, sizeof(redirectStateData));
     r->orig_url = xstrdup(http->uri);
     r->client_addr = conn->log_addr;
- if (conn->ident.ident == NULL || *conn->ident.ident == '\0') {
+ /*srb*/
+ if (ntohs(conn->me.sin_port)==Config.Port.bhttp) {
+ r->client_ident = "B";
+ } else if (conn->ident.ident == NULL || *conn->ident.ident == '\0') {
         r->client_ident = dash_str;
     } else {
         r->client_ident = conn->ident.ident;

********************************************************
Missing argument; why I am the only one seeing this
problem?
********************************************************

diff -u -b -r squid-1.2.beta24/src/tools.c squid-BuGless/src/tools.c
--- squid-1.2.beta24/src/tools.c Sat Jul 25 06:47:29 1998
+++ squid-BuGless/src/tools.c Mon Aug 24 11:18:19 1998
@@ -49,7 +49,7 @@
 static void fatalvf(const char *fmt, va_list args);
 static void mail_warranty(void);
 #if USE_ASYNC_IO
-static void safeunlinkComplete(void *data, int retcode, int errcode);
+static void safeunlinkComplete(int fd, void *data, int retcode, int errcode);
 #endif
 #if MEM_GEN_TRACE
 extern void log_trace_done();
@@ -446,7 +446,7 @@
 
 #if USE_ASYNC_IO
 static void
-safeunlinkComplete(void *data, int retcode, int errcode)
+safeunlinkComplete(int fd, void *data, int retcode, int errcode)
 {
     char *s = data;
     if (retcode < 0) {

-- 
Sincerely,                                                          srb@cuci.nl
           Stephen R. van den Berg (AKA BuGless).
This signature third word omitted, yet is comprehensible.
Received on Tue Jul 29 2003 - 13:15:52 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:52 MST