[PATCH] Fix pthreadpool fork behaviour

Volker Lendecke Volker.Lendecke at SerNet.DE
Mon Sep 4 10:51:42 UTC 2017


On Thu, Aug 31, 2017 at 11:42:08AM +0200, Volker Lendecke via samba-technical wrote:
> On Thu, Aug 31, 2017 at 08:26:55AM +0200, Volker Lendecke via samba-technical wrote:
> > > (note the change from away -> way in the second line of text).
> > 
> > Sure, thanks! New patch attached.
> 
> Now really with patch. Same code, just the comment typo fixed.

Here's another patch for the same problem space. I've given quite some
tought in how to properly test this, but my cmocka-fu is not good
enough (yet?). I've tested this manually by adding some
fork/talloc_free/sleep code to source4/lib/messaging/tests/messaging.c
and looking at /proc/pid/fd.

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 2e285bf53f8a18b91de46762c07d8b6e64249a71 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 30 Aug 2017 17:49:54 +0200
Subject: [PATCH] messaging: Avoid a socket leak after fork

Bug: https://bugzilla.samba.org/show_bug.cgi?id=13006
Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/messages_dgm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index f29180d7ec2..9d87746fa2c 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -280,7 +280,8 @@ static int messaging_dgm_out_destructor(struct messaging_dgm_out *out)
 {
 	DLIST_REMOVE(out->ctx->outsocks, out);
 
-	if (tevent_queue_length(out->queue) != 0) {
+	if ((tevent_queue_length(out->queue) != 0) &&
+	    (getpid() == out->ctx->pid)) {
 		/*
 		 * We have pending jobs. We can't close the socket,
 		 * this has been handed over to messaging_dgm_out_queue_state.
-- 
2.11.0



More information about the samba-technical mailing list