I noticed that many configuration options (configure.txt) have 
environment variable overrides.  However, an important one does not.  In
 the configuration.txt file, there is one section:<br>
<br><span style="font-family:courier new,monospace">Directories used by NUT at run-time</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">-----------------------------------</span><br style="font-family:courier new,monospace">

<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">  --with-pidpath=PATH</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Changes the directory where pid files are stored.  By default this is</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">/var/run.  Certain programs like upsmon will leave files here.</span><br style="font-family:courier new,monospace">

<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">  --with-altpidpath=PATH</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Programs that normally don't have root powers, like the drivers and</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">upsd, write their pid files here.  By default this is whatever the</span><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">statepath is, as those programs should be able to write there.</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> --with-statepath=PATH</span><br style="font-family:courier new,monospace">

<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">Change the default location of the state sockets created by the</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">drivers.</span><br style="font-family:courier new,monospace">

<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">The NUT_STATEPATH environment variable overrides this at run time.</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">Default is /var/state/ups.</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">-----------------------------------</span><br>

<br>So, the PID path does not have an env var override, but the state path does and it substitutes for the Alternate PID path as well.<br>I'm thinking the PID path should also have an override, like NUT_PIDPATH.  Maybe add a function in common.txt such as:<br>

<br><span style="font-family:courier new,monospace">/* Return the path for pid files */</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">const char * pidpath(void)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">{</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">    const char * path;</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">    if ((path = getenv("NUT_PIDPATH")) == NULL)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">        path = PIDPATH;</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">    return path;</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">}</span><br><br>While 
using the NUT_STATEPATH, I noticed an error where in some areas 
altpidpath was not using the statepath as advertised as an override, so I
 include a "patch" here for <span style="font-family:courier new,monospace">altpidpath()<span style="font-family:arial,helvetica,sans-serif"> in </span></span><span style="font-family:arial,helvetica,sans-serif">co</span>mmon.c:<br>

<br><span style="font-family:courier new,monospace">/* Return the alternate path for pid files */</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">const char * altpidpath(void)</span><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">{</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    const char * path;</span><br style="font-family:courier new,monospace">

<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    if ((path = getenv("NUT_STATEPATH")) == NULL)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">        path = ALTPIDPATH;</span><br style="font-family:courier new,monospace">

<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    return path;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">}</span><br>

<br>A problem I see with the above code is that the env checking function appears to be called every time a variable is needed (see <span style="font-family: courier new,monospace;">statepath</span>
 calls).  This practice should probable be changed so that the env 
variable is loaded once at program startup and stored in a global 
var/struct and then used as needed.  This is so that changes to a env 
var within the programs runtime context does not modify behavior or 
cause error, such as changing where it looks for the PID file AFTER the 
PID file was created.<br>
<br>
Maybe each should have their own env vars: NUT_PIDPATH, 
NUT_ALTPIDPATH, NUT_STATEPATH (and others).  In general, each configuration variable probably ought to have a there own environment variables.  This would facilitate fine control over the program within scripts, etc., for the following reasons:<br>
   Since most control could be maintained by the service script or a configuration file augmenting the service script,<br>1. environment variables makes the program very runtime manageable.<br>2. various distribution maintainers would not need to configure compile time defaults to control the program, just manage a config file.<br>
3. developers could quickly check variations by changing environment variables instead of a recompile.<br><br>Rewrite anyone?<br><br>Thanks,<br><font color="#888888">Keven</font>