From c0fc3e038123d7a002f513b9484555fe4f8c54b7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 5 Sep 2017 18:03:30 +0200 Subject: [PATCH 1/3] 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 d7c728c44642b2e8e8128d8056d6a6bf15d2fe9d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 6 Sep 2017 08:14:08 +0200 Subject: [PATCH 2/3] 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 281865e855..cfdc7786fe 100644 --- a/common/common.c +++ b/common/common.c @@ -375,13 +375,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 f7f9dfe6a9283b903ee85b20d03f46d0c972dd85 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 6 Sep 2017 08:35:39 +0200 Subject: [PATCH 3/3] 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 cfdc7786fe..85f871880a 100644 --- a/common/common.c +++ b/common/common.c @@ -369,7 +369,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; @@ -385,10 +386,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