Search

Sunday, October 20, 2019

4.3 BSD VAX - revisiting a minimal tiny httpd web server

Supratim Sanyal's Blog: Simple httpd web server running on 4.3 BSD VAX
Simple httpd web server running on 4.3 BSD VAX

The SIMH 4.3 BSD VAX instance that I wrote about earlier has been performing flawlessly, but was still missing a web server. Recently, Atr0baby figured out a way to compile a web server on his 4.3 BSD VAX installation and documented it here.

So I followed the instructions and got a working web server by compiling Nigel Griffiths's nweb which needed only minor tweaks to get compiled with gcc version 2.7.2.2 VAX-DEC-BSD. You can download the tweaked nweb from here.

It works fine, except that every time it serves a web page, it leaves a zombie <defunct> process behind in 4.3 BSD process table:

Supratim Sanyal's Blog: Zombie Processes on 4.3 BSD VAX fork function usage


I played around with the nweb23.c source code trying things including changing the System-V SIGCLD to BSD SIGCHLD, a dedicated signal handler function, introducing wait() system call, etc. but could not get rid of zombies left behind when the forked process exited after serving a http request. It appears the confusion about zombies was pretty common in these ancient but exciting times - for example here is excerpt from Shichao's Notes:

SIGCLD Semantics

Two signals that continually generate confusion are SIGCLD and SIGCHLD. The name SIGCLD (without the H) is from System V, and this signal has different semantics from the BSD signal, named SIGCHLD. The POSIX.1 signal is also named SIGCHLD.
The semantics of the BSD SIGCHLD signal are normal and its semantics are similar to all other signals. When the signal occurs, the status of a child has changed, and we need to call one of the wait functions to determine what has happened.
System V, however, has traditionally handled the SIGCLD signal differently from other signals:
  1. If the process specifically sets its disposition to SIG_IGN, children of the calling process will not generate zombie processes. [p333]
    • 4.4BSD always generates zombies if SIGCHLD is ignored. If we want to avoid zombies, we have to wait for our children.
  2. If we set the disposition of SIGCLD to be caught, the kernel immediately checks whether any child processes are ready to be waited for and, if so, calls the SIGCLD handler. [p333-335]
    • FreeBSD 8.0 and Mac OS X 10.6.8 don’t exhibit this problem, because BSD-based systems generally don’t support historical System V semantics for SIGCLD.
    • Linux 3.2.0 also doesn’t exhibit this problem, because it doesn’t call the SIGCHLD signal handler when a process arranges to catch SIGCHLD and child processes are ready to be waited for, even though SIGCLD and SIGCHLD are defined to be the same value.
    • Solaris avoids this problem by including extra code in the kernel.
Of the four platforms described in this text, only Linux 3.2.0 and Solaris 10 define SIGCLD. On these platforms, SIGCLD is equivalent to SIGCHLD.

Perhaps the 4.3 BSD kernel works this way and does a cleanup of zombies when needed, as some other literature indicates.

In any case, I gave up on nweb for 4.3 BSD VAX, and switched to a much simpler, and far more rudimentary, httpd responder (I cannot call it a web server): David Egan's HTTP Server in C. This one is as minimal as it gets - when it receives anything on its listening port, it simply accepts the connection and sends back a hard-coded HTTP header string and all lines in a local file back out. It does not try to create child processes etc. I call it "shs" (simple http server) and here is the slightly-tweaked source that compiles fine with gcc 2.7.2.2 on 4.3 BSD VAX:



I also compiled the old "wget" version using gcc on 4.3 BSD VAX. This allows convenient downloading of stuff from around the web. The 4.3 BSD VAX binaries of nweb, shs and wget can be downloaded from my google drive.

Lastly, you can see the little 4.3 BSD VAX http web server in action at http://sanyal.duckdns.org:94/.


No comments:

Post a Comment

"SEO" link builders: move on, your spam link will not get posted.

Recommended Products from Amazon