Package: softflowd / 0.9.9-5

cherry-pick.softflowd-0.9.9-10-g2f195a0.check-pidfile-to-see-if-daemon-already-running.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Subject: Check pidfile to see if daemon already running
Origin: softflowd-0.9.9-10-g2f195a0 <https://github.com/irino/softflowd/commit/softflowd-0.9.9-10-g2f195a0>
Upstream-Author: SysError956 <paulgodard@gmail.com>
Date: Tue Apr 25 18:09:54 2017 -0400

--- a/softflowd.c
+++ b/softflowd.c
@@ -1951,6 +1951,19 @@
 		r = daemon(0, 0);
 		loginit(PROGNAME, 0);
 
+		if ((pidfile = fopen(pidfile_path, "r")) != NULL) {
+			int pid;
+			fscanf(pidfile,"%d", &pid);
+			fclose(pidfile);
+			
+			/* Check if the pid exists */
+			int pidfree = (kill(pid, 0) && errno == ESRCH);
+			if (!pidfree) {
+				fprintf(stderr, "Already running under pid %d\n",
+					pid);
+				exit(1);
+			}
+                }
 		if ((pidfile = fopen(pidfile_path, "w")) == NULL) {
 			fprintf(stderr, "Couldn't open pidfile %s: %s\n",
 			    pidfile_path, strerror(errno));