Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Sep 2010 18:57:06 +0000 (UTC)
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r213006 - head/sbin/hastd
Message-ID:  <201009221857.o8MIv6ei039503@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <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_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];
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201009221857.o8MIv6ei039503>