Cartesius00
Cartesius00

Reputation: 24414

Runtime configuration of a C application for Linux

We have a C application for Linux consisting of few modules. Each module can have some global config variables (some integers, strings etc.). The application is intended to run as a daemon for a long time.

What is the nicest way to reconfigure the app during run-time? Ideally, we would like to change somehow the content of those config-variables. Via /proc, inotify? What's the coolest, advanced way?

Upvotes: 3

Views: 622

Answers (4)

Teddy
Teddy

Reputation: 6163

The "coolest, advanced way" would be to expose the modules as D-Bus objects (on the "system" bus), with the settings as D-Bus properties.

Upvotes: 0

It is usually more simple, even for system administrators, to restart a server after having reconfigured it (and usually, people don't do that directly on a production machine). Or at least to have the server reload its configuration files thru a signal (like SIGHUP is often used for).

If going thru configuration files is not adequate for your needs (but usually, it is a good approach), you could consider having a more interactive interface, e.g. thru a web browser, for that goal. If you really want to go that way, you might embed a tiny web server in your application, or give it FastCGI or SCGI abilities.

Upvotes: 0

e.dan
e.dan

Reputation: 7507

Sending a signal like SIGHUP which your program traps with a signal handler and does whatever it needs to do, like re-reading its configuration file, is a time-honored way of doing this. I can't call it a "coolest advanced" way, rather a practical and easy way. It is, for example, what happens when you want Apache's httpd daemon to re-read httpd.conf - it happens under the hood of service httpd reload.

Upvotes: 8

Some programmer dude
Some programmer dude

Reputation: 409482

Last time I did something similar, I simply checked the modification timestamp of the configuration file every X minutes, and if changed re-read the file. Today I would probably use inotify or similar native API on whatever platform I was on, even though it is more work.

Upvotes: 0

Related Questions