mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-22 21:31:05 +01:00
Before handling any events on descriptors check signals so we can update
our info about worker processes if any of them was terminated in the meantime. This fixes the problem with 'hastctl status' running from a hook called on split-brain: 1. Secondary calls a hooks and terminates. 2. Hook asks for resource status via 'hastctl status'. 3. The main hastd handles the status request by sending it to the secondary worker who is already dead, but because signals weren't checked yet he doesn't know that and we get EPIPE. MFC after: 1 week
This commit is contained in:
parent
8e99556f73
commit
351758d85b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=219837
@ -884,19 +884,12 @@ out:
|
||||
}
|
||||
|
||||
static void
|
||||
main_loop(void)
|
||||
check_signals(void)
|
||||
{
|
||||
struct hast_resource *res;
|
||||
struct timeval seltimeout;
|
||||
struct timespec sigtimeout;
|
||||
int fd, maxfd, ret, signo;
|
||||
time_t lastcheck, now;
|
||||
sigset_t mask;
|
||||
fd_set rfds;
|
||||
int signo;
|
||||
|
||||
lastcheck = time(NULL);
|
||||
seltimeout.tv_sec = REPORT_INTERVAL;
|
||||
seltimeout.tv_usec = 0;
|
||||
sigtimeout.tv_sec = 0;
|
||||
sigtimeout.tv_nsec = 0;
|
||||
|
||||
@ -906,29 +899,45 @@ main_loop(void)
|
||||
PJDLOG_VERIFY(sigaddset(&mask, SIGTERM) == 0);
|
||||
PJDLOG_VERIFY(sigaddset(&mask, SIGCHLD) == 0);
|
||||
|
||||
while ((signo = sigtimedwait(&mask, NULL, &sigtimeout)) != -1) {
|
||||
switch (signo) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
sigexit_received = true;
|
||||
terminate_workers();
|
||||
proto_close(cfg->hc_controlconn);
|
||||
exit(EX_OK);
|
||||
break;
|
||||
case SIGCHLD:
|
||||
child_exit();
|
||||
break;
|
||||
case SIGHUP:
|
||||
hastd_reload();
|
||||
break;
|
||||
default:
|
||||
PJDLOG_ABORT("Unexpected signal (%d).", signo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
main_loop(void)
|
||||
{
|
||||
struct hast_resource *res;
|
||||
struct timeval seltimeout;
|
||||
int fd, maxfd, ret;
|
||||
time_t lastcheck, now;
|
||||
fd_set rfds;
|
||||
|
||||
lastcheck = time(NULL);
|
||||
seltimeout.tv_sec = REPORT_INTERVAL;
|
||||
seltimeout.tv_usec = 0;
|
||||
|
||||
pjdlog_info("Started successfully, running protocol version %d.",
|
||||
HAST_PROTO_VERSION);
|
||||
|
||||
for (;;) {
|
||||
while ((signo = sigtimedwait(&mask, NULL, &sigtimeout)) != -1) {
|
||||
switch (signo) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
sigexit_received = true;
|
||||
terminate_workers();
|
||||
proto_close(cfg->hc_controlconn);
|
||||
exit(EX_OK);
|
||||
break;
|
||||
case SIGCHLD:
|
||||
child_exit();
|
||||
break;
|
||||
case SIGHUP:
|
||||
hastd_reload();
|
||||
break;
|
||||
default:
|
||||
PJDLOG_ABORT("Unexpected signal (%d).", signo);
|
||||
}
|
||||
}
|
||||
check_signals();
|
||||
|
||||
/* Setup descriptors for select(2). */
|
||||
FD_ZERO(&rfds);
|
||||
@ -976,6 +985,12 @@ main_loop(void)
|
||||
pjdlog_exit(EX_OSERR, "select() failed");
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for signals before we do anything to update our
|
||||
* info about terminated workers in the meantime.
|
||||
*/
|
||||
check_signals();
|
||||
|
||||
if (FD_ISSET(proto_descriptor(cfg->hc_controlconn), &rfds))
|
||||
control_handle(cfg);
|
||||
if (FD_ISSET(proto_descriptor(cfg->hc_listenconn), &rfds))
|
||||
|
Loading…
Reference in New Issue
Block a user