diff -up nut-2.7.1/clients/upsmon.c.rmpidf nut-2.7.1/clients/upsmon.c
--- nut-2.7.1/clients/upsmon.c.rmpidf 2014-02-27 11:41:09.139369295 +0100
+++ nut-2.7.1/clients/upsmon.c 2014-02-27 11:41:09.145369344 +0100
@@ -2027,6 +2027,7 @@ int main(int argc, char *argv[])
upslogx(LOG_INFO, "Signal %d: exiting", exit_flag);
upsmon_cleanup();
+ cleanpid(prog);
exit(EXIT_SUCCESS);
}
diff -up nut-2.7.1/common/common.c.rmpidf nut-2.7.1/common/common.c
--- nut-2.7.1/common/common.c.rmpidf 2013-11-20 20:53:31.000000000 +0100
+++ nut-2.7.1/common/common.c 2014-02-27 11:41:09.146369353 +0100
@@ -229,6 +229,20 @@ void writepid(const char *name)
umask(mask);
}
+/* remove pid file */
+void cleanpid(const char *name)
+{
+ char fn[SMALLBUF];
+
+ /* use full path if present, else build filename in PIDPATH */
+ if (*name == '/')
+ snprintf(fn, sizeof(fn), "%s", name);
+ else
+ snprintf(fn, sizeof(fn), "%s/%s.pid", PIDPATH, name);
+
+ unlink(fn);
+}
+
/* open pidfn, get the pid, then send it sig */
int sendsignalfn(const char *pidfn, int sig)
{
diff -up nut-2.7.1/include/common.h.rmpidf nut-2.7.1/include/common.h
--- nut-2.7.1/include/common.h.rmpidf 2013-11-20 20:53:31.000000000 +0100
+++ nut-2.7.1/include/common.h 2014-02-27 11:41:09.146369353 +0100
@@ -70,6 +70,9 @@ void chroot_start(const char *path);
/* write a pid file - <name> is a full pathname *or* just the program name */
void writepid(const char *name);
+/* remove pid file */
+void cleanpid(const char *name);
+
/* send a signal to another running process */
int sendsignal(const char *progname, int sig);
diff -up nut-2.7.1/server/upsd.c.rmpidf nut-2.7.1/server/upsd.c
--- nut-2.7.1/server/upsd.c.rmpidf 2014-02-27 11:41:09.146369353 +0100
+++ nut-2.7.1/server/upsd.c 2014-02-27 11:42:03.715818754 +0100
@@ -1050,6 +1050,7 @@ int main(int argc, char **argv)
ssl_cleanup();
upslogx(LOG_INFO, "Signal %d: exiting", exit_flag);
+ if (*pidfn) cleanpid(pidfn);
return EXIT_SUCCESS;
}