Re: A fnord fork (a fnork?)

Frank Bergmann <[email protected]> Fri, 17 Feb 2012 01:20:19 +0100 (CET)
Newsgroups gmane.comp.web.fnord
Message-ID <20120217000449.GB20795@treferpol>
Hi,

On Thu, Feb 16, 2012 at 11:54:52PM +0100, Felix von Leitner wrote:
> >   Fix if-modified-since date parsing
> 
> What's wrong with it?

"""
When a client sends a If-Modified-Since request-header field then it is
converted as localtime. The fnord-1.11-if-modified-since.patch adds the
timezone offset after mktime() conversion. DST recognition is "fixed" by a
comparing the file mod time to the split second with an one hour offset.
"""

My solution (independent of debian patches or other) looked like this:

diff -ruN fnord-1.10-20100519fwb/httpd.c fnord-1.10-20100519fwb_2/httpd.c
--- fnord-1.10-20100519fwb/httpd.c	2010-05-19 19:07:50.000000000 +0200
+++ fnord-1.10-20100519fwb_2/httpd.c	2010-05-19 19:03:43.000000000 +0200
@@ -848,6 +848,7 @@
   struct tm x;
   int i;
   unsigned long tmp;
+  time_t tnull;
   if (!c) return (time_t)-1;
   /* "Sun, 06 Nov 1994 08:49:37 GMT",
    * "Sunday, 06-Nov-94 08:49:37 GMT" and
@@ -883,7 +884,9 @@
   if (parsetime(c,&x)) return (time_t)-1;
 done:
   x.tm_wday=x.tm_yday=x.tm_isdst=0;
-  return mktime(&x);
+  /* return with timezone offset added */
+  tnull = 0;
+  return mktime(&x)-mktime(gmtime(&tnull));
 }
 
 static void redirectboilerplate() {
@@ -938,7 +941,10 @@
     /* see if the peer accepts MIME type */
     /* see if the document has been changed */
     ims=parsedate(header(buf,buflen,"If-Modified-Since"));
-    if (ims!=(time_t)-1 && st.st_mtime<=ims) { retcode=304; goto bad; }
+    if (ims!=(time_t)-1) {
+      /* 2nd compare is a dirty hack to overcome linux dst limits */
+      if ((st.st_mtime<=ims) || (st.st_mtime == ims + 3600)) { retcode=304; goto bad; }
+    }
     rangestart=0; rangeend=st.st_size;
     if ((accept=header(buf,buflen,"Range"))) {
       /* format: "bytes=17-23", "bytes=23-" */

> Fork away if you want to, but if you actually discovered bugs, then I
> would like to hear about them.

er... I guess that Gerrit and the debian guys had a bunch of patches. Some
things considered to be "bugs" by some people are known for years.

I also collected some fixes and patches til I did a fork. Plz look at
http://www.tuxad.com/fnord-patches.html

> I don't get why you would want to remove libowfat, to be honest.  That
> and dietlibc are what makes fnord viable as a web server in practice.
> Because the static binary is so tiny.

:-)

Frank