diff options
author | pjd <pjd@FreeBSD.org> | 2010-09-22 18:57:06 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2010-09-22 18:57:06 +0000 |
commit | 3657e3ff87f4a157905be2ffb58ae05887892b2c (patch) | |
tree | 43ea2b318d2781bffd40b06b0db52245e5eda1cd /sbin | |
parent | 6738880ac2bdfaeef78a9e585dcecc0196ae13b5 (diff) | |
download | FreeBSD-src-3657e3ff87f4a157905be2ffb58ae05887892b2c.zip FreeBSD-src-3657e3ff87f4a157905be2ffb58ae05887892b2c.tar.gz |
Fix descriptor leaks: when child exits, we have to close control and event
socket pairs. We did that only in one case out of three.
MFC after: 3 days
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/hastd/control.c | 14 | ||||
-rw-r--r-- | sbin/hastd/control.h | 2 | ||||
-rw-r--r-- | sbin/hastd/hastd.c | 10 |
3 files changed, 17 insertions, 9 deletions
diff --git a/sbin/hastd/control.c b/sbin/hastd/control.c index fed9130..b1cb10b 100644 --- a/sbin/hastd/control.c +++ b/sbin/hastd/control.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include <signal.h> #include <stdio.h> #include <string.h> +#include <unistd.h> #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 bde790a..582617d 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 6ddcbd2..af46882 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]; |