"That which is overdesigned, too highly specific, anticipates outcome; the anticipation of outcome guarantees, if not failure, the absence of grace."
-- William Gibson, All Tomorrow's Parties
Daemonology

Spent Friday night rewriting a my daemon prototype. Around 0300 (Saturday morning) I was twitchy enough to realize my mistake:

First off, following JdBP's common mistakes guidelines, I don't have the daemon background itself (which is something that should be left up to a daemon manager, like inetd or preferably, djb's daemontools). So my prototype starts up, attaches to a socket, and starts listening.

When a request from a client kicks off, it spawns off a child using a while() loop. The while loop is structured in such a way that it's only running as long as the process is listening to the socket. So once the last child exits (non-blocking I/O, etc, so multiple clients can talk to multiple children, yadda yadda -- no max children options yet, though, as I haven't started on my queueing code), the parent process dies. It doesn't go through the cleanup code, so it's actually hitting the child exit statement.

This was a problem.

After rewriting the damn thing, however, I realized that for the parent to keep running, I should have an until() around the child while() loop.

eg: until ($term) { ... } where $term is global and defined 0 until $SIG{TERM} (the TERM signal) is caught.

So after that all was happy.

The next goal for this prototyping project is to class it all out into a module which does Actual Useful Stuff, and takes commands from clients and whatnot. The module/daemon will actually be a monitoring suite of some sort: it'll ping hosts, store their stats, etc. Minor stuff.

Once that's complete, I'll move on to writing a CGI::Application application (the prototype will probably be for a small kbase type thing).

And after that, well, I'll be putting all the techniques together and writing a new backup solution for work, which will replace our Veritas NetBackup setup.

Rather intimidating, really.

February 9, 2004 1:50 PM
Comments

glad to see you active.
hope all is going swimmingly.
Ill give you a call some day soon... when I have a life again.

Posted by: Evan at February 10, 2004 1:25 AM
Post a comment









Remember personal info?