Blob Blame History Raw
diff -up nut-2.6.5/clients/upsmon.c.rmpidf nut-2.6.5/clients/upsmon.c
--- nut-2.6.5/clients/upsmon.c.rmpidf	2013-02-28 12:08:34.487394359 +0100
+++ nut-2.6.5/clients/upsmon.c	2013-02-28 12:08:34.494394419 +0100
@@ -2037,6 +2037,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.6.5/common/common.c.rmpidf nut-2.6.5/common/common.c
--- nut-2.6.5/common/common.c.rmpidf	2012-07-31 19:38:58.000000000 +0200
+++ nut-2.6.5/common/common.c	2013-02-28 12:08:34.494394419 +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.6.5/include/common.h.rmpidf nut-2.6.5/include/common.h
--- nut-2.6.5/include/common.h.rmpidf	2012-07-31 19:38:56.000000000 +0200
+++ nut-2.6.5/include/common.h	2013-02-28 12:08:34.495394429 +0100
@@ -64,6 +64,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.6.5/server/upsd.c.rmpidf nut-2.6.5/server/upsd.c
--- nut-2.6.5/server/upsd.c.rmpidf	2013-02-28 12:08:37.967424582 +0100
+++ nut-2.6.5/server/upsd.c	2013-02-28 12:08:37.982424720 +0100
@@ -1040,6 +1040,7 @@ int main(int argc, char **argv)
 	}
 
 	upslogx(LOG_INFO, "Signal %d: exiting", exit_flag);
+	if (*pidfn) cleanpid(pidfn);
 	return EXIT_SUCCESS;
 }