cluster: STABLE3 - cman: fix notifyd loop

Fabio M. Di Nitto fabbione@fedoraproject.org
Wed Feb 4 08:50:00 GMT 2009


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=dc8f60c70f13374a1e1e2dcb242a357ac454f247
Commit:        dc8f60c70f13374a1e1e2dcb242a357ac454f247
Parent:        300d65909c45dd7425beffe71a249bb91098affb
Author:        Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate:    Wed Feb 4 09:49:28 2009 +0100
Committer:     Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Wed Feb 4 09:49:28 2009 +0100

cman: fix notifyd loop

stop polling to check if there are notifications.
Use cman_fd+select instead.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
 cman/notifyd/main.c |   41 +++++++++++++++++++++++++++--------------
 1 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/cman/notifyd/main.c b/cman/notifyd/main.c
index 6aae796..7722032 100644
--- a/cman/notifyd/main.c
+++ b/cman/notifyd/main.c
@@ -10,6 +10,7 @@
 #include <sched.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/select.h>
 
 #include <libcman.h>
 #include <ccs.h>
@@ -334,25 +335,37 @@ out:
 
 static void loop()
 {
-	int rv;
-
-	for (;;) {
-		rv = cman_dispatch(cman_handle, CMAN_DISPATCH_ONE);
-		if (rv == -1 && errno == EHOSTDOWN) {
+	int cd_result, se_result;
+	fd_set read_fds;
+	int cman_fd;
+
+	do {
+		FD_ZERO (&read_fds);
+		cman_fd = cman_get_fd(cman_handle);
+		FD_SET (cman_fd, &read_fds);
+		se_result = select((cman_fd + 1), &read_fds, 0, 0, 0);
+		if (se_result == -1) {
+			logt_print(LOG_CRIT, "Unable to select on cman_fd: %s\n", strerror(errno));
 			byebye_cman();
-			logt_print(LOG_DEBUG, "waiting for cman to reappear..\n");
-			setup_cman(1);
-			logt_print(LOG_DEBUG, "cman is back..\n");
+			exit(EXIT_FAILURE);
 		}
 
-		if (daemon_quit) {
-			logt_print(LOG_DEBUG, "shutting down...\n");
-			byebye_cman();
-			exit(EXIT_SUCCESS);
+		if (FD_ISSET(cman_fd, &read_fds)) {
+			cd_result = 1;
+			while (cd_result > 0) {
+				cd_result = cman_dispatch(cman_handle, CMAN_DISPATCH_ONE);
+				if (cd_result == -1 && errno == EHOSTDOWN) {
+					byebye_cman();
+					logt_print(LOG_DEBUG, "waiting for cman to reappear..\n");
+					setup_cman(1);
+					logt_print(LOG_DEBUG, "cman is back..\n");
+				}
+			}
 		}
+	} while (se_result && !daemon_quit);
 
-		sleep(1);
-	}
+	logt_print(LOG_DEBUG, "shutting down...\n");
+	byebye_cman();
 }
 
 int main(int argc, char **argv)



More information about the Cluster-cvs mailing list