diff --git a/NEWS.adoc b/NEWS.adoc index 85d2346cbe..8060ebffa9 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -41,6 +41,12 @@ https://github.com/networkupstools/nut/milestone/9 - (expected) Bug fixes for fallout possible due to "fightwarn" effort in 2.8.0+ + - common code: + * Revised common `writepid()` to use `altpidpath()` as location for the + PID file creation, if the default `rootpidpath()` is not accessible + (e.g. daemon was not initially started as `root`). Likewise updated + short PID file based signal sending to consult both locations. [#1717] + PLANNED: Release notes for NUT 2.8.3 - what's new since 2.8.2 ------------------------------------------------------------- diff --git a/common/common.c b/common/common.c index fe8f3d87f7..6323b3974d 100644 --- a/common/common.c +++ b/common/common.c @@ -1685,6 +1685,7 @@ void writepid(const char *name) char fn[NUT_PATH_MAX]; FILE *pidf; mode_t mask; + intmax_t initial_uid = getuid(); /* use full path if present, else build filename in PIDPATH */ if (*name == '/') @@ -1694,6 +1695,10 @@ void writepid(const char *name) mask = umask(022); pidf = fopen(fn, "w"); + if (!pidf && initial_uid) { + snprintf(fn, sizeof(fn), "%s/%s.pid", altpidpath(), name); + pidf = fopen(fn, "w"); + } if (pidf) { intmax_t pid = (intmax_t)getpid(); @@ -2062,8 +2067,12 @@ int snprintfcat(char *dst, size_t size, const char *fmt, ...) int sendsignal(const char *progname, int sig, int check_current_progname) { char fn[NUT_PATH_MAX]; + struct stat st; snprintf(fn, sizeof(fn), "%s/%s.pid", rootpidpath(), progname); + if (stat(fn, &st) != 0) { + snprintf(fn, sizeof(fn), "%s/%s.pid", altpidpath(), progname); + } return sendsignalfn(fn, sig, progname, check_current_progname); } diff --git a/common/nutipc.cpp b/common/nutipc.cpp index d8bf131271..7494dbb0bc 100644 --- a/common/nutipc.cpp +++ b/common/nutipc.cpp @@ -44,6 +44,7 @@ #include "nutstream.hpp" #include +#include namespace nut { @@ -297,14 +298,21 @@ int Signal::send(Signal::enum_t signame, const std::string & pid_file) { int NutSignal::send(NutSignal::enum_t signame, const std::string & process) { std::string pid_file; + struct stat st; - // FIXME: What about ALTPIDPATH (for non-root daemons) - // and shouldn't we also consider it (e.g. try/catch)? pid_file += rootpidpath(); pid_file += '/'; pid_file += process; pid_file += ".pid"; + if (::stat(pid_file.c_str(), &st) != 0) { + // Consider ALTPIDPATH (used by non-root daemons) + pid_file = altpidpath(); + pid_file += '/'; + pid_file += process; + pid_file += ".pid"; + } + return Signal::send(signame, pid_file); } diff --git a/docs/nut.dict b/docs/nut.dict index 87a49d98ed..be96ce5af2 100644 --- a/docs/nut.dict +++ b/docs/nut.dict @@ -1,4 +1,4 @@ -personal_ws-1.1 en 3281 utf-8 +personal_ws-1.1 en 3283 utf-8 AAC AAS ABI @@ -2746,6 +2746,7 @@ roadmap rootca rootfs rootfs'es +rootpidpath rpc rq rqt @@ -3225,6 +3226,7 @@ workspaceFolder workspaces writability writeinfo +writepid writeups ws xAAAA