From owner-svn-src-head@FreeBSD.ORG Sun Aug 29 21:41:53 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D11E510656B6; Sun, 29 Aug 2010 21:41:53 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B69838FC08; Sun, 29 Aug 2010 21:41:53 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7TLfrxD075276; Sun, 29 Aug 2010 21:41:53 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7TLfrRG075272; Sun, 29 Aug 2010 21:41:53 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201008292141.o7TLfrRG075272@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Sun, 29 Aug 2010 21:41:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211977 - head/sbin/hastd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Aug 2010 21:41:53 -0000 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);