[Xastir-dev] Shared memory questions...

Curt Mills archer at eskimo.com
Thu Dec 21 20:45:39 EST 2006


On Tue, 19 Dec 2006, Greg Eigsti wrote:

> Here comes a newbie question; I am fairly new to *nix programming and have a
> question regarding forking and shared memory.

You're _new_ to Unix programming and are alreading getting into
forking, threads, and shared memory?  :-O


> I am working on adding an http status page to xastir which shows xastir
> status including connected TCP port status.  Most of this work is in
> x_spider.c where the pipe_object structure is defined.  I have extended the
> pipe_object structure to contain additional per user connection data.
> 
> The problem that I am having is that since the TCP_Server is forked (and it
> 'manages' the pipe_object list) any changes to the list are not reflected in
> the other x_spider processes.
> 
> I investigated using shared memory to hold the pipe_object list but this
> will turn into a huge hassle quickly if one considers the code that needs to
> be written to manage the shared memory (and all the changes to the
> implementation of the pipe_object list).
> 
> Another alternative is to change the forking of the TCP server (and my new
> 'status server') to be threads.  This would make it much easier for the TCP
> server and 'status server' to share the pipe_object list.
> 
> Suggestions, warnings, hints, tips, tricks?

First, we discussed putting a web server into Xastir some time back.
I believe the general concensus was that we shouldn't, instead
relying on the Unix strategy of smaller/simpler tools that one can
add together to get the job done.

Doing our own web server also opens us up to cracking, on one of the
favorite TCP ports for this sort of activity.  Programs like Apache
already keep track of exploits and needed security, therefore
they're better suited to write/patch code for http.

So...  I guess what I might suggest is that you add code which
writes out html files to disk, perhaps with a configuration option
for defining the top-level directory for this, and also perhaps SUID
access to such directories.  Apache or some other web server could
then serve up these pages.

w.r.t. the fork versus thread question, I tried both when I wrote
the spider server.  The end result (what you see today) was due to
the need for a smaller memory image for all the server processes.  I
fork the x_spider server immediately upon starting Xastir (if the
server ports are enabled), then each incoming socket gets a
relatively small program to service it.  If I forked from the main
Xastir process later I'd end up with very large memory images for
these processes.  Same I think for threading.

I'm not aware of any major problems with the x_spider code, so I'd
certainly rather leave it alone right now and concentrate on other
parts of Xastir that need work.  Or enhancements.

-- 
Curt, WE7U.				archer at eskimo dot com
http://www.eskimo.com/~archer
  Lotto:  A tax on people who are bad at math. - unknown
Windows:  Microsoft's tax on computer illiterates. - WE7U.
The world DOES revolve around me:  I picked the coordinate system!"



More information about the Xastir-dev mailing list