Skip to contentSkip to conversation

khttpd crash fix

PATCH In review [email protected] 2 participants 3 messages Aug 20, 2002 – Sep 28, 2002

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 khttpd crash fix

I've been using this patch for some time now; it fixes
a nasty oops in khttpd on smp, and adds crucial details to the doc. Sure, khttpd is going away in 2.5, but 2.4 is stable, let's fix it there.

I sent it multiple times to the author of khttpd and to the khttpd-users mailing list, and even to linux-kernel; I received good comments from khttpd-users but silence elsewhere.
In desperation, I finally read the MAINTAINERS file, and learned that there is no official maintainer for khttpd, so here I am mailing it to the 'mail patches to' address for General Networking Stuff.

Any chance this could be blessed for transmission to Marcello for 2.4.20? Thanks,
Dan Kegel

net/khttpd/README +39 -16
diff -x '*times*' -x '.*' -x '*.o' -Naur linux-2.4.17-orig/net/khttpd/README linux/net/khttpd/README
@@ -14,14 +14,15 @@
    other webservers in that it runs from within the Linux-kernel as a module 
    (device-driver).
 
-   kHTTPd handles only static (file based) web-pages, and passes all requests
-   for non-static information to a regular userspace-webserver such as Apache or 
-   Zeus. The userspace-daemon doesn't have to be altered in any way.
+   kHTTPd handles only static (file based) web-pages, and passes all requests 
+   for non-static information to a regular userspace-webserver such as Apache 
+   or Zeus. The userspace-daemon doesn't have to be altered in any way.
 
    Static web-pages are not a very complex thing to serve, but these are very
    important nevertheless, since virtually all images are static, and a large
    portion of the html-pages are static also. A "regular" webserver has little
-   added value for static pages, it is simply a "copy file to network"-operation.
+   added value for static pages, it is simply a "copy file to network"
+   operation.
    This can be done very efficiently from within the Linux-kernel, for example 
    the nfs (network file system) daemon performs a similar task and also runs 
    in the kernel.
@@ -44,6 +45,7 @@
  
    echo 1 > /proc/sys/net/khttpd/stop
    echo 1 > /proc/sys/net/khttpd/unload 
+   sleep 2
    rmmod khttpd
    
 
@@ -71,7 +73,7 @@
 
    Before you can start using kHTTPd, you have to configure it. This
    is done through the /proc filesystem, and can thus be done from inside
-   a script. Most parameters can only be set when kHTTPd is not active.
+   a script. Most parameters can only be set when kHTTPd is stopped.
 
    The following things need configuration:
 
@@ -117,26 +119,31 @@
 
    Port 8080
 
+   Starting kHTTPd
+   ===============
+   Once you have set up the configuration, start kHTTPD by running
+   echo 1 > /proc/sys/net/khttpd/start
+   It may take a jiffie or two to start.
 
-   
    Stopping kHTTPd
    ===============
-   In order to change the configuration, you should stop kHTTPd by typing
+   To stop kHTTPd, do
    echo 1 > /proc/sys/net/khttpd/stop
-   on a command-prompt.
+   It should stop in a jiffy or two.
 
-   If you want to unload the module, you should type
+   Unloading kHTTPd
+   ===============
+   To unload the module, do
+   echo 1 > /proc/sys/net/khttpd/stop
    echo 1 > /proc/sys/net/khttpd/unload
-   after stopping kHTTPd first.
+   #killall -HUP khttpd
+   sleep 2
+   rmmod khttpd
 
-   If this doesn't work fast enough for you (the commands above can wait for 
+   If this doesn't work fast enough for you (unloading can wait for 
    a remote connection to close down), you can send the daemons a "HUP"
    signal after you told them to stop. This will cause the daemon-threads to
    stop immediately. 
-
-   Note that the daemons will restart immediately if they are not told to
-   stop.
-
    
 
 4. Permissions
@@ -212,7 +219,21 @@
 	maxconnect	1000		Maximum number of concurrent
 					connections
 
-6. More information
+6. Known Issues
+   kHTTPd is *not* currently compatible with tmpfs.  Trying to serve
+   files stored on a tmpfs partition is known to cause kernel oopses
+   as of 2.4.18.  This is due to the same problem that prevents sendfile()
+   from being usable with tmpfs.  A tmpfs patch is floating around that seems
+   to fix this, but has not been released as of 27 May 2002.
+   kHTTPD does work fine with ramfs, though.
+
+   There is debate about whether to remove kHTTPd from the main
+   kernel sources.  This will probably happen in the 2.5 kernel series,
+   after which khttpd will still be available as a patch.
+
+   The kHTTPd source code could use a good spring cleaning.
+
+7. More information
 -------------------
    More information about the architecture of kHTTPd, the mailinglist and
    configuration-examples can be found at the kHTTPd homepage:
@@ -221,4 +242,6 @@
 
    Bugreports, patches, etc can be send to the mailinglist
    ([email protected]) or to [email protected]
+   Mailing list archives are at 
+      http://lists.alt.org/mailman/listinfo/khttpd-users
 
net/khttpd/main.c +40 -72

218 lines not on this page · raw message

