Re: [dev] environment variables versus runtime configuration (rc) files versus X resources

From: Dimitris Papastamos <sin_AT_2f30.org>
Date: Mon, 3 Nov 2014 19:59:14 +0000

On Mon, Nov 03, 2014 at 02:32:25PM -0500, Greg Reagle wrote:
> I just had a thought that might be of interest to fans of the suckless
> philosophy.
>
> It occurred to me that environment variables can be used to configure a
> program, instead of programming in a parser or extension language into a
> program. Are there any reasons not to just use environment variables?
> Then a rc file could just be a shell script that sets environment
> variables. Do you know of any programs that do this? I assume there
> are disadvantages, but what?

I personally prefer a short set of environment variables. There is however,
some sense in having environment variables that have well-defined semantics
across multiple programs. One such example is the http_proxy
environment variable.

The environment is also of limited size. I think POSIX guarantees a space
of about 2kB iirc for environment variables. Tools like xargs(1) need to
take this into account and make sure the invoked program will be able
to access the environment if necessary. An unreasonable large environment
will be capped.

This approach also does not scale in general as people will start naming
variables differently and possibly result in collisions.

A small set of environment variables also helps diagnosing issues, as you
can rule out the environment quickly.

For run-time configuration I'd opt for command line options or if that is
not enough, I'd go for a simple configuration file. There are legitimate
cases where config.h is simply not enough or not applicable. Think of
a long running daemon where it is not acceptable to restart it. scron[0]
for example which is a simple cron daemon does not use config.h but rather
parses a crontab file.
Received on Mon Nov 03 2014 - 20:59:14 CET

This archive was generated by hypermail 2.3.0 : Mon Nov 03 2014 - 21:00:16 CET