I'm in the process of writing a simple C-based daemon mostly for the learning experience. At this point, I've got a working daemon and I'd like to expose some configuration options to users.

What's the standard way that most daemons provide configuration options and are there any good C libraries that help with this?


It really depends on how complicated you want to get.

Two options main options.

  1. Accept command-line options. For a standard daemon, these would be put into the init.d script for system configuration.
  2. Your own conf file inside of /etc/yourDaemon. In this case, there is typically a command-line option to specify the location of the configuration file, and would, by default, be put in /etc/yourDaemon/blah.conf

I recommend libconfuse. http://www.nongnu.org/confuse/



GSettings is as close as there is to a standard way for storing configuration. It uses dconf as a backend.

The advantages of using GSettings and dconf include:

  • Users can use the prebuilt dconf-editor tool to modify the configuration. Many applications also provide a preferences program to provide a higher level interface to this.

  • Consistency - your settings are stored in the same place as the settings for most of the GNOME desktop. This makes administrative jobs such as backup easier because the user doesn't have to remember the location of your config file.

  • Speed - dconf is optimised for speed, especially in read operations which are the most common.

  • This is a good API for application settings. The settings are done on a per-user level. Obviously not suitable for a daemon. gnome's own description of GSettings - "High-level API for application settings" – user606723 Aug 5 '11 at 17:24
  • 1
    The distinction between applications and daemons is artificial. Both are types of programs - daemons just run in the background. So it is not obvious that GSettings in unsuitable for a daemon. Yes the settings are per-user but why is this wrong for a daemon? Daemons often are per user eg. gnome-settings-daemon, zeitgeist-daemon, ubuntuone-syncdaemon ... I can't find any reason why you shouldn't use an application settings framework for daemon settings. – dv3500ea Aug 6 '11 at 10:07
  • Because a classic daemon is -not- per user. And because neither you or the asker made any such distinction. – user606723 Aug 6 '11 at 15:02
  • Well I don't know what you mean by classic daemon. A daemon as I understand it is any background process and there are some standard steps to set one up. A daemon can be either system wide or user specific. GSettings is normally used per user but AFAIK it can be used system wide just like gconf. – dv3500ea Aug 6 '11 at 16:22
  • There are also classes of user applications that could qualify. NetworkManager comes to mind - even though it has an user interface. – Stephen Eilert Jan 31 '12 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.