diff --git a/sbin/hastd/control.c b/sbin/hastd/control.c index fed91302daab..b1cb10b31633 100644 --- a/sbin/hastd/control.c +++ b/sbin/hastd/control.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "hast.h" #include "hastd.h" @@ -51,6 +52,17 @@ __FBSDID("$FreeBSD$"); #include "control.h" +void +child_cleanup(struct hast_resource *res) +{ + + proto_close(res->hr_ctrl); + res->hr_ctrl = NULL; + proto_close(res->hr_event); + res->hr_event = NULL; + res->hr_workerpid = 0; +} + static void control_set_role_common(struct hastd_config *cfg, struct nv *nvout, uint8_t role, struct hast_resource *res, const char *name, unsigned int no) @@ -109,7 +121,7 @@ control_set_role_common(struct hastd_config *cfg, struct nv *nvout, pjdlog_debug(1, "Worker process %u stopped.", (unsigned int)res->hr_workerpid); } - res->hr_workerpid = 0; + child_cleanup(res); } /* Start worker process if we are changing to primary. */ diff --git a/sbin/hastd/control.h b/sbin/hastd/control.h index bde790a6e1fb..582617d21e18 100644 --- a/sbin/hastd/control.h +++ b/sbin/hastd/control.h @@ -38,6 +38,8 @@ struct hastd_config; struct hast_resource; +void child_cleanup(struct hast_resource *res); + void control_set_role(struct hast_resource *res, uint8_t role); void control_handle(struct hastd_config *cfg); diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c index 6ddcbd2f831e..af46882aa7a3 100644 --- a/sbin/hastd/hastd.c +++ b/sbin/hastd/hastd.c @@ -158,13 +158,7 @@ child_exit(void) pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role)); child_exit_log(pid, status); - proto_close(res->hr_ctrl); - res->hr_ctrl = NULL; - if (res->hr_event != NULL) { - proto_close(res->hr_event); - res->hr_event = NULL; - } - res->hr_workerpid = 0; + child_cleanup(res); if (res->hr_role == HAST_ROLE_PRIMARY) { /* * Restart child process if it was killed by signal @@ -553,7 +547,7 @@ listen_accept(void) } else { child_exit_log(res->hr_workerpid, status); } - res->hr_workerpid = 0; + child_cleanup(res); } else if (res->hr_remotein != NULL) { char oaddr[256];