libmicrohttpd - A web interface for your daemons.
When writing daemons there is always the question of “How will I check on the status as it runs?“. Solutions include:
- Have a debug flag and write to stderr.
- Periodically write a file in a known place.
- On a particular signal, write a file in a known place.
- Keep a socket open to write status if someone connects.
I add one more:
- Have an HTTP interface and let people talk to you with a browser.
libmicrohttpd is just the thing for embedding an HTTP server in your daemon. It adds about 25k to your code, a couple lines to start it and then a dispatching function you write to handle the requests.
It has three models, the least obtrusive of which it is to just let it make some threads and live in its own threads. The others are useful if you can’t tolerate threads, but you have to cooperate to get select() calls made.
I don’t think you’d want to let it take a slashdotting, so either keep it behind a firewall or check the incoming IPs.
It seems to be solid and well written, but I did notice that it raises a SIGPIPE that kills the host application when a connection closes in the middle of a request. (3 word fix in the source. Add MSG_NOSIGNAL to the SEND() calls) That was found in the first minutes of testing, so it doesn’t get the “bullet proof - use and forget” stamp of trust. Maybe after 6 months of daily use it can earn that.