From Granizada

Jump to: navigation, search

Daevel is a template daemon written in C from which new daemons can be simply derived. It was inspired by what I couldn't find in Richard W. Stevens' UNIX Network Programming, a foundation used by thousands of programmers in many languages including C. Stevens writes about principles and doesn't present complete solutions, whereas Daevel tries to cover the important points for a production system. Daevel is currently licensed under the GPLversion 2.

The latest version is 0.9, daevel-0.9.tar.gz. Here is the HOWTO.txt. I'm working on version 1.0 at last, with a stack of patches and my own improvements.


Written in C ??

But C is a terrible language! All the best bugs come in C! Other languages can be faster and more portable! Are you mad??[1]

The classic Unix daemons, and many non-classic Windows ones -- the ones found on many corporate networks and of which nearly all the Internet is comprised -- are all written in C. In fact is nearly all system-level code in the world and certainly all significant operating systems are written in C. Any study of good daemon practice must review these packages, ergo, a careful implementor needs to read C [2]. This template represents the beginnings of such a study.

You can write a fast, safe, portable daemon using Twisted, the Python framework, or Ruby on Rails or lots of other things. But it won't teach you how Unix works, and if you don't know that you've missed out on very important basic computer science. Even if you never expect to use a Unix computer in anger (which would seem increasingly unlikely, but still, you may feel that way!) Nor will these other things help you if you are writing for a tiny embedded platform, or if you want to graft on chunks of C pulled out of assorted existing code. In short, a worthy rite of passage if nothing more!

What Daevel Provides

Daevel encapsulates in a small number of source files all the structure for a safe, well-designed Unix daemon that can communicate using the TCP protocol and which is portable across platforms. Build your program on this sample code and you can be reasonably sure you have a good foundation ready for you to extend.

Daevel give you ready-to-run code for:

  • a backgrounding daemon
  • network connection monitoring
  • logging subsystem
  • debugging facilities: multilevel logging and panic routines
  • simple configuration file
  • generic commandline switches
  • default behaviour from the above (background, logfile, lockfile, log level ...)
  • error recovery (recover if possible, log, orderly shutdown)
  • conservation of resources (sockets, filehandles, memory)
  • simple administration interface (lockfile, shutdown command, query)

You can throw away the bits you don't need.

There are a lot things that the Basic Daemon does not do, and which will be covered by the proposed Advanced Daemon, maybe one day:

  • autoconf for even more portability
  • more advanced commandline handling using GNU getopt
  • advanced configuration files using the PCRE library for expressions
  • much better lockfile management using liblockfile
  • daemon administration by web page
  • optional IPv6 support
  • multi-lingual capabilities
  • SSL for protecting connections using libssl


Thanks to the authors of Exim, Samba, Postfix, Apache, sshd, fetchmail and numerous other well-known packages for making your code available for scrutiny for creating completely different packages such as this one.

Thanks to Tellurian Pty Ltd for hosting the development of early versions of this code and allowing me retain copyright, permitting me to publish it in this form. Victor Wodecki and John gave valuable feedback.

Thanks to Martin Poole and Tim Potter for initial review and many others since.


  1. Probably
  2. See ISBN 0-201-79940-5 and ISBN 0-321-16607-8 to learn how and why to read code.
Retrieved from "http://shearer.org/Daevel"
Personal tools