summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2010-08-29 21:41:53 +0000
committerpjd <pjd@FreeBSD.org>2010-08-29 21:41:53 +0000
commit70a52f0307093bb9b0b23ae15d717c7481911ddf (patch)
treee8bd48022ec4570df380ba26e88e0fec1817f491 /sbin
parent9a66bc9a3072bb3aaa48a140ee6c2ef69809de24 (diff)
downloadFreeBSD-src-70a52f0307093bb9b0b23ae15d717c7481911ddf.zip
FreeBSD-src-70a52f0307093bb9b0b23ae15d717c7481911ddf.tar.gz
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
Diffstat (limited to 'sbin')
-rw-r--r--sbin/hastd/hastd.c20
-rw-r--r--sbin/hastd/primary.c2
-rw-r--r--sbin/hastd/secondary.c3
3 files changed, 22 insertions, 3 deletions
diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c
index 785798a..ad80c8e 100644
--- a/sbin/hastd/hastd.c
+++ b/sbin/hastd/hastd.c
@@ -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);
diff --git a/sbin/hastd/primary.c b/sbin/hastd/primary.c
index c495f10..f0b8423 100644
--- a/sbin/hastd/primary.c
+++ b/sbin/hastd/primary.c
@@ -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);
diff --git a/sbin/hastd/secondary.c b/sbin/hastd/secondary.c
index b76f680..6051722 100644
--- a/sbin/hastd/secondary.c
+++ b/sbin/hastd/secondary.c
@@ -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 *res, struct nv *nvin)
res->hr_workerpid = pid;
return;
}
+
(void)pidfile_close(pfh);
+ hook_fini();
setproctitle("%s (secondary)", res->hr_name);
OpenPOWER on IntegriCloud