FreeBSD/sbin/hastd/primary.c
/*
 * Thread guards remote connections and reconnects when needed, handles
 * signals, etc.
 */
Thread guards remote connections and reconnects when needed, handles
signals, etc.
Thread guards remote connections and reconnects when needed handles signals etc .
static void *
guard_thread(void *arg)
{
	struct hast_resource *res = arg;
	unsigned int ii, ncomps;
	struct timespec timeout;
	time_t lastcheck, now;
	sigset_t mask;
	int signo;
	ncomps = HAST_NCOMPONENTS;
	lastcheck = time(NULL);
	PJDLOG_VERIFY(sigemptyset(&mask) == 0);
	PJDLOG_VERIFY(sigaddset(&mask, SIGINT) == 0);
	PJDLOG_VERIFY(sigaddset(&mask, SIGTERM) == 0);
	timeout.tv_sec = HAST_KEEPALIVE;
	timeout.tv_nsec = 0;
	signo = -1;
	for (;;) {
		switch (signo) {
		case SIGINT:
		case SIGTERM:
			sigexit_received = true;
			primary_exitx(EX_OK,
			    "Termination signal received, exiting.");
			break;
		default:
			break;
		}
		if (fullystarted) {
			pjdlog_debug(2, "remote_guard: Checking connections.");
			now = time(NULL);
			if (lastcheck + HAST_KEEPALIVE <= now) {
				for (ii = 0; ii < ncomps; ii++)
					guard_one(res, ii);
				lastcheck = now;
			}
		}
		signo = sigtimedwait(&mask, NULL, &timeout);
	}
	return (NULL);
}
static void * guard_thread ( void * arg ) { struct hast_resource * res = arg ; unsigned int ii , ncomps ; struct timespec timeout ; time_t lastcheck , now ; sigset_t mask ; int signo ; ncomps = HAST_NCOMPONENTS ; lastcheck = time ( NULL ) ; PJDLOG_VERIFY ( sigemptyset ( & mask ) == 0 ) ; PJDLOG_VERIFY ( sigaddset ( & mask , SIGINT ) == 0 ) ; PJDLOG_VERIFY ( sigaddset ( & mask , SIGTERM ) == 0 ) ; timeout . tv_sec = HAST_KEEPALIVE ; timeout . tv_nsec = 0 ; signo = -1 ; for ( ; ; ) { switch ( signo ) { case SIGINT : case SIGTERM : sigexit_received = true ; primary_exitx ( EX_OK , " " ) ; break ; default : break ; } if ( fullystarted ) { pjdlog_debug ( 2 , " " ) ; now = time ( NULL ) ; if ( lastcheck + HAST_KEEPALIVE <= now ) { for ( ii = 0 ; ii < ncomps ; ii ++ ) guard_one ( res , ii ) ; lastcheck = now ; } } signo = sigtimedwait ( & mask , NULL , & timeout ) ; } return ( NULL ) ; }
Thread guards remote connections and reconnects when needed, handles
 signals, etc.
Thread guards remote connections and reconnects when needed handles signals etc .
/*
		 * Don't check connections until we fully started,
		 * as we may still be looping, waiting for remote node
		 * to switch from primary to secondary.
		 */ /* NOTREACHED */