From owner-svn-src-head@FreeBSD.ORG Wed Sep 22 18:57:06 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 76C0A10656CB; Wed, 22 Sep 2010 18:57:06 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4D0E18FC13; Wed, 22 Sep 2010 18:57:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o8MIv6L2039507; Wed, 22 Sep 2010 18:57:06 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8MIv6ei039503; Wed, 22 Sep 2010 18:57:06 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201009221857.o8MIv6ei039503@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Wed, 22 Sep 2010 18:57:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r213006 - head/sbin/hastd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Sep 2010 18:57:06 -0000 Author: pjd Date: Wed Sep 22 18:57:06 2010 New Revision: 213006 URL: http://svn.freebsd.org/changeset/base/213006 Log: 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 Modified: head/sbin/hastd/control.c head/sbin/hastd/control.h head/sbin/hastd/hastd.c Modified: head/sbin/hastd/control.c ============================================================================== --- head/sbin/hastd/control.c Wed Sep 22 18:46:17 2010 (r213005) +++ head/sbin/hastd/control.c Wed Sep 22 18:57:06 2010 (r213006) @@ -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_con 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. */ Modified: head/sbin/hastd/control.h ============================================================================== --- head/sbin/hastd/control.h Wed Sep 22 18:46:17 2010 (r213005) +++ head/sbin/hastd/control.h Wed Sep 22 18:57:06 2010 (r213006) @@ -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); Modified: head/sbin/hastd/hastd.c ============================================================================== --- head/sbin/hastd/hastd.c Wed Sep 22 18:46:17 2010 (r213005) +++ head/sbin/hastd/hastd.c Wed Sep 22 18:57:06 2010 (r213006) @@ -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];