- Check if the worker process was killed by signal and restart it.

- Improve logging.

Pointed out by:	Garrett Cooper <yanefbsd@gmail.com>
MFC after:	3 days
This commit is contained in:
Pawel Jakub Dawidek 2010-04-29 15:42:24 +00:00
parent 5571414ca8
commit c6ddcbe009
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=207372

View File

@ -107,6 +107,22 @@ g_gate_load(void)
}
}
static void
child_exit_log(unsigned int pid, int status)
{
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
pjdlog_debug(1, "Worker process exited gracefully (pid=%u).",
pid);
} else if (WIFSIGNALED(status)) {
pjdlog_error("Worker process killed (pid=%u, signal=%d).",
pid, WTERMSIG(status));
} else {
pjdlog_error("Worker process exited ungracefully (pid=%u, exitcode=%d).",
pid, WIFEXITED(status) ? WEXITSTATUS(status) : -1);
}
}
static void
child_exit(void)
{
@ -129,18 +145,17 @@ child_exit(void)
}
pjdlog_prefix_set("[%s] (%s) ", res->hr_name,
role2str(res->hr_role));
if (WEXITSTATUS(status) == 0) {
pjdlog_debug(1,
"Worker process exited gracefully (pid=%u).",
(unsigned int)pid);
} else {
pjdlog_error("Worker process failed (pid=%u, status=%d).",
(unsigned int)pid, WEXITSTATUS(status));
}
child_exit_log(pid, status);
proto_close(res->hr_ctrl);
res->hr_workerpid = 0;
if (res->hr_role == HAST_ROLE_PRIMARY) {
if (WEXITSTATUS(status) == EX_TEMPFAIL) {
/*
* Restart child process if it was killed by signal
* or exited because of temporary problem.
*/
if (WIFSIGNALED(status) ||
(WIFEXITED(status) &&
WEXITSTATUS(status) == EX_TEMPFAIL)) {
sleep(1);
pjdlog_info("Restarting worker process.");
hastd_primary(res);
@ -300,19 +315,12 @@ listen_accept(void)
/* Wait for it to exit. */
else if ((pid = waitpid(res->hr_workerpid,
&status, 0)) != res->hr_workerpid) {
/* We can only log the problem. */
pjdlog_errno(LOG_ERR,
"Waiting for worker process (pid=%u) failed",
(unsigned int)res->hr_workerpid);
/* See above. */
} else if (WEXITSTATUS(status) != 0) {
pjdlog_error("Worker process (pid=%u) exited ungracefully: status=%d.",
(unsigned int)res->hr_workerpid,
WEXITSTATUS(status));
/* See above. */
} else {
pjdlog_debug(1,
"Worker process (pid=%u) exited gracefully.",
(unsigned int)res->hr_workerpid);
child_exit_log(res->hr_workerpid, status);
}
res->hr_workerpid = 0;
} else if (res->hr_remotein != NULL) {