diff options
author | pjd <pjd@FreeBSD.org> | 2010-04-29 15:42:24 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2010-04-29 15:42:24 +0000 |
commit | db164aeb155dac81c7d06bc5e1780b7dadebde0b (patch) | |
tree | a33eff582abefdfbbfa1756dd9f90d65829d94aa | |
parent | 0dcf2ac7ada163fca882dcaa5c89ddfcef286bf9 (diff) | |
download | FreeBSD-src-db164aeb155dac81c7d06bc5e1780b7dadebde0b.zip FreeBSD-src-db164aeb155dac81c7d06bc5e1780b7dadebde0b.tar.gz |
- 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
-rw-r--r-- | sbin/hastd/hastd.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c index 7b1e228..27b9bba 100644 --- a/sbin/hastd/hastd.c +++ b/sbin/hastd/hastd.c @@ -108,6 +108,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) { struct hast_resource *res; @@ -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) { |