public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
From: "Fabio M. Di Nitto" <fabbione@fedoraproject.org>
To: cluster-cvs-relay@redhat.com
Subject: cluster: STABLE3 - cman: fix notifyd loop
Date: Wed, 04 Feb 2009 08:50:00 -0000	[thread overview]
Message-ID: <20090204085017.995311205B1@lists.fedorahosted.org> (raw)

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)


                 reply	other threads:[~2009-02-04  8:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20090204085017.995311205B1@lists.fedorahosted.org \
    --to=fabbione@fedoraproject.org \
    --cc=cluster-cvs-relay@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).