Skip to content

Commit

Permalink
Merge dc2c6bd into 275cd5a
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov authored Feb 7, 2025
2 parents 275cd5a + dc2c6bd commit d0e8b18
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '/')
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 10 additions & 2 deletions common/nutipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "nutstream.hpp"

#include <iostream>
#include <sys/stat.h>


namespace nut {
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3281 utf-8
personal_ws-1.1 en 3283 utf-8
AAC
AAS
ABI
Expand Down Expand Up @@ -2746,6 +2746,7 @@ roadmap
rootca
rootfs
rootfs'es
rootpidpath
rpc
rq
rqt
Expand Down Expand Up @@ -3225,6 +3226,7 @@ workspaceFolder
workspaces
writability
writeinfo
writepid
writeups
ws
xAAAA
Expand Down

0 comments on commit d0e8b18

Please sign in to comment.