All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve Dickson <SteveD@redhat.com>
To: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
Subject: [PATCH] nfs-utils: sm-notify does not remove its pid file.
Date: Mon, 10 Dec 2007 14:21:29 -0500	[thread overview]
Message-ID: <475D91B9.4070405@RedHat.com> (raw)

It turns out that the sm-notify command, used to notify clients that
they need to reclaim their locks because the server just changed
state, does not clean up its pid file. The pid file is used to ensure
only one instance of the process is running. This results in sm-notify 
exiting before notifying any clients on the second reboot.

I also changed the directory in which the pid file is created from
/var/run into BASEDIR so the file can be removed after the after the 
user id is changed to a non-root uid.

steved.


commit 72e24403c298b7991eb04dd68ed2e9fcbe4baf70
Author: Steve Dickson <steved@redhat.com>
Date:   Mon Dec 10 12:17:29 2007 -0500

    Make sure sm-notify's pid file is removed when the process
    exits. Also moved the pid file from /var/run into BASEDIR
    so the file can be removed after the user id is changed
    to a non-root uid.
    
    Signed-off-by: Steve Dickson <steved@redhat.com>

diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c
index bb67c37..3f80e04 100644
--- a/utils/statd/sm-notify.c
+++ b/utils/statd/sm-notify.c
@@ -32,6 +32,10 @@
 # endif
 #endif
 
+#ifndef PIDFILE
+#define PIDFILE  BASEDIR "/sm-notify.pid"
+#endif
+
 #define DEFAULT_SM_STATE_PATH	BASEDIR "/state"
 #define	DEFAULT_SM_DIR_PATH	BASEDIR "/sm"
 #define	DEFAULT_SM_BAK_PATH	DEFAULT_SM_DIR_PATH ".bak"
@@ -89,6 +93,7 @@ void			nsm_log(int fac, const char *fmt, ...);
 static int		record_pid(void);
 static void		drop_privs(void);
 static void set_kernel_nsm_state(int state);
+static void remove_pid(void);
 
 static struct nsm_host *	hosts = NULL;
 
@@ -155,6 +160,7 @@ usage:		fprintf(stderr,
 			/* already run, don't try again */
 			exit(0);
 	}
+	atexit(remove_pid);
 
 	if (opt_srcaddr) {
 		strncpy(nsm_hostname, opt_srcaddr, sizeof(nsm_hostname)-1);
@@ -736,13 +742,19 @@ static int record_pid(void)
 	int fd;
 
 	snprintf(pid, 20, "%d\n", getpid());
-	fd = open("/var/run/sm-notify.pid", O_CREAT|O_EXCL|O_WRONLY, 0600);
+	fd = open(PIDFILE, O_CREAT|O_EXCL|O_WRONLY, 0600);
 	if (fd < 0)
 		return 0;
 	write(fd, pid, strlen(pid));
 	close(fd);
 	return 1;
 }
+static void remove_pid()
+{
+	if (unlink(PIDFILE) < 0)
+		nsm_log(LOG_WARNING,
+			"Unable to remove %s: %s", PIDFILE, strerror(errno));
+}
 
 /* Drop privileges to match owner of state-directory
  * (in case a reply triggers some unknown bug).

             reply	other threads:[~2007-12-10 19:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-10 19:21 Steve Dickson [this message]
2007-12-10 22:40 ` [PATCH] nfs-utils: sm-notify does not remove its pid file Neil Brown
     [not found]   ` <18269.49269.575546.943037-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2007-12-11  1:21     ` Steve Dickson
2007-12-11  3:28       ` Neil Brown
     [not found]         ` <18270.992.262485.318331-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2007-12-11 14:28           ` Steve Dickson
2007-12-12 23:11             ` Neil Brown

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=475D91B9.4070405@RedHat.com \
    --to=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.