net/khttpd/sysctl.c +22 -1
diff -x '*times*' -x '.*' -x '*.o' -Naur linux-2.4.17-orig/net/khttpd/sysctl.c linux/net/khttpd/sysctl.c
@@ -64,6 +64,7 @@
 int	sysctl_khttpd_threads	= 2;
 int	sysctl_khttpd_maxconnect = 1000;
 
+atomic_t        khttpd_stopCount;
 
 static struct ctl_table_header *khttpd_table_header;
 
@@ -72,6 +73,8 @@
 		  void *newval, size_t newlen, void **context);
 static int proc_dosecurestring(ctl_table *table, int write, struct file *filp,
 		  void *buffer, size_t *lenp);
+static int khttpd_stop_wrap_proc_dointvec(ctl_table *table, int write, struct file *filp,
+		  void *buffer, size_t *lenp);
 
 
 static ctl_table khttpd_table[] = {
@@ -93,7 +96,7 @@
 		sizeof(int),
 		0644,
 		NULL,
-		proc_dointvec,
+		khttpd_stop_wrap_proc_dointvec,
 		&sysctl_intvec,
 		NULL,
 		NULL,
@@ -307,6 +310,24 @@
 	return 0;
 }
 
+/* A wrapper around proc_dointvec that computes
+ * khttpd_stopCount = # of times sysctl_khttpd_stop has gone true
+ * Sensing sysctl_khttpd_stop in other threads is racy;
+ * sensing khttpd_stopCount in other threads is not.
+ */
+static int khttpd_stop_wrap_proc_dointvec(ctl_table *table, int write, struct file *filp,
+		  void *buffer, size_t *lenp)
+{
+	int rv;
+	int oldstop = sysctl_khttpd_stop;
+	rv = proc_dointvec(table, write, filp, buffer, lenp);
+	if (sysctl_khttpd_stop && !oldstop)
+		atomic_inc(&khttpd_stopCount);
+
+	return rv;
+}
+		
+
 static int sysctl_SecureString (/*@unused@*/ctl_table *table, 
 				/*@unused@*/int *name, 
 				/*@unused@*/int nlen,
net/khttpd/sysctl.h +3 -0
diff -x '*times*' -x '.*' -x '*.o' -Naur linux-2.4.17-orig/net/khttpd/sysctl.h linux/net/khttpd/sysctl.h
@@ -14,4 +14,7 @@
 extern int 	sysctl_khttpd_threads;
 extern int	sysctl_khttpd_maxconnect;
 
+/* incremented each time sysctl_khttpd_stop goes nonzero */
+extern atomic_t	khttpd_stopCount;
+
 #endif
net/khttpd/waitheaders.c +7 -1
diff -x '*times*' -x '.*' -x '*.o' -Naur linux-2.4.17-orig/net/khttpd/waitheaders.c linux/net/khttpd/waitheaders.c
@@ -134,7 +134,7 @@
 		CurrentRequest = CurrentRequest->Next;
 	}
 
-	LeaveFunction("WaitHeaders");
+	LeaveFunction("WaitForHeaders");
 	return count;
 }
 
@@ -178,6 +178,12 @@
 	
 	EnterFunction("DecodeHeader");
 	
+	if (Buffer[CPUNR] == NULL) {
+		/* see comments in main.c regarding buffer managemnet - dank */
+		printk(KERN_CRIT "khttpd: lost my buffer");
+		BUG();
+	}
+
 	/* First, read the data */
 
 	msg.msg_name     = 0;
Documentation/networking/khttpd.txt +1 -0
@@ -0,0 +1 @@
+See net/khttpd/README for documentation on khttpd, the kernel http server.
#1 lore raw
Quoted 4 lines · On Mon, 19 Aug 2002 [email protected] wrote:

I've been using this patch for some time now; it fixes
a nasty oops in khttpd on smp, and adds crucial details to the doc. Sure, khttpd is going away in 2.5, but 2.4 is stable, let's fix it there.

Quoted 8 lines

I sent it multiple times to the author of khttpd and to the khttpd-users mailing list, and even to linux-kernel; I received good comments from khttpd-users but silence elsewhere.
In desperation, I finally read the MAINTAINERS file, and learned that there is no official maintainer for khttpd, so here I am mailing it to the 'mail patches to' address for General Networking Stuff.

Any chance this could be blessed for transmission to Marcello for 2.4.20?

I guess Arjan could take a look at the patch, since he is the maintainer.

Arjan ?

#2 lore raw
Quoted 15 lines · Marcelo Tosatti
Quoted 11 lines · On Mon, 19 Aug 2002 [email protected] wrote:

I've been using this patch for some time now; it fixes
a nasty oops in khttpd on smp, and adds crucial details to the doc. Sure, khttpd is going away in 2.5, but 2.4 is stable, let's fix it there.

I sent it multiple times to the author of khttpd and to the khttpd-users mailing list, and even to linux-kernel; I received good comments from khttpd-users but silence elsewhere.
In desperation, I finally read the MAINTAINERS file, and learned that there is no official maintainer for khttpd, so here I am mailing it to the 'mail patches to' address for General Networking Stuff.

Quoted 3 lines
Quoted 1 line

Any chance this could be blessed for transmission to Marcello for 2.4.20?

I guess Arjan could take a look at the patch, since he is the maintainer.

Or rather, used to be.

Anyway, I already got that fix on my tree thanks to Alan.

Just /dev/null both mails ;)