public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Kinglong Mee <kinglongmee@gmail.com>
To: Steve Dickson <SteveD@redhat.com>
Cc: linux-nfs@vger.kernel.org, Kinglong Mee <kinglongmee@gmail.com>
Subject: [PATCH 1/2] blkmapd: Let running correctly when pid file exists
Date: Thu, 14 Jul 2016 10:51:05 +0800	[thread overview]
Message-ID: <ae344139-4e98-4c61-ac5c-352f04bc80db@gmail.com> (raw)

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

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
---
 utils/blkmapd/device-discovery.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c
index 052d582..50e2746 100644
--- a/utils/blkmapd/device-discovery.c
+++ b/utils/blkmapd/device-discovery.c
@@ -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);
 		}
-- 
2.7.4


             reply	other threads:[~2016-07-14  2:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-14  2:51 Kinglong Mee [this message]
2016-07-20 15:13 ` [PATCH 1/2] blkmapd: Let running correctly when pid file exists Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae344139-4e98-4c61-ac5c-352f04bc80db@gmail.com \
    --to=kinglongmee@gmail.com \
    --cc=SteveD@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox