From 70a3dac7b9a42986f6f25d877b5903a6a9ade5cf Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 5 Sep 2017 18:03:30 +0200 Subject: [PATCH 1/4] main.c : update usage message with hints about running as unprivileged user --- drivers/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/main.c b/drivers/main.c index 6c0f40af7b..6c181a70a9 100644 --- a/drivers/main.c +++ b/drivers/main.c @@ -98,7 +98,11 @@ static void help_msg(void) printf(" -s - configure directly from cmd line arguments\n"); printf(" - note: must specify all driver parameters with successive -x\n"); - printf(" - note: at least 'port' variable should be set\n\n"); + printf(" - note: at least 'port' variable should be set\n"); + printf(" - note: to explore the current values on a device from an\n"); + printf(" unprivileged user account (with sufficient media access in\n"); + printf(" the OS - e.g. to query networked devices), you can specify\n"); + printf(" '-d 1' argument and `export NUT_STATEPATH=/tmp` beforehand\n\n"); printf(" -V - print version, then exit\n"); printf(" -L - print parseable list of driver variables\n"); From 480aeb4b628762b69850b9a3372c2b904259aa53 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 6 Sep 2017 08:14:08 +0200 Subject: [PATCH 2/4] common.c : altpidpath() : support priority of an envvar, like statepath does --- common/common.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/common/common.c b/common/common.c index d53be5a76f..7b81dbf26c 100644 --- a/common/common.c +++ b/common/common.c @@ -380,13 +380,27 @@ const char * dflt_statepath(void) return path; } -/* Return the alternate path for pid files */ +/* Return the alternate path for pid files, for processes running as non-root + * Per documentation and configure script, the fallback value is the + * state-file path as the daemon and drivers can write there too. + * Note that this differs from PIDPATH that higher-privileged daemons, such + * as upsmon, tend to use. + */ const char * altpidpath(void) { + const char * path; + + if ((path = getenv("NUT_ALTPIDPATH")) == NULL) + path = getenv("NUT_STATEPATH"); + + if (path != NULL) + return path; + #ifdef ALTPIDPATH return ALTPIDPATH; #else - return dflt_statepath(); +/* We assume, here and elsewhere, that at least STATEPATH is always defined */ + return STATEPATH; #endif } From 074dcedd57f97a6727364abe77a72de61fc5a31d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 6 Sep 2017 08:35:39 +0200 Subject: [PATCH 3/4] common.c : dflt_statepath() / altpidpath() : support defined-but-empty envvars to have same effect as not-defined --- common/common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/common.c b/common/common.c index 7b81dbf26c..65b97996b8 100644 --- a/common/common.c +++ b/common/common.c @@ -374,7 +374,8 @@ const char * dflt_statepath(void) { const char * path; - if ((path = getenv("NUT_STATEPATH")) == NULL) + path = getenv("NUT_STATEPATH"); + if ( (path == NULL) || (*path == '\0') ) path = STATEPATH; return path; @@ -390,10 +391,11 @@ const char * altpidpath(void) { const char * path; - if ((path = getenv("NUT_ALTPIDPATH")) == NULL) + path = getenv("NUT_ALTPIDPATH"); + if ( (path == NULL) || (*path == '\0') ) path = getenv("NUT_STATEPATH"); - if (path != NULL) + if ( (path != NULL) && (*path != '\0') ) return path; #ifdef ALTPIDPATH From 9bd2bd4ce2f21bde25dd289b2889e88f7d4f5ed3 Mon Sep 17 00:00:00 2001 From: Arnaud Quette Date: Wed, 29 Nov 2017 14:35:02 +0100 Subject: [PATCH 4/4] doc: missing documentation for NUT_* env vars Complete documentation for upsd and drivers related to the environment variables NUT_CONFPATH, NUT_STATEPATH and NUT_ALTPIDPATH Signed-off-by: Arnaud Quette --- docs/configure.txt | 2 ++ docs/man/nutupsdrv.txt | 17 +++++++++++++++++ docs/man/upsd.txt | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/configure.txt b/docs/configure.txt index 05649cbb40..fef4087cbb 100644 --- a/docs/configure.txt +++ b/docs/configure.txt @@ -364,6 +364,8 @@ Programs that normally don't have root powers, like the drivers and upsd, write their pid files here. By default this is whatever the statepath is, as those programs should be able to write there. +The NUT_ALTPIDPATH environment variable overrides this at run time. + --with-statepath=PATH Change the default location of the state sockets created by the diff --git a/docs/man/nutupsdrv.txt b/docs/man/nutupsdrv.txt index 4b62075984..0ccc7233f3 100644 --- a/docs/man/nutupsdrv.txt +++ b/docs/man/nutupsdrv.txt @@ -148,6 +148,23 @@ ups.conf:: Required configuration file. This contains all details on which drivers to start and where the hardware is attached. +ENVIRONMENT VARIABLES +--------------------- + +*NUT_CONFPATH* is the path name of the directory that contains +`upsd.conf` and other configuration files. If this variable is not set, +*upsd* uses a built-in default, which is often `/usr/local/ups/etc`. + +*NUT_STATEPATH* is the path name of the directory in which +*upsd* keeps state information. If this variable is not set, +*upsd* uses a built-in default, which is often `/var/state/ups`. +The *STATEPATH* directive in linkman:upsd.conf[5] overrides this variable. + +*NUT_ALTPIDPATH* is the path name of the directory in which +*upsd* and drivers store .pid files. If this variable is not set, +*upsd* and drivers use either *NUT_STATEPATH* if set, or ALTPIDPATH if set, +or otherwise the built-in default *STATEPATH*. + BUGS ---- diff --git a/docs/man/upsd.txt b/docs/man/upsd.txt index 1fddadb1d5..a052e28a29 100644 --- a/docs/man/upsd.txt +++ b/docs/man/upsd.txt @@ -126,11 +126,16 @@ ENVIRONMENT VARIABLES `upsd.conf` and other configuration files. If this variable is not set, *upsd* uses a built-in default, which is often `/usr/local/ups/etc`. -*NUT_STATEPATH* is the path name of the directory in which +*NUT_STATEPATH* is the path name of the directory in which *upsd* keeps state information. If this variable is not set, *upsd* uses a built-in default, which is often `/var/state/ups`. The *STATEPATH* directive in linkman:upsd.conf[5] overrides this variable. +*NUT_ALTPIDPATH* is the path name of the directory in which +*upsd* and drivers store .pid files. If this variable is not set, +*upsd* and drivers use either *NUT_STATEPATH* if set, or ALTPIDPATH if set, +or otherwise the built-in default *STATEPATH*. + SEE ALSO --------