svn commit: r211977 - head/sbin/hastd

Pawel Jakub Dawidek pjd at FreeBSD.org
Sun Aug 29 21:41:53 UTC 2010


Author: pjd
Date: Sun Aug 29 21:41:53 2010
New Revision: 211977
URL: http://svn.freebsd.org/changeset/base/211977

Log:
  Allow to run hooks from the main hastd process.
  
  MFC after:	2 weeks
  Obtained from:	Wheel Systems Sp. z o.o. http://www.wheelsystems.com

Modified:
  head/sbin/hastd/hastd.c
  head/sbin/hastd/primary.c
  head/sbin/hastd/secondary.c

Modified: head/sbin/hastd/hastd.c
==============================================================================
--- head/sbin/hastd/hastd.c	Sun Aug 29 21:39:49 2010	(r211976)
+++ head/sbin/hastd/hastd.c	Sun Aug 29 21:41:53 2010	(r211977)
@@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
 #include "hast.h"
 #include "hast_proto.h"
 #include "hastd.h"
+#include "hooks.h"
 #include "subr.h"
 
 /* Path to configuration file. */
@@ -70,6 +71,9 @@ bool sigexit_received = false;
 /* PID file handle. */
 struct pidfh *pfh;
 
+/* How often check for hooks running for too long. */
+#define	REPORT_INTERVAL	10
+
 static void
 usage(void)
 {
@@ -144,8 +148,10 @@ child_exit(void)
 		if (res == NULL) {
 			/*
 			 * This can happen when new connection arrives and we
-			 * cancel child responsible for the old one.
+			 * cancel child responsible for the old one or if this
+			 * was hook which we executed.
 			 */
+			hook_check_one(pid, status);
 			continue;
 		}
 		pjdlog_prefix_set("[%s] (%s) ", res->hr_name,
@@ -620,6 +626,10 @@ main_loop(void)
 {
 	fd_set rfds, wfds;
 	int cfd, lfd, maxfd, ret;
+	struct timeval timeout;
+
+	timeout.tv_sec = REPORT_INTERVAL;
+	timeout.tv_usec = 0;
 
 	for (;;) {
 		if (sigexit_received) {
@@ -648,8 +658,10 @@ main_loop(void)
 		FD_SET(cfd, &wfds);
 		FD_SET(lfd, &wfds);
 
-		ret = select(maxfd + 1, &rfds, &wfds, NULL, NULL);
-		if (ret == -1) {
+		ret = select(maxfd + 1, &rfds, &wfds, NULL, &timeout);
+		if (ret == 0)
+			hook_check(false);
+		else if (ret == -1) {
 			if (errno == EINTR)
 				continue;
 			KEEP_ERRNO((void)pidfile_remove(pfh));
@@ -754,6 +766,8 @@ main(int argc, char *argv[])
 		}
 	}
 
+	hook_init();
+
 	main_loop();
 
 	exit(0);

Modified: head/sbin/hastd/primary.c
==============================================================================
--- head/sbin/hastd/primary.c	Sun Aug 29 21:39:49 2010	(r211976)
+++ head/sbin/hastd/primary.c	Sun Aug 29 21:41:53 2010	(r211977)
@@ -786,7 +786,9 @@ hastd_primary(struct hast_resource *res)
 		res->hr_workerpid = pid;
 		return;
 	}
+
 	(void)pidfile_close(pfh);
+	hook_fini();
 
 	setproctitle("%s (primary)", res->hr_name);
 

Modified: head/sbin/hastd/secondary.c
==============================================================================
--- head/sbin/hastd/secondary.c	Sun Aug 29 21:39:49 2010	(r211976)
+++ head/sbin/hastd/secondary.c	Sun Aug 29 21:41:53 2010	(r211977)
@@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
 #include "hast.h"
 #include "hast_proto.h"
 #include "hastd.h"
+#include "hooks.h"
 #include "metadata.h"
 #include "proto.h"
 #include "subr.h"
@@ -357,7 +358,9 @@ hastd_secondary(struct hast_resource *re
 		res->hr_workerpid = pid;
 		return;
 	}
+
 	(void)pidfile_close(pfh);
+	hook_fini();
 
 	setproctitle("%s (secondary)", res->hr_name);
 


More information about the svn-src-head mailing list