From ecc99c890e2a30d5ac3d1f2f13550977229485fd Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Sun, 29 Aug 2010 21:41:53 +0000 Subject: [PATCH] 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 --- sbin/hastd/hastd.c | 20 +++++++++++++++++--- sbin/hastd/primary.c | 2 ++ sbin/hastd/secondary.c | 3 +++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c index 785798ad768c..ad80c8e9b42d 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 c495f1093bc0..f0b84232d94c 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 b76f68048910..6051722ed39d 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);