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
This commit is contained in:
Pawel Jakub Dawidek 2010-08-29 21:41:53 +00:00
parent 25ec2e3e2b
commit ecc99c890e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211977
3 changed files with 22 additions and 3 deletions

View File

@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
#include "hast.h" #include "hast.h"
#include "hast_proto.h" #include "hast_proto.h"
#include "hastd.h" #include "hastd.h"
#include "hooks.h"
#include "subr.h" #include "subr.h"
/* Path to configuration file. */ /* Path to configuration file. */
@ -70,6 +71,9 @@ bool sigexit_received = false;
/* PID file handle. */ /* PID file handle. */
struct pidfh *pfh; struct pidfh *pfh;
/* How often check for hooks running for too long. */
#define REPORT_INTERVAL 10
static void static void
usage(void) usage(void)
{ {
@ -144,8 +148,10 @@ child_exit(void)
if (res == NULL) { if (res == NULL) {
/* /*
* This can happen when new connection arrives and we * 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; continue;
} }
pjdlog_prefix_set("[%s] (%s) ", res->hr_name, pjdlog_prefix_set("[%s] (%s) ", res->hr_name,
@ -620,6 +626,10 @@ main_loop(void)
{ {
fd_set rfds, wfds; fd_set rfds, wfds;
int cfd, lfd, maxfd, ret; int cfd, lfd, maxfd, ret;
struct timeval timeout;
timeout.tv_sec = REPORT_INTERVAL;
timeout.tv_usec = 0;
for (;;) { for (;;) {
if (sigexit_received) { if (sigexit_received) {
@ -648,8 +658,10 @@ main_loop(void)
FD_SET(cfd, &wfds); FD_SET(cfd, &wfds);
FD_SET(lfd, &wfds); FD_SET(lfd, &wfds);
ret = select(maxfd + 1, &rfds, &wfds, NULL, NULL); ret = select(maxfd + 1, &rfds, &wfds, NULL, &timeout);
if (ret == -1) { if (ret == 0)
hook_check(false);
else if (ret == -1) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
KEEP_ERRNO((void)pidfile_remove(pfh)); KEEP_ERRNO((void)pidfile_remove(pfh));
@ -754,6 +766,8 @@ main(int argc, char *argv[])
} }
} }
hook_init();
main_loop(); main_loop();
exit(0); exit(0);

View File

@ -786,7 +786,9 @@ hastd_primary(struct hast_resource *res)
res->hr_workerpid = pid; res->hr_workerpid = pid;
return; return;
} }
(void)pidfile_close(pfh); (void)pidfile_close(pfh);
hook_fini();
setproctitle("%s (primary)", res->hr_name); setproctitle("%s (primary)", res->hr_name);

View File

@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include "hast.h" #include "hast.h"
#include "hast_proto.h" #include "hast_proto.h"
#include "hastd.h" #include "hastd.h"
#include "hooks.h"
#include "metadata.h" #include "metadata.h"
#include "proto.h" #include "proto.h"
#include "subr.h" #include "subr.h"
@ -357,7 +358,9 @@ hastd_secondary(struct hast_resource *res, struct nv *nvin)
res->hr_workerpid = pid; res->hr_workerpid = pid;
return; return;
} }
(void)pidfile_close(pfh); (void)pidfile_close(pfh);
hook_fini();
setproctitle("%s (secondary)", res->hr_name); setproctitle("%s (secondary)", res->hr_name);