Skip to contentSkip to conversation

blkmapd: Let running correctly when pid file exists

PATCH In review Kinglong Mee 2 participants 2 messages Jul 14, 2016 – Jul 20, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 blkmapd: Let running correctly when pid file exists

Blkmapd cannot run until blkmapd.pid is unlinked. This patch lets checking exists based on lockf without stat.

# ps -ajx | grep blkmapd
 1644  9126  9125  1644 pts/1     9125 S+       0   0:00 grep --color=auto blkmapd
# ll /var/run/blkmapd
 -rw-r--r--. 1 root root 5 Jul 14 09:51 /var/run/blkmapd.pid
# blkmapd
 Pid file /var/run/blkmapd.pid already existed
---
 utils/blkmapd/device-discovery.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
utils/blkmapd/device-discovery.c +1 -7
index 052d582..50e2746 100644
@@ -436,7 +436,6 @@ static void usage(void)
 int main(int argc, char **argv)
 {
 	int opt, dflag = 0, fg = 0, ret = 1;
-	struct stat statbuf;
 	char pidbuf[64];
 
 	while ((opt = getopt(argc, argv, "hdf")) != -1) {
@@ -460,11 +459,6 @@ int main(int argc, char **argv)
 	if (fg) {
 		openlog("blkmapd", LOG_PERROR, 0);
 	} else {
-		if (!stat(PID_FILE, &statbuf)) {
-			fprintf(stderr, "Pid file %s already existed\n", PID_FILE);
-			exit(1);
-		}
-
 		if (daemon(0, 0) != 0) {
 			fprintf(stderr, "Daemonize failed\n");
 			exit(1);
@@ -478,7 +472,7 @@ int main(int argc, char **argv)
 		}
 
 		if (lockf(pidfd, F_TLOCK, 0) < 0) {
-			BL_LOG_ERR("Lock pid file %s failed\n", PID_FILE);
+			BL_LOG_ERR("Already running; Exiting!");
 			close(pidfd);
 			exit(1);
 		}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 11 lines · Kinglong Mee

Blkmapd cannot run until blkmapd.pid is unlinked. This patch lets checking exists based on lockf without stat.

# ps -ajx | grep blkmapd
 1644  9126  9125  1644 pts/1     9125 S+       0   0:00 grep --color=auto blkmapd
# ll /var/run/blkmapd
 -rw-r--r--. 1 root root 5 Jul 14 09:51 /var/run/blkmapd.pid
# blkmapd
 Pid file /var/run/blkmapd.pid already existed

Committed...

steved.

Quoted 38 lines
---
 utils/blkmapd/device-discovery.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
utils/blkmapd/device-discovery.c +1 -7
index 052d582..50e2746 100644
@@ -436,7 +436,6 @@ static void usage(void)
 int main(int argc, char **argv)
 {
 	int opt, dflag = 0, fg = 0, ret = 1;
-	struct stat statbuf;
 	char pidbuf[64];
 
 	while ((opt = getopt(argc, argv, "hdf")) != -1) {
@@ -460,11 +459,6 @@ int main(int argc, char **argv)
 	if (fg) {
 		openlog("blkmapd", LOG_PERROR, 0);
 	} else {
-		if (!stat(PID_FILE, &statbuf)) {
-			fprintf(stderr, "Pid file %s already existed\n", PID_FILE);
-			exit(1);
-		}
-
 		if (daemon(0, 0) != 0) {
 			fprintf(stderr, "Daemonize failed\n");
 			exit(1);
@@ -478,7 +472,7 @@ int main(int argc, char **argv)
 		}
 
 		if (lockf(pidfd, F_TLOCK, 0) < 0) {
-			BL_LOG_ERR("Lock pid file %s failed\n", PID_FILE);
+			BL_LOG_ERR("Already running; Exiting!");
 			close(pidfd);
 			exit(1);
 		}