hastd.c (212037) | hastd.c (212038) |
---|---|
1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/hastd/hastd.c 212037 2010-08-30 23:19:21Z pjd $"); | 32__FBSDID("$FreeBSD: head/sbin/hastd/hastd.c 212038 2010-08-30 23:26:10Z pjd $"); |
33 34#include <sys/param.h> 35#include <sys/linker.h> 36#include <sys/module.h> 37#include <sys/wait.h> 38 39#include <assert.h> 40#include <err.h> --- 6 unchanged lines hidden (view full) --- 47#include <string.h> 48#include <sysexits.h> 49#include <unistd.h> 50 51#include <activemap.h> 52#include <pjdlog.h> 53 54#include "control.h" | 33 34#include <sys/param.h> 35#include <sys/linker.h> 36#include <sys/module.h> 37#include <sys/wait.h> 38 39#include <assert.h> 40#include <err.h> --- 6 unchanged lines hidden (view full) --- 47#include <string.h> 48#include <sysexits.h> 49#include <unistd.h> 50 51#include <activemap.h> 52#include <pjdlog.h> 53 54#include "control.h" |
55#include "event.h" |
|
55#include "hast.h" 56#include "hast_proto.h" 57#include "hastd.h" 58#include "hooks.h" 59#include "subr.h" 60 61/* Path to configuration file. */ 62const char *cfgpath = HAST_CONFIG; --- 90 unchanged lines hidden (view full) --- 153 */ 154 hook_check_one(pid, status); 155 continue; 156 } 157 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, 158 role2str(res->hr_role)); 159 child_exit_log(pid, status); 160 proto_close(res->hr_ctrl); | 56#include "hast.h" 57#include "hast_proto.h" 58#include "hastd.h" 59#include "hooks.h" 60#include "subr.h" 61 62/* Path to configuration file. */ 63const char *cfgpath = HAST_CONFIG; --- 90 unchanged lines hidden (view full) --- 154 */ 155 hook_check_one(pid, status); 156 continue; 157 } 158 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, 159 role2str(res->hr_role)); 160 child_exit_log(pid, status); 161 proto_close(res->hr_ctrl); |
162 res->hr_ctrl = NULL; 163 if (res->hr_event != NULL) { 164 proto_close(res->hr_event); 165 res->hr_event = NULL; 166 } |
|
161 res->hr_workerpid = 0; 162 if (res->hr_role == HAST_ROLE_PRIMARY) { 163 /* 164 * Restart child process if it was killed by signal 165 * or exited because of temporary problem. 166 */ 167 if (WIFSIGNALED(status) || 168 (WIFEXITED(status) && --- 450 unchanged lines hidden (view full) --- 619 nv_free(nverr); 620 proto_close(conn); 621 pjdlog_prefix_set("%s", ""); 622} 623 624static void 625main_loop(void) 626{ | 167 res->hr_workerpid = 0; 168 if (res->hr_role == HAST_ROLE_PRIMARY) { 169 /* 170 * Restart child process if it was killed by signal 171 * or exited because of temporary problem. 172 */ 173 if (WIFSIGNALED(status) || 174 (WIFEXITED(status) && --- 450 unchanged lines hidden (view full) --- 625 nv_free(nverr); 626 proto_close(conn); 627 pjdlog_prefix_set("%s", ""); 628} 629 630static void 631main_loop(void) 632{ |
627 fd_set rfds; 628 int cfd, lfd, maxfd, ret; | 633 struct hast_resource *res; |
629 struct timeval timeout; | 634 struct timeval timeout; |
635 int fd, maxfd, ret; 636 fd_set rfds; |
|
630 631 timeout.tv_sec = REPORT_INTERVAL; 632 timeout.tv_usec = 0; 633 634 for (;;) { 635 if (sigexit_received) { 636 sigexit_received = false; 637 terminate_workers(); 638 exit(EX_OK); 639 } 640 if (sigchld_received) { 641 sigchld_received = false; 642 child_exit(); 643 } 644 if (sighup_received) { 645 sighup_received = false; 646 hastd_reload(); 647 } 648 | 637 638 timeout.tv_sec = REPORT_INTERVAL; 639 timeout.tv_usec = 0; 640 641 for (;;) { 642 if (sigexit_received) { 643 sigexit_received = false; 644 terminate_workers(); 645 exit(EX_OK); 646 } 647 if (sigchld_received) { 648 sigchld_received = false; 649 child_exit(); 650 } 651 if (sighup_received) { 652 sighup_received = false; 653 hastd_reload(); 654 } 655 |
649 cfd = proto_descriptor(cfg->hc_controlconn); 650 lfd = proto_descriptor(cfg->hc_listenconn); 651 maxfd = cfd > lfd ? cfd : lfd; 652 | |
653 /* Setup descriptors for select(2). */ 654 FD_ZERO(&rfds); | 656 /* Setup descriptors for select(2). */ 657 FD_ZERO(&rfds); |
655 FD_SET(cfd, &rfds); 656 FD_SET(lfd, &rfds); | 658 maxfd = fd = proto_descriptor(cfg->hc_controlconn); 659 FD_SET(fd, &rfds); 660 fd = proto_descriptor(cfg->hc_listenconn); 661 FD_SET(fd, &rfds); 662 maxfd = fd > maxfd ? fd : maxfd; 663 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { 664 if (res->hr_event == NULL) 665 continue; 666 fd = proto_descriptor(res->hr_event); 667 FD_SET(fd, &rfds); 668 maxfd = fd > maxfd ? fd : maxfd; 669 } |
657 658 ret = select(maxfd + 1, &rfds, NULL, NULL, &timeout); 659 if (ret == 0) 660 hook_check(false); 661 else if (ret == -1) { 662 if (errno == EINTR) 663 continue; 664 KEEP_ERRNO((void)pidfile_remove(pfh)); 665 pjdlog_exit(EX_OSERR, "select() failed"); 666 } 667 | 670 671 ret = select(maxfd + 1, &rfds, NULL, NULL, &timeout); 672 if (ret == 0) 673 hook_check(false); 674 else if (ret == -1) { 675 if (errno == EINTR) 676 continue; 677 KEEP_ERRNO((void)pidfile_remove(pfh)); 678 pjdlog_exit(EX_OSERR, "select() failed"); 679 } 680 |
668 if (FD_ISSET(cfd, &rfds)) | 681 if (FD_ISSET(proto_descriptor(cfg->hc_controlconn), &rfds)) |
669 control_handle(cfg); | 682 control_handle(cfg); |
670 if (FD_ISSET(lfd, &rfds)) | 683 if (FD_ISSET(proto_descriptor(cfg->hc_listenconn), &rfds)) |
671 listen_accept(); | 684 listen_accept(); |
685 TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { 686 if (res->hr_event == NULL) 687 continue; 688 if (FD_ISSET(proto_descriptor(res->hr_event), &rfds)) { 689 if (event_recv(res) == 0) 690 continue; 691 /* The worker process exited? */ 692 proto_close(res->hr_event); 693 res->hr_event = NULL; 694 } 695 } |
|
672 } 673} 674 675int 676main(int argc, char *argv[]) 677{ 678 const char *pidfile; 679 pid_t otherpid; --- 92 unchanged lines hidden --- | 696 } 697} 698 699int 700main(int argc, char *argv[]) 701{ 702 const char *pidfile; 703 pid_t otherpid; --- 92 unchanged lines hidden --- |