NeilBrown: mdmon: don't monitor /proc/mounts to decide when to create . pid file.

Martin F. Krafft madduck at alioth.debian.org
Mon May 24 09:20:58 UTC 2010


Module: mdadm
Branch: upstream
Commit: 58a4ba2a6b66ac14fa0ebaf0ce40326582d31429
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=58a4ba2a6b66ac14fa0ebaf0ce40326582d31429

Author: NeilBrown <neilb at suse.de>
Date:   Mon Feb  8 14:12:46 2010 +1100

mdmon: don't monitor /proc/mounts to decide when to create .pid file.

Monitoring /proc/mounts and creating a .pid file as soon as /var/run
is writable is racy.  Most distros clean all non-directories from
/var/run early in boot and if mdmon races with this it could
lose the files as soon as they are created.

Instead require that "mdmon --takeover" be run after /var is writable.

Signed-off-by: NeilBrown <neilb at suse.de>

---

 managemon.c |    8 +-------
 mdadm.h     |    2 +-
 mdstat.c    |    9 ++-------
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/managemon.c b/managemon.c
index 2a73d4b..e01d13b 100644
--- a/managemon.c
+++ b/managemon.c
@@ -677,14 +677,12 @@ void do_manager(struct supertype *container)
 {
 	struct mdstat_ent *mdstat;
 	sigset_t set;
-	int proc_fd;
 
 	sigprocmask(SIG_UNBLOCK, NULL, &set);
 	sigdelset(&set, SIGUSR1);
 	sigdelset(&set, SIGHUP);
 	sigdelset(&set, SIGALRM);
 	sigdelset(&set, SIGTERM);
-	proc_fd = open("/proc/mounts", O_RDONLY);
 
 	do {
 
@@ -711,10 +709,6 @@ void do_manager(struct supertype *container)
 					char *dir = ALT_RUN;
 					if (mkdir(dir, 0600) < 0 && errno != EEXIST)
 						dir = NULL;
-				} else {
-					if (proc_fd >= 0)
-						close(proc_fd);
-					proc_fd = -1;
 				}
 				if (dir && !sigterm &&
 				    (container->sock < 0 ||
@@ -742,7 +736,7 @@ void do_manager(struct supertype *container)
 			wakeup_monitor();
 
 		if (update_queue == NULL)
-			mdstat_wait_fd(container->sock, proc_fd, &set);
+			mdstat_wait_fd(container->sock, &set);
 		else
 			/* If an update is happening, just wait for signal */
 			pselect(0, NULL, NULL, NULL, NULL, &set);
diff --git a/mdadm.h b/mdadm.h
index f65a462..a7d8b79 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -341,7 +341,7 @@ struct mdstat_ent {
 extern struct mdstat_ent *mdstat_read(int hold, int start);
 extern void free_mdstat(struct mdstat_ent *ms);
 extern void mdstat_wait(int seconds);
-extern void mdstat_wait_fd(int fd, int fd2, const sigset_t *sigmask);
+extern void mdstat_wait_fd(int fd, const sigset_t *sigmask);
 extern int mddev_busy(int devnum);
 
 struct map_ent {
diff --git a/mdstat.c b/mdstat.c
index 4b3f6fe..4a9f370 100644
--- a/mdstat.c
+++ b/mdstat.c
@@ -266,7 +266,7 @@ void mdstat_wait(int seconds)
 	select(maxfd + 1, NULL, NULL, &fds, &tm);
 }
 
-void mdstat_wait_fd(int fd, int fd2, const sigset_t *sigmask)
+void mdstat_wait_fd(int fd, const sigset_t *sigmask)
 {
 	fd_set fds, rfds;
 	int maxfd = 0;
@@ -276,10 +276,7 @@ void mdstat_wait_fd(int fd, int fd2, const sigset_t *sigmask)
 	if (mdstat_fd >= 0)
 		FD_SET(mdstat_fd, &fds);
 
-	if (fd < 0)
-		fd = fd2, fd2 = -1;
-
-	while (fd >= 0) {
+	if (fd >= 0) {
 		struct stat stb;
 		fstat(fd, &stb);
 		if ((stb.st_mode & S_IFMT) == S_IFREG)
@@ -294,8 +291,6 @@ void mdstat_wait_fd(int fd, int fd2, const sigset_t *sigmask)
 		if (fd > maxfd)
 			maxfd = fd;
 
-		fd = fd2;
-		fd2 = -1;
 	}
 	if (mdstat_fd > maxfd)
 		maxfd = mdstat_fd;




More information about the pkg-mdadm-commits mailing list